Modifier and Type | Method | Description |
---|---|---|
@NotNull ItemStack[] |
getArmorContents() |
Get all ItemStacks from the armor slots
|
@Nullable ItemStack |
getBoots() |
Return the ItemStack from the boots slot
|
@Nullable ItemStack |
getChestplate() |
Return the ItemStack from the chestplate slot
|
@NotNull ItemStack[] |
getExtraContents() |
Get all additional ItemStacks stored in this inventory.
|
int |
getHeldItemSlot() |
Get the slot number of the currently held item
|
@Nullable ItemStack |
getHelmet() |
Return the ItemStack from the helmet slot
|
@Nullable HumanEntity |
getHolder() |
Gets the block or entity belonging to the open inventory
|
@NotNull ItemStack |
getItem(@NotNull EquipmentSlot slot) |
Gets the ItemStack at the given equipment slot in the inventory.
|
@NotNull ItemStack |
getItemInHand() |
Deprecated.
players can duel wield now use the methods for the
specific hand instead
|
@NotNull ItemStack |
getItemInMainHand() |
Gets a copy of the item the player is currently holding
in their main hand.
|
@NotNull ItemStack |
getItemInOffHand() |
Gets a copy of the item the player is currently holding
in their off hand.
|
@Nullable ItemStack |
getLeggings() |
Return the ItemStack from the leg slot
|
void |
setArmorContents(@Nullable ItemStack[] items) |
Put the given ItemStacks into the armor slots
|
void |
setBoots(@Nullable ItemStack boots) |
Put the given ItemStack into the boots slot.
|
void |
setChestplate(@Nullable ItemStack chestplate) |
Put the given ItemStack into the chestplate slot.
|
void |
setExtraContents(@Nullable ItemStack[] items) |
Put the given ItemStacks into the extra slots
See getExtraContents() for an explanation of extra slots. |
void |
setHeldItemSlot(int slot) |
Set the slot number of the currently held item.
|
void |
setHelmet(@Nullable ItemStack helmet) |
Put the given ItemStack into the helmet slot.
|
void |
setItem(int index,
@Nullable ItemStack item) |
Stores the ItemStack at the given index of the inventory.
|
void |
setItem(@NotNull EquipmentSlot slot,
@Nullable ItemStack item) |
Stores the ItemStack at the given equipment slot in the inventory.
|
void |
setItemInHand(@Nullable ItemStack stack) |
Deprecated.
players can duel wield now use the methods for the
specific hand instead
|
void |
setItemInMainHand(@Nullable ItemStack item) |
Sets the item the player is holding in their main hand.
|
void |
setItemInOffHand(@Nullable ItemStack item) |
Sets the item the player is holding in their off hand.
|
void |
setLeggings(@Nullable ItemStack leggings) |
Put the given ItemStack into the leg slot.
|
addItem, all, all, clear, clear, contains, contains, contains, contains, containsAtLeast, first, first, firstEmpty, getContents, getHolder, getItem, getLocation, getMaxStackSize, getSize, getStorageContents, getType, getViewers, iterator, iterator, remove, remove, removeItem, removeItemAnySlot, setContents, setMaxStackSize, setStorageContents
forEach, spliterator
@NotNull @NotNull ItemStack[] getArmorContents()
@NotNull @NotNull ItemStack[] getExtraContents()
Inventory.getStorageContents()
or
getArmorContents()
@Nullable @Nullable ItemStack getHelmet()
@Nullable @Nullable ItemStack getChestplate()
@Nullable @Nullable ItemStack getLeggings()
@Nullable @Nullable ItemStack getBoots()
void setItem(int index, @Nullable @Nullable ItemStack item)
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.
If you attempt to use this method with an index less than 0 or greater than 40, an ArrayIndexOutOfBounds exception will be thrown.
setItem
in interface Inventory
index
- The index where to put the ItemStackitem
- The ItemStack to setArrayIndexOutOfBoundsException
- when index < 0 || index > 40setBoots(ItemStack)
,
setChestplate(ItemStack)
,
setHelmet(ItemStack)
,
setLeggings(ItemStack)
,
setItemInOffHand(ItemStack)
void setItem(@NotNull @NotNull EquipmentSlot slot, @Nullable @Nullable ItemStack item)
slot
- the slot to put the ItemStackitem
- the ItemStack to setsetItem(int, ItemStack)
@NotNull @NotNull ItemStack getItem(@NotNull @NotNull EquipmentSlot slot)
slot
- the slot to get the ItemStackvoid setArmorContents(@Nullable @Nullable ItemStack[] items)
items
- The ItemStacks to use as armourvoid setExtraContents(@Nullable @Nullable ItemStack[] items)
getExtraContents()
for an explanation of extra slots.items
- The ItemStacks to use as extravoid setHelmet(@Nullable @Nullable ItemStack helmet)
helmet
- The ItemStack to use as helmetvoid setChestplate(@Nullable @Nullable ItemStack chestplate)
chestplate
- The ItemStack to use as chestplatevoid setLeggings(@Nullable @Nullable ItemStack leggings)
leggings
- The ItemStack to use as leggingsvoid setBoots(@Nullable @Nullable ItemStack boots)
boots
- The ItemStack to use as boots@NotNull @NotNull ItemStack getItemInMainHand()
void setItemInMainHand(@Nullable @Nullable ItemStack item)
item
- The item to put into the player's hand@NotNull @NotNull ItemStack getItemInOffHand()
void setItemInOffHand(@Nullable @Nullable ItemStack item)
item
- The item to put into the player's hand@Deprecated @NotNull @NotNull ItemStack getItemInHand()
getItemInMainHand()
,
getItemInOffHand()
@Deprecated void setItemInHand(@Nullable @Nullable ItemStack stack)
stack
- The item to put into the player's handsetItemInMainHand(ItemStack)
,
setItemInOffHand(ItemStack)
int getHeldItemSlot()
void setHeldItemSlot(int slot)
This validates whether the slot is between 0 and 8 inclusive.
slot
- The new slot numberIllegalArgumentException
- Thrown if slot is not between 0 and 8
inclusive@Nullable @Nullable HumanEntity getHolder()
Inventory
Copyright © 2020. All rights reserved.