public class Item extends Object implements ItemConvertible
Modifier and Type | Class and Description |
---|---|
static class |
Item.Settings |
Modifier and Type | Field and 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 and Description |
---|
Item(Item.Settings settings) |
Modifier and Type | Method and 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) |
protected static final UUID ATTACK_DAMAGE_MODIFIER_ID
protected static final UUID ATTACK_SPEED_MODIFIER_ID
protected static final Random RANDOM
protected final ItemGroup group
private final Rarity rarity
private final int maxCount
private final int maxDamage
private final boolean fireproof
private final Item recipeRemainder
@Nullable private final FoodComponent foodComponent
public Item(Item.Settings settings)
public static int getRawId(Item item)
public static Item byRawId(int id)
@Deprecated public static Item fromBlock(Block block)
public void usageTick(World world, LivingEntity user, ItemStack stack, int remainingUseTicks)
public boolean postProcessTag(CompoundTag tag)
public boolean canMine(BlockState state, World world, BlockPos pos, PlayerEntity miner)
public Item asItem()
asItem
in interface ItemConvertible
public ActionResult useOnBlock(ItemUsageContext context)
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()
.
context
- the usage contextpublic float getMiningSpeedMultiplier(ItemStack stack, BlockState state)
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand)
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()
.
world
- the world the item was used inuser
- the player who used the itemhand
- the hand usedpublic ItemStack finishUsing(ItemStack stack, World world, LivingEntity user)
public final int getMaxCount()
public final int getMaxDamage()
public boolean isDamageable()
public boolean postHit(ItemStack stack, LivingEntity target, LivingEntity attacker)
public boolean postMine(ItemStack stack, World world, BlockState state, BlockPos pos, LivingEntity miner)
public boolean isEffectiveOn(BlockState state)
public ActionResult useOnEntity(ItemStack stack, PlayerEntity user, LivingEntity entity, Hand hand)
@Environment(value=CLIENT) public Text getName()
protected String getOrCreateTranslationKey()
public String getTranslationKey()
public String getTranslationKey(ItemStack stack)
public boolean shouldSyncTagToClient()
#tag
sent to the client.
If an item is damageable, this method is ignored and data is always synced to client.
@Nullable public final Item getRecipeRemainder()
public boolean hasRecipeRemainder()
public void inventoryTick(ItemStack stack, World world, Entity entity, int slot, boolean selected)
public void onCraft(ItemStack stack, World world, PlayerEntity player)
public boolean isNetworkSynced()
public int getMaxUseTime(ItemStack stack)
public void onStoppedUsing(ItemStack stack, World world, LivingEntity user, int remainingUseTicks)
@Environment(value=CLIENT) public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> tooltip, TooltipContext context)
public boolean hasGlint(ItemStack stack)
By default, returns true if the item has enchantments.
public boolean isEnchantable(ItemStack stack)
protected static BlockHitResult raycast(World world, PlayerEntity player, RaycastContext.FluidHandling fluidHandling)
public int getEnchantability()
If the value of this method is 0, the item cannot be enchanted using an enchanting table.
public void appendStacks(ItemGroup group, DefaultedList<ItemStack> stacks)
protected boolean isIn(ItemGroup group)
ItemGroup.SEARCH
.public Multimap<EntityAttribute,EntityAttributeModifier> getAttributeModifiers(EquipmentSlot slot)
public boolean isUsedOnRelease(ItemStack stack)
public ItemStack getDefaultStack()
public boolean isFood()
@Nullable public FoodComponent getFoodComponent()
public SoundEvent getDrinkSound()
public SoundEvent getEatSound()
public boolean isFireproof()
public boolean damage(DamageSource source)