Class Item
- All Implemented Interfaces:
ItemConvertible
- Direct Known Subclasses:
AirBlockItem,ArmorItem,ArmorStandItem,ArrowItem,BannerPatternItem,BlockItem,BoatItem,BoneMealItem,BookItem,BucketItem,BundleItem,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,SpyglassItem,SuspiciousStewItem,ToolItem,TridentItem,WritableBookItem,WrittenBookItem
public class Item extends Object implements ItemConvertible
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classItem.Settings -
Field Summary
Fields Modifier and Type Field Description protected static UUIDATTACK_DAMAGE_MODIFIER_IDprotected static UUIDATTACK_SPEED_MODIFIER_IDstatic Map<Block,Item>BLOCK_ITEMSprivate static Loggerfield_27017private booleanfireproofprivate FoodComponentfoodComponentprotected ItemGroupgroupprivate intmaxCountprivate intmaxDamageprivate Rarityrarityprivate ItemrecipeRemainderprivate StringtranslationKey -
Constructor Summary
Constructors Constructor Description Item(Item.Settings settings) -
Method Summary
Modifier and Type Method Description voidappendStacks(ItemGroup group, DefaultedList<ItemStack> stacks)voidappendTooltip(ItemStack stack, World world, List<Text> tooltip, TooltipContext context)ItemasItem()Gets this object in its item form.static ItembyRawId(int id)booleancanMine(BlockState state, World world, BlockPos pos, PlayerEntity miner)Checks if a player can break a block while holding the item.booleancanRepair(ItemStack stack, ItemStack ingredient)booleandamage(DamageSource source)ItemStackfinishUsing(ItemStack stack, World world, LivingEntity livingEntity)static ItemfromBlock(Block block)Deprecated.Multimap<EntityAttribute,EntityAttributeModifier>getAttributeModifiers(EquipmentSlot slot)ItemStackgetDefaultStack()SoundEventgetDrinkSound()SoundEventgetEatSound()intgetEnchantability()Gets the enchantability of an item.SoundEventgetEquipSound()FoodComponentgetFoodComponent()ItemGroupgetGroup()intgetItemBarColor(ItemStack stack)intgetItemBarStep(ItemStack stack)intgetMaxCount()intgetMaxDamage()intgetMaxUseTime(ItemStack stack)floatgetMiningSpeedMultiplier(ItemStack stack, BlockState state)TextgetName()TextgetName(ItemStack stack)protected StringgetOrCreateTranslationKey()RaritygetRarity(ItemStack stack)static intgetRawId(Item item)ItemgetRecipeRemainder()Gets the remainder item that should be left behind when this item is used as a crafting ingredient.Optional<TooltipData>getTooltipData(ItemStack stack)StringgetTranslationKey()Gets the translation key of this item.StringgetTranslationKey(ItemStack stack)Gets the translation key of this item using the provided item stack for context.UseActiongetUseAction(ItemStack stack)booleanhasGlint(ItemStack stack)Checks if the glint effect should be applied when the item is rendered.booleanhasRecipeRemainder()Checks if this item has a remainder item that is left behind when used as a crafting ingredient.booleanhasStoredInventory()voidinventoryTick(ItemStack stack, World world, Entity entity, int slot, boolean selected)booleanisDamageable()booleanisEnchantable(ItemStack stack)booleanisFireproof()booleanisFood()Checks if this item is food and therefore is edible.protected booleanisIn(ItemGroup group)Checks whether this item should appear in a specified item group.booleanisItemBarVisible(ItemStack stack)booleanisNetworkSynced()booleanisSuitableFor(BlockState state)Determines whether this item can be used as a suitable tool for mining the specified block.booleanisUsedOnRelease(ItemStack stack)voidmethod_33261(ItemEntity itemEntity)booleanonClicked(ItemStack stack, ItemStack otherStack, Slot slot, ClickType clickType, PlayerInventory playerInventory)voidonCraft(ItemStack stack, World world, PlayerEntity player)Called when a player acquires the item by crafting, smelting, smithing, etc.booleanonStackClicked(ItemStack stack, Slot slot, ClickType clickType, PlayerInventory playerInventory)voidonStoppedUsing(ItemStack stack, World world, LivingEntity user, int remainingUseTicks)booleanpostHit(ItemStack stack, LivingEntity target, LivingEntity attacker)booleanpostMine(ItemStack stack, World world, BlockState state, BlockPos pos, LivingEntity miner)booleanpostProcessTag(CompoundTag tag)protected static BlockHitResultraycast(World world, PlayerEntity player, RaycastContext.FluidHandling fluidHandling)booleanshouldSyncTagToClient()Checks if an item should have its NBT data stored inItemStack.tagsent to the client.StringtoString()voidusageTick(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.ActionResultuseOnBlock(ItemUsageContext context)Called when an item is used on a block.ActionResultuseOnEntity(ItemStack stack, PlayerEntity user, LivingEntity entity, Hand hand)
-
Field Details
-
field_27017
-
BLOCK_ITEMS
-
ATTACK_DAMAGE_MODIFIER_ID
-
ATTACK_SPEED_MODIFIER_ID
-
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.Please useBlock.asItem() -
usageTick
-
method_33261
-
postProcessTag
-
canMine
Checks if a player can break a block while holding the item. -
asItem
Gets this object in its item form.- Specified by:
asItemin 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() -
isItemBarVisible
-
getItemBarStep
-
getItemBarColor
-
onStackClicked
public boolean onStackClicked(ItemStack stack, Slot slot, ClickType clickType, PlayerInventory playerInventory) -
onClicked
public boolean onClicked(ItemStack stack, ItemStack otherStack, Slot slot, ClickType clickType, PlayerInventory playerInventory) -
postHit
-
postMine
public boolean postMine(ItemStack stack, World world, BlockState state, BlockPos pos, LivingEntity miner) -
isSuitableFor
Determines whether this item can be used as a suitable tool for mining the specified block. Depending on block implementation, when combined together, the correct item and block may achieve a better mining speed and yield drops that would not be obtained when mining otherwise.Note that this is not the only way to achieve "effectiveness" when mining. Other items, such as shears on string, may use their own logic and calls to this method might not return a value consistent to this rule for those items.
-
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 inItemStack.tagsent 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
-
getTooltipData
-
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
-
isFood
public boolean isFood()Checks if this item is food and therefore is edible. -
getFoodComponent
-
getDrinkSound
-
getEatSound
-
isFireproof
public boolean isFireproof() -
damage
-
getEquipSound
-
hasStoredInventory
public boolean hasStoredInventory()
-
Block.asItem()