Interface PlayerInventory

All Superinterfaces:
Inventory, java.lang.Iterable<ItemStack>

public interface PlayerInventory
extends Inventory
Interface to the inventory of a Player, including the four armor slots.
  • Method Details

    • getArmorContents

      ItemStack[] getArmorContents()
      Get all ItemStacks from the armor slots
      Returns:
      All the ItemStacks from the armor slots
    • getHelmet

      ItemStack getHelmet()
      Return the ItemStack from the helmet slot
      Returns:
      The ItemStack in the helmet slot
    • getChestplate

      ItemStack getChestplate()
      Return the ItemStack from the chestplate slot
      Returns:
      The ItemStack in the chestplate slot
    • getLeggings

      ItemStack getLeggings()
      Return the ItemStack from the leg slot
      Returns:
      The ItemStack in the leg slot
    • getBoots

      ItemStack getBoots()
      Return the ItemStack from the boots slot
      Returns:
      The ItemStack in the boots slot
    • setItem

      void setItem​(int index, ItemStack item)
      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.

      Specified by:
      setItem in interface Inventory
      Parameters:
      index - The index where to put the ItemStack
      item - The ItemStack to set
      Throws:
      java.lang.ArrayIndexOutOfBoundsException - when index < 0 || index > 39
      See Also:
      setBoots(ItemStack), setChestplate(ItemStack), setHelmet(ItemStack), setLeggings(ItemStack)
    • setArmorContents

      void setArmorContents​(ItemStack[] items)
      Put the given ItemStacks into the armor slots
      Parameters:
      items - The ItemStacks to use as armour
    • setHelmet

      void setHelmet​(ItemStack helmet)
      Put the given ItemStack into the helmet slot. This does not check if the ItemStack is a helmet
      Parameters:
      helmet - The ItemStack to use as helmet
    • setChestplate

      void setChestplate​(ItemStack chestplate)
      Put the given ItemStack into the chestplate slot. This does not check if the ItemStack is a chestplate
      Parameters:
      chestplate - The ItemStack to use as 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
      Parameters:
      leggings - The ItemStack to use as leggings
    • setBoots

      void setBoots​(ItemStack boots)
      Put the given ItemStack into the boots slot. This does not check if the ItemStack is a boots
      Parameters:
      boots - The ItemStack to use as boots
    • getItemInHand

      ItemStack getItemInHand()
      Returns the ItemStack currently hold
      Returns:
      The currently held ItemStack
    • setItemInHand

      void setItemInHand​(ItemStack stack)
      Sets the item in hand
      Parameters:
      stack - Stack to set
    • getHeldItemSlot

      int getHeldItemSlot()
      Get the slot number of the currently held item
      Returns:
      Held item slot number
    • setHeldItemSlot

      void setHeldItemSlot​(int slot)
      Set the slot number of the currently held item.

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

      Parameters:
      slot - The new slot number
      Throws:
      java.lang.IllegalArgumentException - Thrown if slot is not between 0 and 8 inclusive
    • clear

      @Deprecated int clear​(int id, int data)
      Deprecated.
      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.
      Parameters:
      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
      Returns:
      The number of items cleared
    • getHolder

      HumanEntity getHolder()
      Description copied from interface: Inventory
      Gets the block or entity belonging to the open inventory
      Specified by:
      getHolder in interface Inventory
      Returns:
      The holder of the inventory; null if it has no holder.