Interface IForgeItemStack
- All Superinterfaces:
ICapabilityProvider
,ICapabilitySerializable<CompoundNBT>
,INBTSerializable<CompoundNBT>
- All Known Implementing Classes:
ItemStack
-
Method Summary
Modifier and TypeMethodDescriptiondefault boolean
areShareTagsEqual
(ItemStack other) Modeled after ItemStack.areItemStackTagsEqual Uses Item.getNBTShareTag for comparison instead of NBT and capabilities.default boolean
canApplyAtEnchantingTable
(Enchantment enchantment) Checks whether an item can be enchanted with a certain enchantment.default boolean
canDisableShield
(ItemStack shield, LivingEntity entity, LivingEntity attacker) Can this Item disable a shielddefault boolean
canElytraFly
(LivingEntity entity) Used to determine if the player can use Elytra flight.default boolean
canEquip
(EquipmentSlotType armorType, Entity entity) Determines if the specific ItemStack can be placed in the specified armor slot, for the entity.default boolean
doesSneakBypassUse
(IWorldReader world, BlockPos pos, PlayerEntity player) Should this item, when held, allow sneak-clicks to pass through to the underlying block?default boolean
elytraFlightTick
(LivingEntity entity, int flightTicks) Used to determine if the player can continue Elytra flight, this is called each tick, and can be used to apply ItemStack damage, consume Energy, or what have you.default boolean
Determines if the ItemStack is equal to the other item stack, including Item, Count, and NBT.default int
Deprecated.default int
getBurnTime
(IRecipeType<?> recipeType) default ItemStack
ItemStack sensitive version of getContainerItem.default int
getEntityLifespan
(World world) Retrieves the normal 'lifespan' of this item when it is dropped on the ground as a EntityItem.default EquipmentSlotType
Override this to set a non-default armor slot for an ItemStack, but do not use this to get the armor slot of said stack; for that, usenet.minecraft.entity.LivingEntity#getSlotForItemStack(ItemStack)
.default int
getHarvestLevel
(ToolType tool, PlayerEntity player, BlockState state) Queries the harvest level of this item stack for the specified tool class, Returns -1 if this tool is not of the specified typedefault ITextComponent
getHighlightTip
(ITextComponent displayName) Allow the item one last chance to modify its name used for the tool highlight useful for adding something extra that can't be removed by a user in the displayed name, such as a mode of operation.default int
ItemStack sensitive version of getItemEnchantabilitydefault CompoundNBT
Get the NBT data to be sent to the client.default ItemStack
getStack()
default float
Determines the amount of durability the mending enchantment will repair, on average, per point of experience.default boolean
ItemStack sensitive version of hasContainerItemdefault boolean
isBookEnchantable
(ItemStack book) Allow or forbid the specific book/item combination as an anvil enchantdefault boolean
isEnderMask
(PlayerEntity player, EndermanEntity endermanEntity) Whether this Item can be used to hide player head for enderman.default boolean
Called by Piglins when checking to see if they will give an item or something in exchange for this item.default boolean
Determines if a item is reparable, used by Repair recipes and Grindstone.default boolean
isShield
(LivingEntity entity) Is this Item a shielddefault boolean
makesPiglinsNeutral
(LivingEntity wearer) Called by Piglins to check if a given item prevents hostility on sight.default void
onArmorTick
(World world, PlayerEntity player) Called to tick armor in the armor slot.default boolean
onBlockStartBreak
(BlockPos pos, PlayerEntity player) Called before a block is broken.default boolean
onDroppedByPlayer
(PlayerEntity player) Called when a player drops the item into the world, returning false from this will prevent the item from being removed from the players inventory and spawning in the worlddefault boolean
onEntityItemUpdate
(ItemEntity entity) Called by the default implemetation of EntityItem's onUpdate method, allowing for cleaner control over the update of the item without having to write a subclass.default boolean
onEntitySwing
(LivingEntity entity) Called when a entity tries to play the 'swing' animation.default void
onHorseArmorTick
(World world, MobEntity horse) Called every tick fromHorseEntity#onUpdate()
on the item in the armor slot.default ActionResultType
onItemUseFirst
(ItemUseContext context) default void
onUsingTick
(LivingEntity player, int count) Called each tick while using an item.default void
readShareTag
(CompoundNBT nbt) Override this method to decide what to do with the NBT data received from getNBTShareTag().default CompoundNBT
default boolean
shouldCauseBlockBreakReset
(ItemStack newStack) Called when the player is mining a block and the item in his hand changes.Methods inherited from interface net.minecraftforge.common.capabilities.ICapabilityProvider
getCapability, getCapability
Methods inherited from interface net.minecraftforge.common.util.INBTSerializable
deserializeNBT
-
Method Details
-
getStack
-
getContainerItem
ItemStack sensitive version of getContainerItem. Returns a full ItemStack instance of the result.- Returns:
- The resulting ItemStack
-
hasContainerItem
default boolean hasContainerItem()ItemStack sensitive version of hasContainerItem- Returns:
- True if this item has a 'container'
-
getBurnTime
- Returns:
- the fuel burn time for this itemStack in a furnace. Return 0 to make it not act as a fuel. Return -1 to let the default vanilla logic decide.
-
getBurnTime
Deprecated. -
getHarvestLevel
default int getHarvestLevel(ToolType tool, @Nullable PlayerEntity player, @Nullable BlockState state) Queries the harvest level of this item stack for the specified tool class, Returns -1 if this tool is not of the specified type- Parameters:
tool
- the tool type of the itemplayer
- The player trying to harvest the given blockstatestate
- The block to harvest- Returns:
- Harvest level, or -1 if not the specified tool type.
-
getToolTypes
-
onItemUseFirst
-
serializeNBT
- Specified by:
serializeNBT
in interfaceINBTSerializable<CompoundNBT>
-
onBlockStartBreak
Called before a block is broken. Return true to prevent default block harvesting. Note: In SMP, this is called on both client and server sides!- Parameters:
pos
- Block's position in worldplayer
- The Player that is wielding the item- Returns:
- True to prevent harvesting, false to continue as normal
-
shouldCauseBlockBreakReset
Called when the player is mining a block and the item in his hand changes. Allows to not reset blockbreaking if only NBT or similar changes.- Parameters:
newStack
- The new stack- Returns:
- True to reset block break progress
-
canApplyAtEnchantingTable
Checks whether an item can be enchanted with a certain enchantment. This applies specifically to enchanting an item in the enchanting table and is called when retrieving the list of possible enchantments for an item. Enchantments may additionally (or exclusively) be doing their own checks inEnchantment.canApplyAtEnchantingTable(ItemStack)
; check the individual implementation for reference. By default this will check if the enchantment type is valid for this item type.- Parameters:
enchantment
- the enchantment to be applied- Returns:
- true if the enchantment can be applied to this item
-
getItemEnchantability
default int getItemEnchantability()ItemStack sensitive version of getItemEnchantability- Returns:
- the item echantability value
-
getEquipmentSlot
Override this to set a non-default armor slot for an ItemStack, but do not use this to get the armor slot of said stack; for that, usenet.minecraft.entity.LivingEntity#getSlotForItemStack(ItemStack)
.- Returns:
- the armor slot of the ItemStack, or
null
to let the default vanilla logic as perLivingEntity.getSlotForItemStack(stack)
decide
-
canDisableShield
Can this Item disable a shield- Parameters:
shield
- The shield in questionentity
- The LivingEntity holding the shieldattacker
- The LivingEntity holding the ItemStack
-
isShield
Is this Item a shield- Parameters:
entity
- The Entity holding the ItemStack- Returns:
- True if the ItemStack is considered a shield
-
onEntitySwing
Called when a entity tries to play the 'swing' animation.- Parameters:
entity
- The entity swinging the item.- Returns:
- True to cancel any further processing by EntityLiving
-
onUsingTick
Called each tick while using an item.- Parameters:
player
- The Player using the itemcount
- The amount of time in tick the item has been used for continuously
-
getEntityLifespan
Retrieves the normal 'lifespan' of this item when it is dropped on the ground as a EntityItem. This is in ticks, standard result is 6000, or 5 mins.- Parameters:
world
- The world the entity is in- Returns:
- The normal lifespan in ticks.
-
onEntityItemUpdate
Called by the default implemetation of EntityItem's onUpdate method, allowing for cleaner control over the update of the item without having to write a subclass.- Parameters:
entity
- The entity Item- Returns:
- Return true to skip any further update code.
-
getXpRepairRatio
default float getXpRepairRatio()Determines the amount of durability the mending enchantment will repair, on average, per point of experience. -
onArmorTick
Called to tick armor in the armor slot. Override to do something -
onHorseArmorTick
Called every tick fromHorseEntity#onUpdate()
on the item in the armor slot.- Parameters:
world
- the world the horse is inhorse
- the horse wearing this armor
-
canEquip
Determines if the specific ItemStack can be placed in the specified armor slot, for the entity.- Parameters:
armorType
- Armor slot to be verified.entity
- The entity trying to equip the armor- Returns:
- True if the given ItemStack can be inserted in the slot
-
isBookEnchantable
Allow or forbid the specific book/item combination as an anvil enchant- Parameters:
book
- The book- Returns:
- if the enchantment is allowed
-
onDroppedByPlayer
Called when a player drops the item into the world, returning false from this will prevent the item from being removed from the players inventory and spawning in the world- Parameters:
player
- The player that dropped the item
-
getHighlightTip
Allow the item one last chance to modify its name used for the tool highlight useful for adding something extra that can't be removed by a user in the displayed name, such as a mode of operation.- Parameters:
displayName
- the name that will be displayed unless it is changed in this method.
-
doesSneakBypassUse
Should this item, when held, allow sneak-clicks to pass through to the underlying block?- Parameters:
world
- The worldpos
- Block position in worldplayer
- The Player that is wielding the item- Returns:
-
equals
Determines if the ItemStack is equal to the other item stack, including Item, Count, and NBT.- Parameters:
other
- The other stacklimitTags
- True to use shareTag False to use full NBT tag- Returns:
- true if equals
-
isRepairable
default boolean isRepairable()Determines if a item is reparable, used by Repair recipes and Grindstone.- Returns:
- True if reparable
-
isPiglinCurrency
default boolean isPiglinCurrency()Called by Piglins when checking to see if they will give an item or something in exchange for this item.- Returns:
- True if this item can be used as "currency" by piglins
-
makesPiglinsNeutral
Called by Piglins to check if a given item prevents hostility on sight. If this is true the Piglins will be neutral to the entity wearing this item, and will not attack on sight. Note: This does not prevent Piglins from becoming hostile due to other actions, nor does it make Piglins that are already hostile stop being so.- Parameters:
wearer
- The entity wearing this ItemStack- Returns:
- True if piglins are neutral to players wearing this item in an armor slot
-
isEnderMask
Whether this Item can be used to hide player head for enderman.- Parameters:
player
- The player watching the endermanendermanEntity
- The enderman that the player look- Returns:
- true if this Item can be used.
-
canElytraFly
Used to determine if the player can use Elytra flight. This is called Client and Server side.- Parameters:
entity
- The entity trying to fly.- Returns:
- True if the entity can use Elytra flight.
-
elytraFlightTick
Used to determine if the player can continue Elytra flight, this is called each tick, and can be used to apply ItemStack damage, consume Energy, or what have you. For example the Vanilla implementation of this, applies damage to the ItemStack every 20 ticks.- Parameters:
entity
- The entity currently in Elytra flight.flightTicks
- The number of ticks the entity has been Elytra flying for.- Returns:
- True if the entity should continue Elytra flight or False to stop.
-