Interface FabricItem


public interface FabricItem
General-purpose Fabric-provided extensions for Item subclasses.

Note: This interface is automatically implemented on all items via Mixin and interface injection.

Note to maintainers: Functions should only be added to this interface if they are general-purpose enough, to be evaluated on a case-by-case basis. Otherwise they are better suited for more specialized APIs.

  • Method Summary

    Modifier and Type
    Method
    Description
    default boolean
    allowContinuingBlockBreaking(net.minecraft.entity.player.PlayerEntity player, net.minecraft.item.ItemStack oldStack, net.minecraft.item.ItemStack newStack)
    When the NBT of the selected stack changes, block breaking progress is reset.
    default boolean
    allowNbtUpdateAnimation(net.minecraft.entity.player.PlayerEntity player, net.minecraft.util.Hand hand, net.minecraft.item.ItemStack oldStack, net.minecraft.item.ItemStack newStack)
    When the NBT of an item stack in the main hand or off hand changes, vanilla runs an "update animation".
    default Multimap<net.minecraft.entity.attribute.EntityAttribute,net.minecraft.entity.attribute.EntityAttributeModifier>
    getAttributeModifiers(net.minecraft.item.ItemStack stack, net.minecraft.entity.EquipmentSlot slot)
    Return the attribute modifiers to apply when this stack is worn in a living entity equipment slot.
    default boolean
    isSuitableFor(net.minecraft.item.ItemStack stack, net.minecraft.block.BlockState state)
    Determines if mining with this item allows drops to be harvested from the specified block state.
  • Method Details

    • allowNbtUpdateAnimation

      default boolean allowNbtUpdateAnimation(net.minecraft.entity.player.PlayerEntity player, net.minecraft.util.Hand hand, net.minecraft.item.ItemStack oldStack, net.minecraft.item.ItemStack newStack)
      When the NBT of an item stack in the main hand or off hand changes, vanilla runs an "update animation". This function is called on the client side when the NBT or count of the stack has changed, but not the item, and returning false cancels this animation.
      Parameters:
      player - the current player; this may be safely cast to ClientPlayerEntity in client-only code
      hand - the hand; this function applies both to the main hand and the off hand
      oldStack - the previous stack, of this item
      newStack - the new stack, also of this item
      Returns:
      true to run the vanilla animation, false to cancel it.
    • allowContinuingBlockBreaking

      default boolean allowContinuingBlockBreaking(net.minecraft.entity.player.PlayerEntity player, net.minecraft.item.ItemStack oldStack, net.minecraft.item.ItemStack newStack)
      When the NBT of the selected stack changes, block breaking progress is reset. This function is called when the NBT of the selected stack has changed, and returning true allows the block breaking progress to continue.
      Parameters:
      player - the player breaking the block
      oldStack - the previous stack, of this item
      newStack - the new stack, also of this item
      Returns:
      true to allow continuing block breaking, false to reset the progress.
    • getAttributeModifiers

      default Multimap<net.minecraft.entity.attribute.EntityAttribute,net.minecraft.entity.attribute.EntityAttributeModifier> getAttributeModifiers(net.minecraft.item.ItemStack stack, net.minecraft.entity.EquipmentSlot slot)
      Return the attribute modifiers to apply when this stack is worn in a living entity equipment slot. Stack-aware version of Item.getAttributeModifiers(EquipmentSlot).

      Note that attribute modifiers are only updated when the stack changes, i.e. when ItemStack.areEqual(old, new) is false.

      Parameters:
      stack - the current stack
      slot - the equipment slot this stack is in
      Returns:
      the attribute modifiers
    • isSuitableFor

      default boolean isSuitableFor(net.minecraft.item.ItemStack stack, net.minecraft.block.BlockState state)
      Determines if mining with this item allows drops to be harvested from the specified block state. Stack-aware version of Item.isSuitableFor(BlockState).
      Parameters:
      stack - the current stack
      state - the block state of the targeted block
      Returns:
      true if drops can be harvested