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, StringItemBase

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

  • 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()
      重构项目物品列表

      rebuild ItemList

    • getItemList

      @PowerNukkitOnly @Since("1.4.0.0-PN") public static List<String> getItemList()
      获取项目物品列表也可以获取重构物品列表

      Get the list of item items and also get the list of reconstructed items

    • registerCustomItem

      @PowerNukkitXOnly @Since("1.6.0.0-PNX") public static OK<?> registerCustomItem(Class<? extends CustomItem> c)
      注册自定义物品

      Register custom item

      Parameters:
      c - 传入自定义物品类的实例

      Import in an instance of a custom item class

    • registerCustomItem

      @PowerNukkitXOnly @Since("1.6.0.0-PNX") public static OK<?> registerCustomItem(@NotNull List<Class<? extends CustomItem>> itemClassList)
      注册自定义物品

      Register custom item

      Parameters:
      itemClassList - 传入自定义物品class List
      Import custom items class List
    • deleteCustomItem

      @PowerNukkitXOnly @Since("1.6.0.0-PNX") public static void deleteCustomItem(String namespaceId)
      卸载自定义物品

      Remove custom items

      Parameters:
      namespaceId - 传入自定义物品的namespaceId
    • deleteAllCustomItem

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

      Remove all custom items

    • getCustomItems

      @PowerNukkitXOnly @Since("1.6.0.0-PNX") public static HashMap<String,Supplier<? extends Item>> getCustomItems()
      用于获取发送给客户端的自定义物品数据

      Used to get the custom item data sent to the client

    • getCustomItemDefinition

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

      public static void clearCreativeItems()
      取消创造模式下创造背包中的物品

      Cancel the Creative of items in the backpack in Creative mode

    • getCreativeItems

      public static ArrayList<Item> getCreativeItems()
      获取creative

      Get the creative

    • addCreativeItem

      public static void addCreativeItem(Item item)
      添加一个物品到creative

      Add a item to creative

    • removeCreativeItem

      public static void removeCreativeItem(Item item)
      移除一个指定的创造物品

      Remove a specified created item

    • isCreativeItem

      public static boolean isCreativeItem(Item item)
      检测这个物品是否存在于创造背包

      Detect if the item exists in the Creative backpack

    • getCreativeItem

      public static Item getCreativeItem(int index)
    • getCreativeItemIndex

      public static int getCreativeItemIndex(Item item)
      获取指定物品在creative中的索引

      Get the index of the specified item in creative

      Parameters:
      item - 指定物品
      specified 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") @NotNull 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()
    • 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)
      通过附魔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.
    • getCustomEnchantmentLevel

      @PowerNukkitXOnly @Since("1.19.60-r1") public int getCustomEnchantmentLevel(String id)
      通过附魔id来查找对应附魔的等级

      Find the enchantment level by the enchantment id.

      Parameters:
      id - 要查询的附魔标识符
      Returns:
      0 if the item don't have that enchantment or the current level of the given enchantment.
    • getCustomEnchantment

      @PowerNukkitXOnly @Since("1.19.60-r1") public Enchantment getCustomEnchantment(String id)
      Parameters:
      id - 要查询的附魔标识符
    • hasCustomEnchantment

      @PowerNukkitXOnly @Since("1.19.60-r1") public boolean hasCustomEnchantment(String id)
      检测该物品是否有该附魔

      Detect if the item has the enchantment

      Parameters:
      id - 要查询的附魔标识符
    • getCustomEnchantmentLevel

      @PowerNukkitXOnly @Since("1.19.80-r3") public int getCustomEnchantmentLevel(@NotNull Identifier id)
      Parameters:
      id - 要查询的附魔标识符
    • hasCustomEnchantment

      @PowerNukkitXOnly @Since("1.19.80-r3") public boolean hasCustomEnchantment(@NotNull Identifier id)
      Parameters:
      id - 要查询的附魔标识符
    • getCustomEnchantment

      @PowerNukkitXOnly @Since("1.19.80-r3") public Enchantment getCustomEnchantment(@NotNull Identifier id)
      Parameters:
      id - 要查询的附魔标识符
    • getEnchantment

      public Enchantment getEnchantment(int id)
      从给定的附魔id查找该物品是否存在对应的附魔效果,如果查找不到返回null

      Get the id of the enchantment

    • getEnchantment

      public Enchantment getEnchantment(short id)
    • addEnchantment

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

      public Enchantment[] getEnchantments()
      获取该物品所带有的全部附魔

      Get all the enchantments that the item comes with

      Returns:
      如果没有附魔效果返回Enchantment.EMPTY_ARRAY
      If there is no enchanting effect return Enchantment.EMPTY_ARRAY
    • hasEnchantment

      @Since("1.4.0.0-PN") public boolean hasEnchantment(int id)
      检测该物品是否有该附魔

      Detect if the item has the enchantment

      Parameters:
      id - The enchantment ID from Enchantment constants.
    • 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)
      设置物品的自定义名字

      Set custom names for items

      Parameters:
      name -
      Returns:
    • clearCustomName

      public Item clearCustomName()
      清除物品的自定义名称

      Clear custom name for item

      Returns:
    • getLore

      public String[] getLore()
      定义物品的Lore信息

      Get the Lore information of the item

      Returns:
    • setLore

      public Item setLore(String... lines)
      设置物品的Lore信息

      Set the Lore information of the item

      Parameters:
      lines - the lines
      Returns:
      the lore
    • 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

      @Nullable public final String getName()
    • getDisplayName

      @PowerNukkitXOnly @Since("1.20.0-r2") @NotNull public final String getDisplayName()
    • canBePlaced

      public final boolean canBePlaced()
    • getBlock

      @NotNull public Block getBlock()
    • getBlockUnsafe

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

      public int getId()
    • getNetworkId

      @PowerNukkitOnly @Since("1.4.0.0-PN") public final int getNetworkId() 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()
      创建一个通配配方物品,即该物品可以不限制数据值应用到配方中

      Create a wildcard recipe item,the item can be applied to a recipe without restriction on data(damage/meta) values

    • getMaxStackSize

      public int getMaxStackSize()
      定义物品堆叠的最大数量

      Define the maximum number of items to be stacked

    • getFuelTime

      public final Short getFuelTime()
      获取一个可燃烧物品的燃烧时间

      Get the burn time of a burnable item

    • useOn

      public boolean useOn(Entity entity)
    • useOn

      public boolean useOn(Block block)
    • isTool

      public boolean isTool()
      定义物品是否为工具

      Define if this item is a tool

    • getMaxDurability

      public int getMaxDurability()
      定义物品最大耐久值

      Define the maximum durability value of the item

    • getTier

      public int getTier()
      定义物品的挖掘等级

      Define the item Tier level

    • isPickaxe

      public boolean isPickaxe()
      定义物品是否为镐子

      Define if the item is a Pickaxe

    • isAxe

      public boolean isAxe()
      定义物品是否为斧子

      Define if the item is a Axe

    • isSword

      public boolean isSword()
      定义物品是否为剑

      Define if the item is a Sword

    • isShovel

      public boolean isShovel()
      定义物品是否为铲子

      Define if the item is a Shovel

    • isHoe

      public boolean isHoe()
      定义物品是否为锄头

      Define if the item is a Hoe

    • isShears

      public boolean isShears()
      定义物品是否为剪刀

      Define if the item is a Shears

    • isArmor

      public boolean isArmor()
      定义物品是否为盔甲

      Define if the item is a Armor

    • isHelmet

      public boolean isHelmet()
      定义物品是否为头盔

      Define if the item is a Helmet

    • isChestplate

      public boolean isChestplate()
      定义物品是否为胸甲

      Define if the item is a Chestplate

    • isLeggings

      public boolean isLeggings()
      定义物品是否为护腿

      Define if the item is a Leggings

    • isBoots

      public boolean isBoots()
      定义物品是否为靴子

      Define if the item is a Boots

    • getEnchantAbility

      public int getEnchantAbility()
      定义物品的附魔

      Define the enchantment of an item

    • getAttackDamage

      public int getAttackDamage()
      定义物品的攻击伤害

      Define the attackdamage of an item

    • getArmorPoints

      public int getArmorPoints()
      定义物品的护甲值

      Define the Armour value of an item

    • getToughness

      public int getToughness()
      定义物品的盔甲韧性

      Define the Armour Toughness of an item

    • isUnbreakable

      public boolean isUnbreakable()
      定义物品是否不可损坏

      Define if the item is Unbreakable

    • 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()
      定义物品是否可以打破盾牌

      Define if the item can break the shield

    • onUse

      public boolean onUse(Player player, int ticksUsed)
      Parameters:
      player - the player
      ticksUsed - 物品被使用了多久(右键持续时间)
      How long the item has been used (right-click duration)
      Returns:
      the boolean
    • 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.
      这个物品被使用多少ticks时间
      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)
      玩家使用一个物品交互时会调用这个方法

      This method is called when the player interacts with an item

      Parameters:
      level - 玩家所在地图
      Player location level
      player - 玩家实例对象
      Player instance object
      block - the block
      target - 交互的目标方块
      Interacting target block
      face - 交互的方向
      Direction of Interaction
      fx - the fx
      fy - the fy
      fz - the fz
      Returns:
      boolean
    • 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()
      如果为true,这个物品可以如骨粉一样减少作物成长时间

      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 - 点击的方向向量
      The direction vector of the click
      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)
      判断两个物品是否相等
      Parameters:
      item - 要比较的物品
      checkDamage - 是否检查数据值
      checkCompound - 是否检查NBT
      Returns:
      the boolean
    • equalsExact

      public final boolean equalsExact(Item other)
      返回物品堆叠是否与指定的物品堆叠有相同的ID,伤害,NBT和数量

      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
    • addCanPlaceOn

      @PowerNukkitXOnly @Since("1.6.0.0-PNX") public void addCanPlaceOn(Block block)
      控制此方块(在冒险模式下)可以使用/放置在其上的方块类型。

      Controls what block types this block may be placed on.

    • 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)
      控制此方块(在冒险模式下)可以破坏的方块类型。此效果不会改变原本的破坏速度和破坏后掉落物。

      Controls what block types can destroy

    • 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()
      获取物品锁定在玩家的物品栏的模式

      Get items locked mode in the player's item inventory

      Returns:
    • setKeepOnDeath

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

      @PowerNukkitXOnly @Since("1.6.0.0-PNX") public boolean keepOnDeath()
      该物品是否死亡不掉落

      Define if the item does not drop on death

      Returns:
    • readItemJsonComponents

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