Package net.minecraft.world.item
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic interface -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final ResourceLocationstatic final ResourceLocationprivate final Holder.Reference<Item> protected final booleanprivate DataComponentMapprivate final Itemstatic final intprivate Stringprivate static final org.slf4j.Loggerstatic final intprivate final FeatureFlagSetFields inherited from interface net.minecraft.world.flag.FeatureElement
FILTERED_REGISTRIES -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidappendHoverText(ItemStack stack, Item.TooltipContext context, List<Component> tooltipComponents, TooltipFlag tooltipFlag) asItem()Deprecated.static ItemDeprecated.static ItembyId(int id) booleancanAttackBlock(BlockState state, Level level, BlockPos pos, Player player) booleanfinishUsingItem(ItemStack stack, Level level, LivingEntity livingEntity) Called when the player finishes using this Item (E.g.floatgetAttackDamageBonus(Entity target, float damage, DamageSource damageSource) intgetBarColor(ItemStack stack) intgetBarWidth(ItemStack stack) final ItemDeprecated.Deprecated.intgetDescriptionId(ItemStack stack) Returns the unlocalized name of this item.floatgetDestroySpeed(ItemStack stack, BlockState state) intDeprecated.Neo: Use ItemStack sensitive version.static intprotected Stringstatic BlockHitResultgetPlayerPOVHitResult(Level level, Player player, ClipContext.Fluid fluidMode) getTooltipImage(ItemStack stack) getUseAnimation(ItemStack stack) Returns the action that specifies what animation to play when the item is being used.intgetUseDuration(ItemStack stack, LivingEntity entity) booleanDeprecated.booleanhurtEnemy(ItemStack stack, LivingEntity target, LivingEntity attacker) Current implementations of this method in child classes do not use the entry argument beside ev.voidinitializeClient(Consumer<IClientItemExtensions> consumer) Deprecated, for removal: This API element is subject to removal in a future version.UseRegisterClientExtensionsEventinsteadinteractLivingEntity(ItemStack stack, Player player, LivingEntity interactionTarget, InteractionHand usedHand) Try interacting with given entity.voidinventoryTick(ItemStack stack, Level level, Entity entity, int slotId, boolean isSelected) Called each tick as long the item is in a player's inventory.booleanisBarVisible(ItemStack stack) booleanbooleanisCorrectToolForDrops(ItemStack stack, BlockState state) booleanisEnchantable(ItemStack stack) Checks isDamagable and if it cannot be stackedbooleanReturnstrueif this item has an enchantment glint.booleanisRepairable(ItemStack stack) Called by CraftingManager to determine if an item is reparable.booleanisValidRepairItem(ItemStack stack, ItemStack repairCandidate) Return whether this item is repairable in an anvil.booleanmineBlock(ItemStack stack, Level level, BlockState state, BlockPos pos, LivingEntity miningEntity) Called when aBlockis destroyed using this Item.voidDeprecated.Neo: do not use, usethe eventinsteadvoidonCraftedBy(ItemStack stack, Level level, Player player) Called when item is crafted/smelted.voidonCraftedPostProcess(ItemStack stack, Level level) voidonDestroyed(ItemEntity itemEntity) Deprecated.voidonUseTick(Level level, LivingEntity livingEntity, ItemStack stack, int remainingUseDuration) Called as the item is being used by an entity.booleanoverrideOtherStackedOnMe(ItemStack stack, ItemStack other, Slot slot, ClickAction action, Player player, SlotAccess access) booleanoverrideStackedOnOther(ItemStack stack, Slot slot, ClickAction action, Player player) voidpostHurtEnemy(ItemStack stack, LivingEntity target, LivingEntity attacker) voidreleaseUsing(ItemStack stack, Level level, LivingEntity livingEntity, int timeCharged) Called when the player stops using an Item (stops holding the right mouse button).toString()use(Level level, Player player, InteractionHand usedHand) Called to trigger the item's "innate" right click behavior.useOn(UseOnContext context) Called when this item is used when targeting a BlockbooleanuseOnRelease(ItemStack stack) If this stack's item is a crossbowvoidMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface net.minecraft.world.flag.FeatureElement
isEnabledMethods inherited from interface net.neoforged.neoforge.common.extensions.IItemExtension
applyEnchantments, canBeHurtBy, canContinueUsing, canDisableShield, canElytraFly, canEquip, canGrindstoneRepair, canPerformAction, canWalkOnPowderedSnow, createEntity, damageItem, doesSneakBypassUse, elytraFlightTick, getAllEnchantments, getArmorTexture, getBurnTime, getCraftingRemainingItem, getCreatorModId, getDamage, getDefaultAttributeModifiers, getEnchantmentLevel, getEnchantmentValue, getEntityLifespan, getEquipmentSlot, getFoodProperties, getHighlightTip, getMaxDamage, getMaxStackSize, getSweepHitBox, getXpRepairRatio, hasCraftingRemainingItem, hasCustomEntity, isBookEnchantable, isDamageable, isDamaged, isEnderMask, isNotReplaceableByPickAction, isPiglinCurrency, isPrimaryItemFor, makesPiglinsNeutral, onAnimalArmorTick, onDestroyed, onDroppedByPlayer, onEntityItemUpdate, onEntitySwing, onEntitySwing, onItemUseFirst, onLeftClickEntity, onStopUsing, setDamage, shouldCauseBlockBreakReset, shouldCauseReequipAnimation, supportsEnchantment
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
BY_BLOCK
-
BASE_ATTACK_DAMAGE_ID
-
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
-
components
-
craftingRemainingItem
-
descriptionId
-
requiredFeatures
-
canRepair
protected final boolean canRepair
-
-
Constructor Details
-
Item
-
-
Method Details
-
getId
-
byId
-
byBlock
Deprecated. -
builtInRegistryHolder
Deprecated. -
components
-
modifyDefaultComponentsFrom
Deprecated.Neo: do not use, usethe eventinstead -
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. -
verifyComponentsAfterLoad
-
canAttackBlock
-
asItem
-
useOn
Called when this item is used when targeting a Block -
getDestroySpeed
-
use
Called to trigger the item's "innate" right click behavior. To handle when this item is used on a Block, seeuseOn(net.minecraft.world.item.context.UseOnContext). -
finishUsingItem
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
-
getBarWidth
-
getBarColor
-
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
-
hurtEnemy
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
-
mineBlock
public boolean mineBlock(ItemStack stack, Level level, BlockState state, BlockPos pos, LivingEntity miningEntity) Called when aBlockis destroyed using this Item. Returntrueto trigger the "Use Item" statistic. -
isCorrectToolForDrops
-
interactLivingEntity
public InteractionResult interactLivingEntity(ItemStack stack, Player player, LivingEntity interactionTarget, InteractionHand usedHand) Try interacting with given entity. ReturnInteractionResult.PASSif nothing should happen. -
getDescription
-
toString
-
getOrCreateDescriptionId
-
getDescriptionId
-
getDescriptionId
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
Deprecated. -
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
Called when item is crafted/smelted. Used only by maps so far. -
onCraftedPostProcess
-
isComplex
public boolean isComplex() -
getUseAnimation
Returns the action that specifies what animation to play when the item is being used. -
getUseDuration
-
releaseUsing
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
-
getName
-
isFoil
Returnstrueif this item has an enchantment glint. By default, this returnsstack.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 (onItem) to get the glint for enchanted items. Of course, that is unnecessary if the overwritten version always returns true. -
isEnchantable
Checks isDamagable and if it cannot be stacked -
getPlayerPOVHitResult
public static BlockHitResult getPlayerPOVHitResult(Level level, Player player, ClipContext.Fluid fluidMode) -
getEnchantmentValue
Deprecated.Neo: Use ItemStack sensitive version. -
isValidRepairItem
Return whether this item is repairable in an anvil. -
getDefaultAttributeModifiers
Deprecated. -
isRepairable
Description copied from interface:IItemExtensionCalled by CraftingManager to determine if an item is reparable.- Specified by:
isRepairablein interfaceIItemExtension- Returns:
- True if reparable
-
useOnRelease
If this stack's item is a crossbow -
getDefaultInstance
-
getDrinkingSound
-
getEatingSound
-
getBreakingSound
-
canFitInsideContainerItems
public boolean canFitInsideContainerItems() -
requiredFeatures
- Specified by:
requiredFeaturesin interfaceFeatureElement
-
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.UseRegisterClientExtensionsEventinsteadNeo: Allowing mods to define client behavior for their Items
-
IItemExtension.getDefaultAttributeModifiers(ItemStack)