Package net.minecraft.item
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
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Item.Settings
-
Field Summary
Fields Modifier and Type Field Description protected static UUID
ATTACK_DAMAGE_MODIFIER_ID
protected static UUID
ATTACK_SPEED_MODIFIER_ID
static Map<Block,Item>
BLOCK_ITEMS
private boolean
fireproof
private FoodComponent
foodComponent
protected ItemGroup
group
private int
maxCount
private int
maxDamage
protected static Random
RANDOM
private Rarity
rarity
private Item
recipeRemainder
private String
translationKey
-
Constructor Summary
Constructors Constructor Description Item(Item.Settings settings)
-
Method Summary
Modifier and Type Method Description void
appendStacks(ItemGroup group, DefaultedList<ItemStack> stacks)
void
appendTooltip(ItemStack stack, World world, List<Text> tooltip, TooltipContext context)
Item
asItem()
Gets this object in its item form.static Item
byRawId(int id)
boolean
canMine(BlockState state, World world, BlockPos pos, PlayerEntity miner)
Checks if a player can break a block while holding the item.boolean
canRepair(ItemStack stack, ItemStack ingredient)
boolean
damage(DamageSource source)
ItemStack
finishUsing(ItemStack stack, World world, LivingEntity user)
static Item
fromBlock(Block block)
Deprecated.Multimap<EntityAttribute,EntityAttributeModifier>
getAttributeModifiers(EquipmentSlot slot)
ItemStack
getDefaultStack()
SoundEvent
getDrinkSound()
SoundEvent
getEatSound()
int
getEnchantability()
Gets the enchantability of an item.FoodComponent
getFoodComponent()
ItemGroup
getGroup()
int
getMaxCount()
int
getMaxDamage()
int
getMaxUseTime(ItemStack stack)
float
getMiningSpeedMultiplier(ItemStack stack, BlockState state)
Text
getName()
Text
getName(ItemStack stack)
protected String
getOrCreateTranslationKey()
Rarity
getRarity(ItemStack stack)
static int
getRawId(Item item)
Item
getRecipeRemainder()
Gets the remainder item that should be left behind when this item is used as a crafting ingredient.String
getTranslationKey()
Gets the translation key of this item.String
getTranslationKey(ItemStack stack)
Gets the translation key of this item using the provided item stack for context.UseAction
getUseAction(ItemStack stack)
boolean
hasGlint(ItemStack stack)
Checks if the glint effect should be applied when the item is rendered.boolean
hasRecipeRemainder()
Checks if this item has a remainder item that is left behind when used as a crafting ingredient.void
inventoryTick(ItemStack stack, World world, Entity entity, int slot, boolean selected)
boolean
isDamageable()
boolean
isEffectiveOn(BlockState state)
boolean
isEnchantable(ItemStack stack)
boolean
isFireproof()
boolean
isFood()
Checks if this item is food and therefore is edible.protected boolean
isIn(ItemGroup group)
Checks whether this item should appear in a specified item group.boolean
isIn(Tag<Item> tag)
boolean
isNetworkSynced()
boolean
isUsedOnRelease(ItemStack stack)
void
onCraft(ItemStack stack, World world, PlayerEntity player)
Called when a player acquires the item by crafting, smelting, smithing, etc.void
onStoppedUsing(ItemStack stack, World world, LivingEntity user, int remainingUseTicks)
boolean
postHit(ItemStack stack, LivingEntity target, LivingEntity attacker)
boolean
postMine(ItemStack stack, World world, BlockState state, BlockPos pos, LivingEntity miner)
boolean
postProcessTag(CompoundTag tag)
protected static BlockHitResult
raycast(World world, PlayerEntity player, RaycastContext.FluidHandling fluidHandling)
boolean
shouldSyncTagToClient()
Checks if an item should have its NBT data stored in#tag
sent to the client.String
toString()
void
usageTick(World world, LivingEntity user, ItemStack stack, int remainingUseTicks)
TypedActionResult<ItemStack>
use(World world, PlayerEntity user, Hand hand)
Called when an item is used by a player.ActionResult
useOnBlock(ItemUsageContext context)
Called when an item is used on a block.ActionResult
useOnEntity(ItemStack stack, PlayerEntity user, LivingEntity entity, Hand hand)
-
Field Details
-
BLOCK_ITEMS
-
ATTACK_DAMAGE_MODIFIER_ID
-
ATTACK_SPEED_MODIFIER_ID
-
RANDOM
-
group
-
rarity
-
maxCount
private final int maxCount -
maxDamage
private final int maxDamage -
fireproof
private final boolean fireproof -
recipeRemainder
-
translationKey
-
foodComponent
-
-
Constructor Details
-
Item
-
-
Method Details
-
getRawId
-
byRawId
-
fromBlock
Deprecated. -
usageTick
-
postProcessTag
-
canMine
Checks if a player can break a block while holding the item. -
asItem
Gets this object in its item form.- Specified by:
asItem
in interfaceItemConvertible
-
useOnBlock
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
-
use
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 inuser
- the player who used the itemhand
- 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
-
getMaxCount
public final int getMaxCount() -
getMaxDamage
public final int getMaxDamage() -
isDamageable
public boolean isDamageable() -
postHit
-
postMine
public boolean postMine(ItemStack stack, World world, BlockState state, BlockPos pos, LivingEntity miner) -
isEffectiveOn
-
useOnEntity
public ActionResult useOnEntity(ItemStack stack, PlayerEntity user, LivingEntity entity, Hand hand) -
getName
-
toString
-
getOrCreateTranslationKey
-
getTranslationKey
Gets the translation key of this item. -
getTranslationKey
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
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
-
onCraft
Called when a player acquires the item by crafting, smelting, smithing, etc. -
isNetworkSynced
public boolean isNetworkSynced() -
getUseAction
-
getMaxUseTime
-
onStoppedUsing
-
appendTooltip
-
getName
-
hasGlint
Checks if the glint effect should be applied when the item is rendered.By default, returns true if the item has enchantments.
-
getRarity
-
isEnchantable
-
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
-
isIn
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
-
canRepair
-
getAttributeModifiers
public Multimap<EntityAttribute,EntityAttributeModifier> getAttributeModifiers(EquipmentSlot slot) -
isUsedOnRelease
-
getDefaultStack
-
isIn
-
isFood
public boolean isFood()Checks if this item is food and therefore is edible. -
getFoodComponent
-
getDrinkSound
-
getEatSound
-
isFireproof
public boolean isFireproof() -
damage
-