Interface PlayerInventory
-
Method Summary
Modifier and TypeMethodDescriptionGets all ItemStacks from the armor slots.getBoots()Return the ItemStack from the boots slotReturn the ItemStack from the chestplate slotGet all additional ItemStacks stored in this inventory.intGet the slot number of the currently held itemReturn the ItemStack from the helmet slotGets the block or entity belonging to the open inventorygetItem(@NotNull EquipmentSlot slot) Gets the ItemStack at the given equipment slot in the inventory.Deprecated.players can duel wield now use the methods for the specific hand insteadGets the item the player is currently holding in their main hand.Gets the item the player is currently holding in their off hand.Return the ItemStack from the leg slotvoidsetArmorContents(@Nullable ItemStack @NotNull [] items) Put the given ItemStacks into the armor slotsvoidPut the given ItemStack into the boots slot.voidsetChestplate(@Nullable ItemStack chestplate) Put the given ItemStack into the chestplate slot.voidsetExtraContents(@Nullable ItemStack @NotNull [] items) Put the given ItemStacks into the extra slots
SeegetExtraContents()for an explanation of extra slots.voidsetHeldItemSlot(int slot) Set the slot number of the currently held item.voidPut the given ItemStack into the helmet slot.voidStores the ItemStack at the given index of the inventory.voidsetItem(@NotNull EquipmentSlot slot, @Nullable ItemStack item) Stores the ItemStack at the given equipment slot in the inventory.voidsetItemInHand(@Nullable ItemStack stack) Deprecated.players can duel wield now use the methods for the specific hand insteadvoidSets the item the player is holding in their main hand.voidSets the item the player is holding in their off hand.voidsetLeggings(@Nullable ItemStack leggings) Put the given ItemStack into the leg slot.Methods inherited from interface Inventory
addItem, all, all, clear, clear, close, contains, contains, contains, contains, containsAtLeast, first, first, firstEmpty, getContents, getHolder, getItem, getLocation, getMaxStackSize, getSize, getStorageContents, getType, getViewers, isEmpty, iterator, iterator, remove, remove, removeItem, removeItemAnySlot, setContents, setMaxStackSize, setStorageContentsMethods inherited from interface Iterable
forEach, spliterator
-
Method Details
-
getArmorContents
-
getExtraContents
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 withinInventory.getStorageContents()orgetArmorContents()- Returns:
- All additional ItemStacks. Individual items can be null.
-
getHelmet
-
getChestplate
-
getLeggings
-
getBoots
-
setItem
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.
Index 40 refers to the off hand (shield) item slot. Though you can set off hand with this method using this index, you are encouraged to use the provided method for this slot.
Index 41 refers to the body item slot and 42 is the saddle item slot. Note that these are not visible in the player inventory menu.
If you attempt to use this method with an index less than 0 or greater than 42, an ArrayIndexOutOfBounds exception will be thrown.
- Specified by:
setItemin interfaceInventory- Parameters:
index- The index where to put the ItemStackitem- The ItemStack to set- Throws:
ArrayIndexOutOfBoundsException- when index < 0 || index > 42- See Also:
-
setItem
Stores the ItemStack at the given equipment slot in the inventory.- Parameters:
slot- the slot to put the ItemStackitem- the ItemStack to set- Throws:
IllegalArgumentException- if the slot is invalid for the player- See Also:
-
getItem
Gets the ItemStack at the given equipment slot in the inventory.- Parameters:
slot- the slot to get the ItemStack- Returns:
- the ItemStack in the given slot
- Throws:
IllegalArgumentException- if the slot is invalid for the player- See Also:
-
setArmorContents
-
setExtraContents
Put the given ItemStacks into the extra slots
SeegetExtraContents()for an explanation of extra slots.- Parameters:
items- The ItemStacks to use as extra
-
setHelmet
-
setChestplate
-
setLeggings
-
setBoots
-
getItemInMainHand
-
setItemInMainHand
-
getItemInOffHand
-
setItemInOffHand
-
getItemInHand
Deprecated.players can duel wield now use the methods for the specific hand insteadGets the item the player is currently holding- Returns:
- the currently held item
- See Also:
-
setItemInHand
Deprecated.players can duel wield now use the methods for the specific hand insteadSets the item the player is holding- Parameters:
stack- The item to put into the player's hand- See Also:
-
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:
IllegalArgumentException- Thrown if slot is not between 0 and 8 inclusive
-
getHolder
-