接口 PlayerInventory

所有超级接口:
Inventory, Iterable<ItemStack>

public interface PlayerInventory extends Inventory
玩家背包. 包括装备栏,背包和其他额外的格子.
  • 方法详细资料

    • getArmorContents

      ItemStack[] getArmorContents()
      获取装备槽内的全部物品.

      原文: Get all ItemStacks from the armor slots

      返回:
      装备槽的全部物品
    • getExtraContents

      ItemStack[] getExtraContents()
      获取存储在此背包的所有额外物品.

      注意:额外的物品槽是由实现来定义的,但这些额外的物品不会在Inventory.getStorageContents()getArmorContents()之内.

      原文:Get all additional ItemStacks stored in this inventory.
      NB: What defines an extra slot is up to the implementation, however it will not be contained within Inventory.getStorageContents() or getArmorContents()

      返回:
      所有的附加物品
    • getHelmet

      ItemStack getHelmet()
      返回头盔槽内的物品.

      原文: Return the ItemStack from the helmet slot

      返回:
      头盔槽内的物品
    • getChestplate

      ItemStack getChestplate()
      返回胸甲槽内的物品.

      原文: Return the ItemStack from the chestplate slot

      返回:
      胸甲槽内的物品
    • getLeggings

      ItemStack getLeggings()
      返回护腿槽内的物品.

      原文: Return the ItemStack from the leg slot

      返回:
      护腿槽内的物品
    • getBoots

      ItemStack getBoots()
      返回靴子槽内的物品.

      原文: Return the ItemStack from the boots slot

      返回:
      靴子槽内的物品
    • setItem

      void setItem(int index, ItemStack item)
      把物品放在背包的指定位置.

      索引值0~8指向平视显示器(HUD)上的工具栏. 9~35指向主物品栏(中间的27个物品槽), 从主物品栏的左上角往上数(索引值9指向主物品栏左上角的物品槽),向右移动, 到行末时再从下一行的最左的物品槽继续往上数.

      索引值36~39指向玩家的盔甲槽. 即使你可以使用本方法设置盔甲槽内的物品, 我们还是建议你使用我们提供的相关的设置盔甲槽内物品的方法来设置.

      如果你试图传递错误的index值(取值范围为0≤index≤39)给本方法, 将抛出ArrayIndexOutOfBounds异常.

      原文:Stores the ItemStack at the given index of the inventory.

      Indexes 0 through 8 refer to the hotbar. 9 through 35 refer to the main inventory, counting up from 9 at the top left corner of the inventory, moving to the right, and moving to the row below it back on the left side when it reaches the end of the row. It follows the same path in the inventory like you would read a book.

      Indexes 36 through 39 refer to the armor slots. Though you can set armor with this method using these indexes, you are encouraged to use the provided methods for those slots.

      If you attempt to use this method with an index less than 0 or greater than 39, an ArrayIndexOutOfBounds exception will be thrown.

      指定者:
      setItem 在接口中 Inventory
      参数:
      index - 将物品放在哪
      item - 要放置的物品
      抛出:
      ArrayIndexOutOfBoundsException - 当 index 值 < 0 || index > 39
      另请参阅:
    • setArmorContents

      void setArmorContents(ItemStack[] items)
      设置装备槽的全部物品.

      原文: Put the given ItemStacks into the armor slots

      参数:
      items - 用作装备的物品(任意)
    • setExtraContents

      void setExtraContents(ItemStack[] items)
      将给定的物品放在额外物品槽内.

      请到 getExtraContents() 去了解额外物品槽是什么.

      原文:Put the given ItemStacks into the extra slots
      See getExtraContents() for an explanation of extra slots.

      参数:
      items - 额外物品
    • setHelmet

      void setHelmet(ItemStack helmet)
      设置头盔物品栏内的物品. 不检查它是不是一个头盔.

      原文: Put the given ItemStack into the helmet slot. This does not check if the ItemStack is a helmet

      参数:
      helmet - 作为头盔的物品
    • setChestplate

      void setChestplate(ItemStack chestplate)
      设置胸甲物品栏内的物品. 不检查它是不是一个胸甲.

      原文: Put the given ItemStack into the chestplate slot. This does not check if the ItemStack is a chestplate

      参数:
      chestplate - 作为胸甲的物品
    • setLeggings

      void setLeggings(ItemStack leggings)
      设置护腿物品栏内的物品. 不检查它是不是一个护腿.

      原文: Put the given ItemStack into the leg slot. This does not check if the ItemStack is a pair of leggings

      参数:
      leggings - 作为护腿的物品
    • setBoots

      void setBoots(ItemStack boots)
      设置靴子物品栏内的物品. 不检查它是不是一个靴子.

      原文: Put the given ItemStack into the boots slot. This does not check if the ItemStack is a boots

      参数:
      boots - 作为靴子的物品
    • getItemInMainHand

      ItemStack getItemInMainHand()
      获得玩家握在主手的物品(的副本).

      原文:Gets a copy of the item the player is currently holding in their main hand.

      返回:
      握着的物品
    • setItemInMainHand

      void setItemInMainHand(ItemStack item)
      设置玩家握在主手的物品.

      原文:Sets the item the player is holding in their main hand.

      参数:
      item - 要放在玩家手上的物品
    • getItemInOffHand

      ItemStack getItemInOffHand()
      获取玩家握在副手的物品(的副本).

      原文:Gets a copy of the item the player is currently holding in their off hand.

      返回:
      握着的物品
    • setItemInOffHand

      void setItemInOffHand(ItemStack item)
      设置玩家握在副手的物品.

      原文:Sets the item the player is holding in their off hand.

      参数:
      item - 要放在玩家副手上的物品
    • getItemInHand

      @Deprecated ItemStack getItemInHand()
      已过时。
      players can duel wield now use the methods for the specific hand instead
      玩家可以双持了,不再详细介绍.Gets a copy of the item the player is currently holding
      返回:
      the currently held item
      另请参阅:
    • setItemInHand

      @Deprecated void setItemInHand(ItemStack stack)
      已过时。
      players can duel wield now use the methods for the specific hand instead
      玩家可以双持了,不再详细介绍.Sets the item the player is holding
      参数:
      stack - The item to put into the player's hand
      另请参阅:
    • getHeldItemSlot

      int getHeldItemSlot()
      获取玩家握着的物品所在的物品槽位.

      原文:Get the slot number of the currently held item

      返回:
      槽位
    • setHeldItemSlot

      void setHeldItemSlot(int slot)
      设置玩家握着哪一个槽位的物品.

      本方法会验证“slot”的取值是否符合该不等式:0≤slot≤8.

      原文:Set the slot number of the currently held item.

      This validates whether the slot is between 0 and 8 inclusive.

      参数:
      slot - 槽位
      抛出:
      IllegalArgumentException - 如果slot的取值有误
    • clear

      @Deprecated int clear(int id, int data)
      已过时。
      Magic value
      Clears all matching items from the inventory. Setting either value to -1 will skip it's check, while setting both to -1 will clear all items in your inventory unconditionally.
      参数:
      id - the id of the item you want to clear from the inventory
      data - the data of the item you want to clear from the inventory
      返回:
      The number of items cleared
    • getHolder

      HumanEntity getHolder()
      从接口复制的说明: Inventory
      获得此物品栏的持有者(方块或实体).

      原文:Gets the block or entity belonging to the open inventory

      指定者:
      getHolder 在接口中 Inventory
      返回:
      物品栏的持有者;null表示没有归属者