Interface IItemStackExtension


public interface IItemStackExtension
  • Method Summary

    Modifier and Type
    Method
    Description
    default boolean
    canEquip(net.minecraft.world.entity.EquipmentSlot armorType, net.minecraft.world.entity.LivingEntity entity)
    Determines if the specific ItemStack can be placed in the specified armor slot, for the entity.
    default boolean
    Returns true if the given ItemStack can be put into a grindstone to be repaired and/or stripped of its enchantments.
    default boolean
    Queries if an item can perform the given action.
    default boolean
    canWalkOnPowderedSnow(net.minecraft.world.entity.LivingEntity wearer)
    Called by the powdered snow block to check if a living entity wearing this can walk on the snow, granting the same behavior as leather boots.
    default boolean
    doesSneakBypassUse(net.minecraft.world.level.LevelReader level, net.minecraft.core.BlockPos pos, net.minecraft.world.entity.player.Player player)
    Should this item, when held, allow sneak-clicks to pass through to the underlying block?
    default net.minecraft.world.item.enchantment.ItemEnchantments
    getAllEnchantments(net.minecraft.core.HolderLookup.RegistryLookup<net.minecraft.world.item.enchantment.Enchantment> lookup)
    Gets the gameplay level of all enchantments on this stack.
    default net.minecraft.world.item.component.ItemAttributeModifiers
    Computes the gameplay attribute modifiers for this item stack.
    default int
    getBurnTime(@Nullable net.minecraft.world.item.crafting.RecipeType<?> recipeType, net.minecraft.world.level.block.entity.FuelValues fuelValues)
    Returns the fuel burn time for this item stack.
    default <T, C extends @Nullable Object>
    T
    getCapability(ItemCapability<T,C> capability, C context)
     
    default <T> T
    getCapability(ItemCapability<T,@Nullable Void> capability)
     
    default net.minecraft.world.item.ItemStack
    ItemStack sensitive version of Item.getCraftingRemainder().
    default int
    getEnchantmentLevel(net.minecraft.core.Holder<net.minecraft.world.item.enchantment.Enchantment> enchantment)
    Gets the gameplay level of the target enchantment on this stack.
    default int
    getEntityLifespan(net.minecraft.world.level.Level level)
    Retrieves the normal 'lifespan' of this item when it is dropped on the ground as a EntityItem.
    default @Nullable net.minecraft.world.entity.EquipmentSlot
    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, use LivingEntity.getEquipmentSlotForItem(ItemStack).
    default net.minecraft.network.chat.Component
    getHighlightTip(net.minecraft.network.chat.Component 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 net.minecraft.world.phys.AABB
    getSweepHitBox(net.minecraft.world.entity.player.Player player, net.minecraft.world.entity.Entity target)
    Get a bounding box (AABB) of a sweep attack.
    default float
    Determines the amount of durability the mending enchantment will repair, on average, per point of experience.
    default boolean
    isBookEnchantable(net.minecraft.world.item.ItemStack book)
    Allow or forbid the specific book/item combination as an anvil enchant
    default boolean
    Determines if an item is repairable by combining, used by Repair recipes and Grindstone.
    default boolean
    isGazeDisguise(net.minecraft.world.entity.player.Player player, @Nullable net.minecraft.world.entity.LivingEntity entity)
    Whether this Item can be used to hide player's gaze from Endermen and Creakings.
    default boolean
    isNotReplaceableByPickAction(net.minecraft.world.entity.player.Player player, int inventorySlot)
    Whether this stack should be excluded (if possible) when selecting the target hotbar slot of a "pick" action.
    default boolean
    Called by Piglins when checking to see if they will give an item or something in exchange for this item.
    default boolean
    isPrimaryItemFor(net.minecraft.core.Holder<net.minecraft.world.item.enchantment.Enchantment> enchantment)
     
    default boolean
    makesPiglinsNeutral(net.minecraft.world.entity.LivingEntity wearer)
    Called by Piglins to check if a given item prevents hostility on sight.
    default void
    onAnimalArmorTick(net.minecraft.world.level.Level level, net.minecraft.world.entity.Mob horse)
    Called every tick when this item is equipped as an armor item by a Mob that can wear armor.
    default void
    onDestroyed(net.minecraft.world.entity.item.ItemEntity itemEntity, net.minecraft.world.damagesource.DamageSource damageSource)
    Called when an item entity for this stack is destroyed.
    default boolean
    onDroppedByPlayer(net.minecraft.world.entity.player.Player 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 world
    default boolean
    onEntityItemUpdate(net.minecraft.world.entity.item.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(net.minecraft.world.entity.LivingEntity entity, net.minecraft.world.InteractionHand hand)
    Called when a entity tries to play the 'swing' animation.
    default net.minecraft.world.InteractionResult
    onItemUseFirst(net.minecraft.world.item.context.UseOnContext context)
     
    default void
    onStopUsing(net.minecraft.world.entity.LivingEntity entity, int count)
    Called when an entity stops using an item item for any reason.
    private net.minecraft.world.item.ItemStack
     
    default boolean
    shouldCauseBlockBreakReset(net.minecraft.world.item.ItemStack newStack)
    Called when the player is mining a block and the item in his hand changes.
    default boolean
    supportsEnchantment(net.minecraft.core.Holder<net.minecraft.world.item.enchantment.Enchantment> enchantment)
     
  • Method Details

    • self

      private net.minecraft.world.item.ItemStack self()
    • getCraftingRemainder

      default net.minecraft.world.item.ItemStack getCraftingRemainder()
      ItemStack sensitive version of Item.getCraftingRemainder(). Returns a full ItemStack instance of the result.
      Returns:
      The resulting ItemStack
    • getBurnTime

      default int getBurnTime(@Nullable @Nullable net.minecraft.world.item.crafting.RecipeType<?> recipeType, net.minecraft.world.level.block.entity.FuelValues fuelValues)
      Returns the fuel burn time for this item stack. If it is zero, this item is not a fuel.

      Will never return a negative value.

      Returns:
      the fuel burn time for this item stack in a furnace.
    • onItemUseFirst

      default net.minecraft.world.InteractionResult onItemUseFirst(net.minecraft.world.item.context.UseOnContext context)
    • canPerformAction

      default boolean canPerformAction(ItemAbility itemAbility)
      Queries if an item can perform the given action. See ItemAbilities for a description of each stock action
      Parameters:
      itemAbility - The action being queried
      Returns:
      True if the stack can perform the action
    • shouldCauseBlockBreakReset

      default boolean shouldCauseBlockBreakReset(net.minecraft.world.item.ItemStack newStack)
      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
    • isPrimaryItemFor

      default boolean isPrimaryItemFor(net.minecraft.core.Holder<net.minecraft.world.item.enchantment.Enchantment> enchantment)
    • supportsEnchantment

      default boolean supportsEnchantment(net.minecraft.core.Holder<net.minecraft.world.item.enchantment.Enchantment> enchantment)
    • getEnchantmentLevel

      default int getEnchantmentLevel(net.minecraft.core.Holder<net.minecraft.world.item.enchantment.Enchantment> enchantment)
      Gets the gameplay level of the target enchantment on this stack.

      Use in place of EnchantmentHelper.getTagEnchantmentLevel(net.minecraft.core.Holder<net.minecraft.world.item.enchantment.Enchantment>, net.minecraft.world.item.ItemStack) for gameplay logic.

      Use EnchantmentHelper.getEnchantmentsForCrafting(net.minecraft.world.item.ItemStack) and EnchantmentHelper.setEnchantments(net.minecraft.world.item.ItemStack, net.minecraft.world.item.enchantment.ItemEnchantments) when modifying the item's enchantments.

      Parameters:
      enchantment - The enchantment being checked for.
      Returns:
      The level of the enchantment, or 0 if not present.
    • getAllEnchantments

      default net.minecraft.world.item.enchantment.ItemEnchantments getAllEnchantments(net.minecraft.core.HolderLookup.RegistryLookup<net.minecraft.world.item.enchantment.Enchantment> lookup)
      Gets the gameplay level of all enchantments on this stack.

      Use in place of ItemStack.getTagEnchantments() for gameplay logic.

      Use EnchantmentHelper.getEnchantmentsForCrafting(net.minecraft.world.item.ItemStack) and EnchantmentHelper.setEnchantments(net.minecraft.world.item.ItemStack, net.minecraft.world.item.enchantment.ItemEnchantments) when modifying the item's enchantments.

      Returns:
      Map of all enchantments on the stack, or an empty map if no enchantments are present.
    • getEquipmentSlot

      @Nullable default @Nullable net.minecraft.world.entity.EquipmentSlot 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, use LivingEntity.getEquipmentSlotForItem(ItemStack).
      Returns:
      the armor slot of the ItemStack, or null to let the default vanilla logic as per LivingEntity.getSlotForItemStack(stack) decide
    • onEntitySwing

      default boolean onEntitySwing(net.minecraft.world.entity.LivingEntity entity, net.minecraft.world.InteractionHand hand)
      Called when a entity tries to play the 'swing' animation.
      Parameters:
      entity - The entity swinging the item.
      hand - The hand the item is held in.
      Returns:
      True to cancel any further processing by LivingEntity
    • onStopUsing

      default void onStopUsing(net.minecraft.world.entity.LivingEntity entity, int count)
      Called when an entity stops using an item item for any reason.
      Parameters:
      entity - The entity using the item, typically a player
      count - The amount of time in tick the item has been used for continuously
    • getEntityLifespan

      default int getEntityLifespan(net.minecraft.world.level.Level level)
      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:
      level - The level the entity is in
      Returns:
      The normal lifespan in ticks.
    • onEntityItemUpdate

      default boolean onEntityItemUpdate(net.minecraft.world.entity.item.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.
      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.
    • onAnimalArmorTick

      default void onAnimalArmorTick(net.minecraft.world.level.Level level, net.minecraft.world.entity.Mob horse)
      Called every tick when this item is equipped as an armor item by a Mob that can wear armor.
      Parameters:
      level - The level the horse is in
      horse - The horse wearing this item
    • canEquip

      default boolean canEquip(net.minecraft.world.entity.EquipmentSlot armorType, net.minecraft.world.entity.LivingEntity entity)
      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

      default boolean isBookEnchantable(net.minecraft.world.item.ItemStack book)
      Allow or forbid the specific book/item combination as an anvil enchant
      Parameters:
      book - The book
      Returns:
      if the enchantment is allowed
    • onDroppedByPlayer

      default boolean onDroppedByPlayer(net.minecraft.world.entity.player.Player 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 world
      Parameters:
      player - The player that dropped the item
    • getHighlightTip

      default net.minecraft.network.chat.Component getHighlightTip(net.minecraft.network.chat.Component 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.
      Parameters:
      displayName - the name that will be displayed unless it is changed in this method.
    • doesSneakBypassUse

      default boolean doesSneakBypassUse(net.minecraft.world.level.LevelReader level, net.minecraft.core.BlockPos pos, net.minecraft.world.entity.player.Player player)
      Should this item, when held, allow sneak-clicks to pass through to the underlying block?
      Parameters:
      level - The level
      pos - Block position in level
      player - The Player that is wielding the item
    • isCombineRepairable

      default boolean isCombineRepairable()
      Determines if an item is repairable by combining, used by Repair recipes and Grindstone.
      Returns:
      True if repairable by combining
    • 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

      default boolean makesPiglinsNeutral(net.minecraft.world.entity.LivingEntity wearer)
      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
    • isGazeDisguise

      default boolean isGazeDisguise(net.minecraft.world.entity.player.Player player, @Nullable @Nullable net.minecraft.world.entity.LivingEntity entity)
      Whether this Item can be used to hide player's gaze from Endermen and Creakings.
      Parameters:
      player - The player watching the entity
      entity - The entity the player is looking at, may be null
      Returns:
      true if this Item hides the player's gaze from the given entity
    • canWalkOnPowderedSnow

      default boolean canWalkOnPowderedSnow(net.minecraft.world.entity.LivingEntity wearer)
      Called by the powdered snow block to check if a living entity wearing this can walk on the snow, granting the same behavior as leather boots. Only affects items worn in the boots slot.
      Parameters:
      wearer - The entity wearing this ItemStack
      Returns:
      True if the entity can walk on powdered snow
    • getSweepHitBox

      default net.minecraft.world.phys.AABB getSweepHitBox(net.minecraft.world.entity.player.Player player, net.minecraft.world.entity.Entity target)
      Get a bounding box (AABB) of a sweep attack.
      Parameters:
      player - the performing the attack the attack.
      target - the entity targeted by the attack.
      Returns:
      the bounding box.
    • onDestroyed

      default void onDestroyed(net.minecraft.world.entity.item.ItemEntity itemEntity, net.minecraft.world.damagesource.DamageSource damageSource)
      Called when an item entity for this stack is destroyed. Note: The ItemStack can be retrieved from the item entity.
      Parameters:
      itemEntity - The item entity that was destroyed.
      damageSource - Damage source that caused the item entity to "die".
    • isNotReplaceableByPickAction

      default boolean isNotReplaceableByPickAction(net.minecraft.world.entity.player.Player player, int inventorySlot)
      Whether this stack should be excluded (if possible) when selecting the target hotbar slot of a "pick" action. By default, this returns true for enchanted stacks.
      Parameters:
      player - the player performing the picking
      inventorySlot - the inventory slot of the item being up for replacement
      Returns:
      true to leave this stack in the hotbar if possible
      See Also:
      • Inventory.getSuitableHotbarSlot()
    • canGrindstoneRepair

      default boolean canGrindstoneRepair()
      Returns true if the given ItemStack can be put into a grindstone to be repaired and/or stripped of its enchantments.
      Returns:
      true if the given ItemStack can be put into a grindstone to be repaired and/or stripped of its enchantments
    • getCapability

      @Nullable default <T, C extends @Nullable Object> T getCapability(ItemCapability<T,C> capability, C context)
    • getCapability

      @Nullable default <T> T getCapability(ItemCapability<T,@Nullable Void> capability)
    • getAttributeModifiers

      default net.minecraft.world.item.component.ItemAttributeModifiers getAttributeModifiers()
      Computes the gameplay attribute modifiers for this item stack. Used in place of direct access to DataComponents.ATTRIBUTE_MODIFIERS or IItemExtension.getDefaultAttributeModifiers(ItemStack) when querying attributes for gameplay purposes.

      This method first computes the default modifiers, using DataComponents.ATTRIBUTE_MODIFIERS if present, otherwise falling back to IItemExtension.getDefaultAttributeModifiers(ItemStack).

      The ItemAttributeModifierEvent is then fired to allow external adjustments.