Class Item

java.lang.Object
cn.nukkit.item.Item
All Implemented Interfaces:
BlockID, ItemID, Cloneable
Direct Known Subclasses:
ItemAmethystShard, ItemArmor, ItemArmorStand, ItemArrow, ItemBanner, ItemBannerPattern, ItemBed, ItemBlazePowder, ItemBlazeRod, ItemBlock, ItemBoat, ItemBone, ItemBook, ItemBookEnchanted, ItemBookWritable, ItemBowl, ItemBrewingStand, ItemBrick, ItemBucket, ItemCake, ItemCampfire, ItemCampfireSoul, ItemCauldron, ItemChain, ItemChestBoatBase, ItemChorusFruitPopped, ItemClay, ItemClock, ItemCoal, ItemCompass, ItemCompassLodestone, ItemDiamond, ItemDiscFragment5, ItemDoorAcacia, ItemDoorBirch, ItemDoorCrimson, ItemDoorDarkOak, ItemDoorIron, ItemDoorJungle, ItemDoorMangrove, ItemDoorSpruce, ItemDoorWarped, ItemDoorWood, ItemDragonBreath, ItemDye, ItemEchoShard, ItemEdible, ItemEmerald, ItemEmptyMap, ItemEndCrystal, ItemEnderEye, ItemFeather, ItemFireCharge, ItemFirework, ItemFireworkStar, ItemFlint, ItemFlowerPot, ItemGhastTear, ItemGlassBottle, ItemGlowstoneDust, ItemGunpowder, ItemHeartOfTheSea, ItemHoneycomb, ItemHopper, ItemHorseArmorDiamond, ItemHorseArmorGold, ItemHorseArmorIron, ItemHorseArmorLeather, ItemIngotGold, ItemIngotIron, ItemIngotNetherite, ItemItemFrame, ItemItemFrameGlow, ItemKelp, ItemLead, ItemLeather, ItemMagmaCream, ItemMap, ItemMelonGlistering, ItemMinecart, ItemMinecartChest, ItemMinecartHopper, ItemMinecartTNT, ItemNameTag, ItemNautilusShell, ItemNetherBrick, ItemNetherSprouts, ItemNetherStar, ItemNetherWart, ItemNuggetGold, ItemNuggetIron, ItemPainting, ItemPaper, ItemPhantomMembrane, ItemPotion, ItemPrismarineCrystals, ItemPrismarineShard, ItemQuartz, ItemRabbitFoot, ItemRabbitHide, ItemRecord, ItemRedstone, ItemRedstoneComparator, ItemRedstoneRepeater, ItemSaddle, ItemScrapNetherite, ItemScute, ItemSeedsBeetroot, ItemSeedsMelon, ItemSeedsPumpkin, ItemSeedsWheat, ItemShulkerShell, ItemSign, ItemSkull, ItemSlimeball, ItemSpawnEgg, ItemSpiderEyeFermented, ItemSpyglass, ItemStick, ItemString, ItemSugar, ItemSugarcane, ItemTool, ItemTotem, ItemWheat, ProjectileItem, StringItem

public class Item extends Object implements Cloneable, BlockID, ItemID
Author:
MagicDroidX (Nukkit Project)
  • Field Details

    • EMPTY_ARRAY

      @PowerNukkitOnly @Since("1.4.0.0-PN") public static final Item[] EMPTY_ARRAY
    • UNKNOWN_STR

      protected static String UNKNOWN_STR
    • list

      public static Class[] list
    • block

      protected Block block
    • id

      protected final int id
    • meta

      protected int meta
    • hasMeta

      protected boolean hasMeta
    • count

      public int count
    • durability

      @Deprecated @DeprecationDetails(since="1.4.0.0-PN", by="PowerNukkit", reason="Unused", replaceWith="meta or getDamage()") protected int durability
      Deprecated.
    • name

      protected String name
  • Constructor Details

    • Item

      public Item(int id)
    • Item

      public Item(int id, Integer meta)
    • Item

      public Item(int id, Integer meta, int count)
    • Item

      public Item(int id, Integer meta, int count, String name)
  • Method Details

    • hasMeta

      public boolean hasMeta()
    • canBeActivated

      public boolean canBeActivated()
    • init

      public static void init()
    • rebuildItemList

      @PowerNukkitOnly @Since("1.4.0.0-PN") public static List<String> rebuildItemList()
    • getItemList

      @PowerNukkitOnly @Since("1.4.0.0-PN") public static List<String> getItemList()
    • registerCustomItem

      @PowerNukkitXOnly @Since("1.6.0.0-PNX") public static void registerCustomItem(Class<? extends ItemCustom> c)
      注册自定义物品
      Parameters:
      c - 传入自定义物品类的实例
    • registerCustomItem

      @PowerNukkitXOnly @Since("1.6.0.0-PNX") public static void registerCustomItem(@Nonnull List<Class<? extends ItemCustom>> itemClassList)
      注册自定义方块
      Parameters:
      itemClassList - 传入自定义物品class List
    • deleteCustomItem

      @PowerNukkitXOnly @Since("1.6.0.0-PNX") public static void deleteCustomItem(String namespaceId)
      卸载指定的自定义物品
      Parameters:
      namespaceId - 传入自定义物品的namespaceId
    • deleteAllCustomItem

      @PowerNukkitXOnly @Since("1.6.0.0-PNX") public static void deleteAllCustomItem()
      卸载全部的自定义物品
    • getCustomItems

      @PowerNukkitXOnly @Since("1.6.0.0-PNX") public static HashMap<String,Class<? extends Item>> getCustomItems()
    • getCustomItemDefinition

      @PowerNukkitXOnly @Since("1.19.31-r1") public static HashMap<String,CustomItemDefinition> getCustomItemDefinition()
    • clearCreativeItems

      public static void clearCreativeItems()
    • getCreativeItems

      public static ArrayList<Item> getCreativeItems()
    • addCreativeItem

      public static void addCreativeItem(Item item)
    • removeCreativeItem

      public static void removeCreativeItem(Item item)
    • isCreativeItem

      public static boolean isCreativeItem(Item item)
    • getCreativeItem

      public static Item getCreativeItem(int index)
    • getCreativeItemIndex

      public static int getCreativeItemIndex(Item item)
    • getBlock

      @PowerNukkitOnly public static Item getBlock(int id)
    • getBlock

      @PowerNukkitOnly public static Item getBlock(int id, Integer meta)
    • getBlock

      @PowerNukkitOnly public static Item getBlock(int id, Integer meta, int count)
    • getBlock

      @PowerNukkitOnly public static Item getBlock(int id, Integer meta, int count, byte[] tags)
    • get

      public static Item get(int id)
    • get

      public static Item get(int id, Integer meta)
    • get

      public static Item get(int id, Integer meta, int count)
    • get

      @PowerNukkitDifference(info="Prevents players from getting invalid items by limiting the return to the maximum damage defined in Block.getMaxItemDamage()", since="1.4.0.0-PN") public static Item get(int id, Integer meta, int count, byte[] tags)
    • fromString

      @PowerNukkitDifference(since="1.4.0.0-PN", info="Improve namespaced name handling and allows to get custom blocks by name") public static Item fromString(String str)
    • fromJson

      public static Item fromJson(Map<String,Object> data)
    • fromJsonNetworkId

      @PowerNukkitOnly @Since("1.4.0.0-PN") public static Item fromJsonNetworkId(Map<String,Object> data)
    • fromStringMultiple

      public static Item[] fromStringMultiple(String str)
    • setCompoundTag

      public Item setCompoundTag(CompoundTag tag)
    • setCompoundTag

      public Item setCompoundTag(byte[] tags)
    • getCompoundTag

      public byte[] getCompoundTag()
    • hasCompoundTag

      public boolean hasCompoundTag()
    • hasCustomCompoundTag

      @PowerNukkitOnly @Since("FUTURE") public boolean hasCustomCompoundTag()
    • getCustomCompoundTag

      @PowerNukkitOnly @Since("FUTURE") public byte[] getCustomCompoundTag()
    • hasCustomBlockData

      public boolean hasCustomBlockData()
    • clearCustomBlockData

      public Item clearCustomBlockData()
    • setCustomBlockData

      public Item setCustomBlockData(CompoundTag compoundTag)
    • getCustomBlockData

      public CompoundTag getCustomBlockData()
    • applyEnchantments

      @PowerNukkitXOnly @Since("1.6.0.0-PNX") public boolean applyEnchantments()
    • hasEnchantments

      public boolean hasEnchantments()
    • getEnchantmentLevel

      @PowerNukkitOnly @Since("1.4.0.0-PN") public int getEnchantmentLevel(int id)
      Find the enchantment level by the enchantment id.
      Parameters:
      id - The enchantment ID from Enchantment constants.
      Returns:
      0 if the item don't have that enchantment or the current level of the given enchantment.
    • getEnchantment

      public Enchantment getEnchantment(int id)
    • getEnchantment

      public Enchantment getEnchantment(short id)
    • addEnchantment

      public void addEnchantment(Enchantment... enchantments)
    • getEnchantments

      public Enchantment[] getEnchantments()
    • hasEnchantment

      @Since("1.4.0.0-PN") public boolean hasEnchantment(int id)
      Convenience method to check if the item stack has positive level on a specific enchantment by it's id.
      Parameters:
      id - The enchantment ID from Enchantment constants.
    • getAttackSideEffects

      @PowerNukkitOnly @Since("1.5.1.0-PN") @Nonnull public SideEffect[] getAttackSideEffects(@Nonnull Entity attacker, @Nonnull Entity entity)
    • getRepairCost

      @Since("1.4.0.0-PN") public int getRepairCost()
    • setRepairCost

      @Since("1.4.0.0-PN") public Item setRepairCost(int cost)
    • hasCustomName

      public boolean hasCustomName()
    • getCustomName

      public String getCustomName()
    • setCustomName

      public Item setCustomName(String name)
    • clearCustomName

      public Item clearCustomName()
    • getLore

      public String[] getLore()
    • setLore

      public Item setLore(String... lines)
    • getNamedTagEntry

      public Tag getNamedTagEntry(String name)
    • getNamedTag

      public CompoundTag getNamedTag()
    • getOrCreateNamedTag

      public CompoundTag getOrCreateNamedTag()
    • setNamedTag

      public Item setNamedTag(CompoundTag tag)
    • clearNamedTag

      public Item clearNamedTag()
    • parseCompoundTag

      public static CompoundTag parseCompoundTag(byte[] tag)
    • writeCompoundTag

      public byte[] writeCompoundTag(CompoundTag tag)
    • getCount

      public int getCount()
    • setCount

      public void setCount(int count)
    • isNull

      public boolean isNull()
    • getName

      public final String getName()
    • canBePlaced

      public final boolean canBePlaced()
    • getBlock

      public Block getBlock()
    • getBlockUnsafe

      @Since("1.4.0.0-PN") public Block getBlockUnsafe()
    • getId

      public int getId()
    • getNetworkFullId

      @PowerNukkitOnly @Since("1.4.0.0-PN") public final int getNetworkFullId() throws UnknownNetworkIdException
      Throws:
      UnknownNetworkIdException
    • getNamespaceId

      @PowerNukkitOnly @Since("1.4.0.0-PN") public String getNamespaceId()
    • getBlockId

      @PowerNukkitOnly @Since("1.4.0.0-PN") public int getBlockId()
    • getDamage

      public int getDamage()
    • setDamage

      public void setDamage(Integer meta)
    • createFuzzyCraftingRecipe

      @PowerNukkitOnly @Since("1.4.0.0-PN") public Item createFuzzyCraftingRecipe()
    • getMaxStackSize

      public int getMaxStackSize()
    • getFuelTime

      public final Short getFuelTime()
    • useOn

      public boolean useOn(Entity entity)
    • useOn

      public boolean useOn(Block block)
    • isTool

      public boolean isTool()
    • getMaxDurability

      public int getMaxDurability()
    • getTier

      public int getTier()
    • isPickaxe

      public boolean isPickaxe()
    • isAxe

      public boolean isAxe()
    • isSword

      public boolean isSword()
    • isShovel

      public boolean isShovel()
    • isHoe

      public boolean isHoe()
    • isShears

      public boolean isShears()
    • isArmor

      public boolean isArmor()
    • isHelmet

      public boolean isHelmet()
    • isChestplate

      public boolean isChestplate()
    • isLeggings

      public boolean isLeggings()
    • isBoots

      public boolean isBoots()
    • getEnchantAbility

      public int getEnchantAbility()
    • getAttackDamage

      public int getAttackDamage()
    • getArmorPoints

      public int getArmorPoints()
    • getToughness

      public int getToughness()
    • isUnbreakable

      public boolean isUnbreakable()
    • isLavaResistant

      @PowerNukkitOnly @Since("1.4.0.0-PN") public boolean isLavaResistant()
      If the item is resistant to lava and fire and can float on lava like if it was on water.
      Since:
      1.4.0.0-PN
    • canBreakShield

      @PowerNukkitXOnly @Since("1.19.21-r4") public boolean canBreakShield()
    • onUse

      public boolean onUse(Player player, int ticksUsed)
    • onRelease

      public boolean onRelease(Player player, int ticksUsed)
      Allows the item to execute code when the player releases the item after long clicking it.
      Parameters:
      player - The player who released the click button
      ticksUsed - How many ticks the item was held.
      Returns:
      If an inventory contents update should be sent to the player
    • toString

      public final String toString()
      Overrides:
      toString in class Object
    • getDestroySpeed

      public int getDestroySpeed(Block block, Player player)
    • onActivate

      public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz)
    • decrement

      @PowerNukkitOnly @Since("1.4.0.0-PN") public final Item decrement(int amount)
    • increment

      @PowerNukkitOnly @Since("1.4.0.0-PN") public final Item increment(int amount)
    • isFertilizer

      @Since("1.4.0.0-PN") @PowerNukkitOnly public boolean isFertilizer()
      When true, this item can be used to reduce growing times like a bone meal.
      Returns:
      true if it can act like a bone meal
    • onClickAir

      public boolean onClickAir(Player player, Vector3 directionVector)
      Called when a player uses the item on air, for example throwing a projectile. Returns whether the item was changed, for example count decrease or durability change.
      Parameters:
      player - player
      directionVector - direction
      Returns:
      item changed
    • equals

      public final boolean equals(Object item)
      Overrides:
      equals in class Object
    • equals

      public final boolean equals(Item item, boolean checkDamage)
    • equals

      public final boolean equals(Item item, boolean checkDamage, boolean checkCompound)
    • equalsExact

      public final boolean equalsExact(Item other)
      Returns whether the specified item stack has the same ID, damage, NBT and count as this item stack.
      Parameters:
      other - item
      Returns:
      equal
    • equalsIgnoringEnchantmentOrder

      @PowerNukkitOnly @Since("1.2.1.0-PN") public final boolean equalsIgnoringEnchantmentOrder(Item item, boolean checkDamage)
      Same as equals(Item, boolean) but the enchantment order of the items does not affect the result.
      Since:
      1.2.1.0-PN
    • deepEquals

      @Deprecated public final boolean deepEquals(Item item)
      Deprecated.
    • deepEquals

      @Deprecated public final boolean deepEquals(Item item, boolean checkDamage)
      Deprecated.
    • deepEquals

      @Deprecated public final boolean deepEquals(Item item, boolean checkDamage, boolean checkCompound)
      Deprecated.
    • clone

      public Item clone()
      Overrides:
      clone in class Object
    • getNetworkId

      @Since("1.4.0.0-PN") public final int getNetworkId() throws UnknownNetworkIdException
      Throws:
      UnknownNetworkIdException
    • addCanPlaceOn

      @PowerNukkitXOnly @Since("1.6.0.0-PNX") public void addCanPlaceOn(Block block)
    • addCanPlaceOn

      @PowerNukkitXOnly @Since("1.6.0.0-PNX") public void addCanPlaceOn(Block[] blocks)
    • setCanPlaceOn

      @PowerNukkitXOnly @Since("1.6.0.0-PNX") public void setCanPlaceOn(Block[] blocks)
    • getCanPlaceOn

      @PowerNukkitXOnly @Since("1.6.0.0-PNX") public ListTag<StringTag> getCanPlaceOn()
    • addCanDestroy

      @PowerNukkitXOnly @Since("1.6.0.0-PNX") public void addCanDestroy(Block block)
    • addCanDestroy

      @PowerNukkitXOnly @Since("1.6.0.0-PNX") public void addCanDestroy(Block[] blocks)
    • setCanDestroy

      @PowerNukkitXOnly @Since("1.6.0.0-PNX") public void setCanDestroy(Block[] blocks)
    • getCanDestroy

      @PowerNukkitXOnly @Since("1.6.0.0-PNX") public ListTag<StringTag> getCanDestroy()
    • setItemLockMode

      @PowerNukkitXOnly @Since("1.6.0.0-PNX") public void setItemLockMode(Item.ItemLockMode mode)
    • getItemLockMode

      @PowerNukkitXOnly @Since("1.6.0.0-PNX") public Item.ItemLockMode getItemLockMode()
    • setKeepOnDeath

      @PowerNukkitXOnly @Since("1.6.0.0-PNX") public void setKeepOnDeath(boolean keepOnDeath)
    • keepOnDeath

      @PowerNukkitXOnly @Since("1.6.0.0-PNX") public boolean keepOnDeath()
    • readItemJsonComponents

      @PowerNukkitXOnly @Since("1.6.0.0-PNX") public void readItemJsonComponents(Item.ItemJsonComponents components)