Class Item

java.lang.Object
net.minecraft.world.item.Item
All Implemented Interfaces:
FeatureElement, ItemLike, IItemExtension
Direct Known Subclasses:
AirItem, ArmorItem, ArmorStandItem, ArrowItem, BannerPatternItem, BlockItem, BoatItem, BoneMealItem, BookItem, BottleItem, BrushItem, BucketItem, BundleItem, ChorusFruitItem, CompassItem, ComplexItem, DebugStickItem, DiscFragmentItem, DyeItem, EggItem, ElytraItem, EnchantedBookItem, EndCrystalItem, EnderEyeItem, EnderpearlItem, ExperienceBottleItem, FireChargeItem, FireworkRocketItem, FireworkStarItem, FishingRodItem, FlintAndSteelItem, FoodOnAStickItem, GlowInkSacItem, HangingEntityItem, HoneyBottleItem, HoneycombItem, InkSacItem, InstrumentItem, KnowledgeBookItem, LeadItem, MaceItem, MilkBucketItem, MinecartItem, NameTagItem, OminousBottleItem, PotionItem, ProjectileWeaponItem, SaddleItem, ShearsItem, ShieldItem, SmithingTemplateItem, SnowballItem, SpawnEggItem, SpyglassItem, SuspiciousStewItem, TieredItem, TridentItem, WindChargeItem, WritableBookItem, WrittenBookItem

public class Item extends Object implements FeatureElement, ItemLike, IItemExtension
  • Field Details

    • LOGGER

      private static final org.slf4j.Logger LOGGER
    • BY_BLOCK

      public static final Map<Block,Item> BY_BLOCK
    • BASE_ATTACK_DAMAGE_ID

      public static final ResourceLocation BASE_ATTACK_DAMAGE_ID
    • BASE_ATTACK_SPEED_ID

      public static final ResourceLocation BASE_ATTACK_SPEED_ID
    • DEFAULT_MAX_STACK_SIZE

      public static final int DEFAULT_MAX_STACK_SIZE
      See Also:
    • ABSOLUTE_MAX_STACK_SIZE

      public static final int ABSOLUTE_MAX_STACK_SIZE
      See Also:
    • MAX_BAR_WIDTH

      public static final int MAX_BAR_WIDTH
      See Also:
    • builtInRegistryHolder

      private final Holder.Reference<Item> builtInRegistryHolder
    • components

      private DataComponentMap components
    • craftingRemainingItem

      @Nullable private final Item craftingRemainingItem
    • descriptionId

      @Nullable private String descriptionId
    • requiredFeatures

      private final FeatureFlagSet requiredFeatures
    • canRepair

      protected final boolean canRepair
  • Constructor Details

  • Method Details

    • getId

      public static int getId(Item item)
    • byId

      public static Item byId(int id)
    • byBlock

      @Deprecated public static Item byBlock(Block block)
      Deprecated.
    • builtInRegistryHolder

      @Deprecated public Holder.Reference<Item> builtInRegistryHolder()
      Deprecated.
    • components

      public DataComponentMap components()
    • modifyDefaultComponentsFrom

      @Internal @Deprecated public void modifyDefaultComponentsFrom(DataComponentPatch patch)
      Deprecated.
      Neo: do not use, use the event instead
    • getDefaultMaxStackSize

      public int getDefaultMaxStackSize()
    • onUseTick

      public void onUseTick(Level level, LivingEntity livingEntity, ItemStack stack, int remainingUseDuration)
      Called as the item is being used by an entity.
    • onDestroyed

      @Deprecated public void onDestroyed(ItemEntity itemEntity)
    • verifyComponentsAfterLoad

      public void verifyComponentsAfterLoad(ItemStack stack)
    • canAttackBlock

      public boolean canAttackBlock(BlockState state, Level level, BlockPos pos, Player player)
    • asItem

      public Item asItem()
      Specified by:
      asItem in interface ItemLike
    • useOn

      public InteractionResult useOn(UseOnContext context)
      Called when this item is used when targeting a Block
    • getDestroySpeed

      public float getDestroySpeed(ItemStack stack, BlockState state)
    • use

      public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand usedHand)
      Called to trigger the item's "innate" right click behavior. To handle when this item is used on a Block, see useOn(net.minecraft.world.item.context.UseOnContext).
    • finishUsingItem

      public ItemStack finishUsingItem(ItemStack stack, Level level, LivingEntity livingEntity)
      Called when the player finishes using this Item (E.g. finishes eating.). Not called when the player stops using the Item before the action is complete.
    • isBarVisible

      public boolean isBarVisible(ItemStack stack)
    • getBarWidth

      public int getBarWidth(ItemStack stack)
    • getBarColor

      public int getBarColor(ItemStack stack)
    • overrideStackedOnOther

      public boolean overrideStackedOnOther(ItemStack stack, Slot slot, ClickAction action, Player player)
    • overrideOtherStackedOnMe

      public boolean overrideOtherStackedOnMe(ItemStack stack, ItemStack other, Slot slot, ClickAction action, Player player, SlotAccess access)
    • getAttackDamageBonus

      public float getAttackDamageBonus(Entity target, float damage, DamageSource damageSource)
    • hurtEnemy

      public boolean hurtEnemy(ItemStack stack, LivingEntity target, LivingEntity attacker)
      Current implementations of this method in child classes do not use the entry argument beside ev. They just raise the damage on the stack.
    • postHurtEnemy

      public void postHurtEnemy(ItemStack stack, LivingEntity target, LivingEntity attacker)
    • mineBlock

      public boolean mineBlock(ItemStack stack, Level level, BlockState state, BlockPos pos, LivingEntity miningEntity)
      Called when a Block is destroyed using this Item. Return true to trigger the "Use Item" statistic.
    • isCorrectToolForDrops

      public boolean isCorrectToolForDrops(ItemStack stack, BlockState state)
    • interactLivingEntity

      public InteractionResult interactLivingEntity(ItemStack stack, Player player, LivingEntity interactionTarget, InteractionHand usedHand)
      Try interacting with given entity. Return InteractionResult.PASS if nothing should happen.
    • getDescription

      public Component getDescription()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getOrCreateDescriptionId

      protected String getOrCreateDescriptionId()
    • getDescriptionId

      public String getDescriptionId()
    • getDescriptionId

      public String getDescriptionId(ItemStack stack)
      Returns the unlocalized name of this item. This version accepts an ItemStack so different stacks can have different names based on their damage or NBT.
    • getCraftingRemainingItem

      @Nullable @Deprecated public final Item getCraftingRemainingItem()
      Deprecated.
    • hasCraftingRemainingItem

      @Deprecated public boolean hasCraftingRemainingItem()
      Deprecated.
    • inventoryTick

      public void inventoryTick(ItemStack stack, Level level, Entity entity, int slotId, boolean isSelected)
      Called each tick as long the item is in a player's inventory. Used by maps to check if it's in a player's hand and update its contents.
    • onCraftedBy

      public void onCraftedBy(ItemStack stack, Level level, Player player)
      Called when item is crafted/smelted. Used only by maps so far.
    • onCraftedPostProcess

      public void onCraftedPostProcess(ItemStack stack, Level level)
    • isComplex

      public boolean isComplex()
    • getUseAnimation

      public UseAnim getUseAnimation(ItemStack stack)
      Returns the action that specifies what animation to play when the item is being used.
    • getUseDuration

      public int getUseDuration(ItemStack stack, LivingEntity entity)
    • releaseUsing

      public void releaseUsing(ItemStack stack, Level level, LivingEntity livingEntity, int timeCharged)
      Called when the player stops using an Item (stops holding the right mouse button).
    • appendHoverText

      public void appendHoverText(ItemStack stack, Item.TooltipContext context, List<Component> tooltipComponents, TooltipFlag tooltipFlag)
    • getTooltipImage

      public Optional<TooltipComponent> getTooltipImage(ItemStack stack)
    • getName

      public Component getName(ItemStack stack)
    • isFoil

      public boolean isFoil(ItemStack stack)
      Returns true if this item has an enchantment glint. By default, this returns stack.isEnchanted(), but other items can override it (for instance, written books always return true). Note that if you override this method, you generally want to also call the super version (on Item) to get the glint for enchanted items. Of course, that is unnecessary if the overwritten version always returns true.
    • isEnchantable

      public boolean isEnchantable(ItemStack stack)
      Checks isDamagable and if it cannot be stacked
    • getPlayerPOVHitResult

      public static BlockHitResult getPlayerPOVHitResult(Level level, Player player, ClipContext.Fluid fluidMode)
    • getEnchantmentValue

      @Deprecated public int getEnchantmentValue()
      Deprecated.
      Neo: Use ItemStack sensitive version.
    • isValidRepairItem

      public boolean isValidRepairItem(ItemStack stack, ItemStack repairCandidate)
      Return whether this item is repairable in an anvil.
    • getDefaultAttributeModifiers

      @Deprecated public ItemAttributeModifiers getDefaultAttributeModifiers()
    • isRepairable

      public boolean isRepairable(ItemStack stack)
      Description copied from interface: IItemExtension
      Called by CraftingManager to determine if an item is reparable.
      Specified by:
      isRepairable in interface IItemExtension
      Returns:
      True if reparable
    • useOnRelease

      public boolean useOnRelease(ItemStack stack)
      If this stack's item is a crossbow
    • getDefaultInstance

      public ItemStack getDefaultInstance()
    • getDrinkingSound

      public SoundEvent getDrinkingSound()
    • getEatingSound

      public SoundEvent getEatingSound()
    • getBreakingSound

      public SoundEvent getBreakingSound()
    • canFitInsideContainerItems

      public boolean canFitInsideContainerItems()
    • requiredFeatures

      public FeatureFlagSet requiredFeatures()
      Specified by:
      requiredFeatures in interface FeatureElement
    • initializeClient

      @Deprecated(forRemoval=true, since="1.21") public void initializeClient(Consumer<IClientItemExtensions> consumer)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Neo: Allowing mods to define client behavior for their Items