Class Item

java.lang.Object
net.minecraft.item.Item
All Implemented Interfaces:
ItemConvertible
Direct Known Subclasses:
AirBlockItem, ArmorItem, ArmorStandItem, ArrowItem, BannerPatternItem, BlockItem, BoatItem, BoneMealItem, BookItem, BucketItem, ChorusFruitItem, CompassItem, DebugStickItem, DecorationItem, DyeItem, EggItem, ElytraItem, EnchantedBookItem, EnchantedGoldenAppleItem, EndCrystalItem, EnderEyeItem, EnderPearlItem, ExperienceBottleItem, FireChargeItem, FireworkChargeItem, FireworkItem, FishingRodItem, FlintAndSteelItem, GlassBottleItem, HoneyBottleItem, HorseArmorItem, KnowledgeBookItem, LeadItem, MilkBucketItem, MinecartItem, MushroomStewItem, MusicDiscItem, NameTagItem, NetherStarItem, NetworkSyncedItem, OnAStickItem, PotionItem, RangedWeaponItem, SaddleItem, ShearsItem, ShieldItem, SnowballItem, SpawnEggItem, SuspiciousStewItem, ToolItem, TridentItem, WritableBookItem, WrittenBookItem

public class Item
extends Object
implements ItemConvertible
  • Field Details

    • BLOCK_ITEMS

      public static final Map<Block,​Item> BLOCK_ITEMS
    • ATTACK_DAMAGE_MODIFIER_ID

      protected static final UUID ATTACK_DAMAGE_MODIFIER_ID
    • ATTACK_SPEED_MODIFIER_ID

      protected static final UUID ATTACK_SPEED_MODIFIER_ID
    • RANDOM

      protected static final Random RANDOM
    • group

      protected final ItemGroup group
    • rarity

      private final Rarity rarity
    • maxCount

      private final int maxCount
    • maxDamage

      private final int maxDamage
    • fireproof

      private final boolean fireproof
    • recipeRemainder

      private final Item recipeRemainder
    • translationKey

      @Nullable private String translationKey
    • foodComponent

      @Nullable private final FoodComponent foodComponent
  • Constructor Details

  • Method Details

    • getRawId

      public static int getRawId​(Item item)
    • byRawId

      public static Item byRawId​(int id)
    • fromBlock

      @Deprecated public static Item fromBlock​(Block block)
      Deprecated.
    • usageTick

      public void usageTick​(World world, LivingEntity user, ItemStack stack, int remainingUseTicks)
    • postProcessTag

      public boolean postProcessTag​(CompoundTag tag)
    • canMine

      public boolean canMine​(BlockState state, World world, BlockPos pos, PlayerEntity miner)
      Checks if a player can break a block while holding the item.
    • asItem

      public Item asItem()
      Gets this object in its item form.
      Specified by:
      asItem in interface ItemConvertible
    • useOnBlock

      public ActionResult useOnBlock​(ItemUsageContext context)
      Called when an item is used on a block.

      This method is called on both the logical client and logical server, so take caution when using this method. The logical side can be checked using context.getWorld().isClient().

      Parameters:
      context - the usage context
      Returns:
      an action result that specifies if using the item on a block was successful.
    • getMiningSpeedMultiplier

      public float getMiningSpeedMultiplier​(ItemStack stack, BlockState state)
    • use

      public TypedActionResult<ItemStack> use​(World world, PlayerEntity user, Hand hand)
      Called when an item is used by a player. The use action, by default, is bound to the right mouse button.

      This method is called on both the logical client and logical server, so take caution when overriding this method. The logical side can be checked using world.isClient().

      Parameters:
      world - the world the item was used in
      user - the player who used the item
      hand - the hand used
      Returns:
      a typed action result that specifies whether using the item was successful. The action result contains the new item stack that the player's hand will be set to.
    • finishUsing

      public ItemStack finishUsing​(ItemStack stack, World world, LivingEntity user)
    • getMaxCount

      public final int getMaxCount()
    • getMaxDamage

      public final int getMaxDamage()
    • isDamageable

      public boolean isDamageable()
    • postHit

      public boolean postHit​(ItemStack stack, LivingEntity target, LivingEntity attacker)
    • postMine

      public boolean postMine​(ItemStack stack, World world, BlockState state, BlockPos pos, LivingEntity miner)
    • isEffectiveOn

      public boolean isEffectiveOn​(BlockState state)
    • useOnEntity

      public ActionResult useOnEntity​(ItemStack stack, PlayerEntity user, LivingEntity entity, Hand hand)
    • getName

      @Environment(CLIENT) public Text getName()
    • toString

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

      protected String getOrCreateTranslationKey()
    • getTranslationKey

      public String getTranslationKey()
      Gets the translation key of this item.
    • getTranslationKey

      public String getTranslationKey​(ItemStack stack)
      Gets the translation key of this item using the provided item stack for context.
    • shouldSyncTagToClient

      public boolean shouldSyncTagToClient()
      Checks if an item should have its NBT data stored in #tag sent to the client.

      If an item is damageable, this method is ignored and data is always synced to client.

    • getRecipeRemainder

      @Nullable public final Item getRecipeRemainder()
      Gets the remainder item that should be left behind when this item is used as a crafting ingredient.
    • hasRecipeRemainder

      public boolean hasRecipeRemainder()
      Checks if this item has a remainder item that is left behind when used as a crafting ingredient.
    • inventoryTick

      public void inventoryTick​(ItemStack stack, World world, Entity entity, int slot, boolean selected)
    • onCraft

      public void onCraft​(ItemStack stack, World world, PlayerEntity player)
      Called when a player acquires the item by crafting, smelting, smithing, etc.
    • isNetworkSynced

      public boolean isNetworkSynced()
    • getUseAction

      public UseAction getUseAction​(ItemStack stack)
    • getMaxUseTime

      public int getMaxUseTime​(ItemStack stack)
    • onStoppedUsing

      public void onStoppedUsing​(ItemStack stack, World world, LivingEntity user, int remainingUseTicks)
    • appendTooltip

      @Environment(CLIENT) public void appendTooltip​(ItemStack stack, @Nullable World world, List<Text> tooltip, TooltipContext context)
    • getName

      public Text getName​(ItemStack stack)
    • hasGlint

      public boolean hasGlint​(ItemStack stack)
      Checks if the glint effect should be applied when the item is rendered.

      By default, returns true if the item has enchantments.

    • getRarity

      public Rarity getRarity​(ItemStack stack)
    • isEnchantable

      public boolean isEnchantable​(ItemStack stack)
    • raycast

      protected static BlockHitResult raycast​(World world, PlayerEntity player, RaycastContext.FluidHandling fluidHandling)
    • getEnchantability

      public int getEnchantability()
      Gets the enchantability of an item. This specifies the ability of an item to receive enchantments when enchanted using an enchanting table. As the value increases, the amount and level of enchantments applied increase.

      If the value of this method is 0, the item cannot be enchanted using an enchanting table.

    • appendStacks

      public void appendStacks​(ItemGroup group, DefaultedList<ItemStack> stacks)
    • isIn

      protected boolean isIn​(ItemGroup group)
      Checks whether this item should appear in a specified item group.
      Returns:
      true if the item is in the specified item group or the item group is ItemGroup.SEARCH.
    • getGroup

      @Nullable public final ItemGroup getGroup()
    • canRepair

      public boolean canRepair​(ItemStack stack, ItemStack ingredient)
    • getAttributeModifiers

      public Multimap<EntityAttribute,​EntityAttributeModifier> getAttributeModifiers​(EquipmentSlot slot)
    • isUsedOnRelease

      public boolean isUsedOnRelease​(ItemStack stack)
    • getDefaultStack

      public ItemStack getDefaultStack()
    • isIn

      public boolean isIn​(Tag<Item> tag)
    • isFood

      public boolean isFood()
      Checks if this item is food and therefore is edible.
    • getFoodComponent

      @Nullable public FoodComponent getFoodComponent()
    • getDrinkSound

      public SoundEvent getDrinkSound()
    • getEatSound

      public SoundEvent getEatSound()
    • isFireproof

      public boolean isFireproof()
    • damage

      public boolean damage​(DamageSource source)