Inventory
Constants
MAX_STACK
public const MAX_STACK = 64Methods
addItem()
public function addItem(\pocketmine\item\Item ...$slots) : arrayStores the given Items in the inventory. This will add to any non-full existing stacks first, and then put the remaining items in empty slots if there are any available.
Returns an array of items which could not fit in the inventory.
all()
public function all(\pocketmine\item\Item $item) : arrayReturns all matching items in the inventory, irrespective of stack size. The returned array is indexed by slot number.
If the input item has specific NBT, only items with the same type and NBT will match. Otherwise, only the item type is checked.
canAddItem()
public function canAddItem(\pocketmine\item\Item $item) : boolChecks if a given Item can be added to the inventory
clear()
public function clear(int $index) : voidWill clear a specific slot
clearAll()
public function clearAll() : voidClears all the slots
contains()
public function contains(\pocketmine\item\Item $item) : boolReturns whether the total amount of matching items is at least the stack size of the given item. Multiple stacks of the same item are added together.
If the input item has specific NBT, only items with the same type and NBT will match. Otherwise, only the item type is checked.
first()
public function first(\pocketmine\item\Item $item, bool $exact = false) : intReturns the first slot number containing a matching item with a stack size greater than or equal to the input item.
If the input item has specific NBT, or if $exact is true, only items with the same type and NBT will match. Otherwise, only the item type is checked.
firstEmpty()
public function firstEmpty() : intReturns the first empty slot, or -1 if not found
getAddableItemQuantity()
public function getAddableItemQuantity(\pocketmine\item\Item $item) : intReturns how many items from the given itemstack can be added to this inventory.
getContents()
public function getContents(bool $includeEmpty = false) : arrayReturns an array of all the itemstacks in the inventory, indexed by their slot number. Empty slots are not included unless includeEmpty is true.
getItem()
public function getItem(int $index) : \pocketmine\item\ItemReturns the item in the specified slot.
getListeners()
public function getListeners() : \pocketmine\utils\ObjectSetgetMaxStackSize()
public function getMaxStackSize() : intReturns the maximum stack size for items in this inventory. Individual item types (such as armor or tools) may have a smaller maximum stack size.
getSize()
public function getSize() : intReturns the number of slots in the inventory.
getViewers()
public function getViewers() : arrayGets all the Players viewing the inventory Players will view their inventory at all times, even when not open.
isSlotEmpty()
public function isSlotEmpty(int $index) : boolReturns whether the given slot is empty.
onClose()
public function onClose(\pocketmine\player\Player $who) : voidonOpen()
public function onOpen(\pocketmine\player\Player $who) : voidCalled when a player opens this inventory.
remove()
public function remove(\pocketmine\item\Item $item) : voidClears all slots containing items equivalent to the given item.
If the input item has specific NBT, only items with the same type and NBT will match. Otherwise, only the item type is checked.
removeItem()
public function removeItem(\pocketmine\item\Item ...$slots) : arrayRemoves items from the inventory in the amounts specified by the given itemstacks. Returns an array of items that couldn't be removed.
If the input item has specific NBT, only items with the same type and NBT will match. Otherwise, only the item type is checked.
setContents()
public function setContents(array $items) : voidSets the contents of the inventory. Non-numeric offsets or offsets larger than the size of the inventory are ignored.
setItem()
public function setItem(int $index, \pocketmine\item\Item $item) : voidPuts an Item in a slot.
setMaxStackSize()
public function setMaxStackSize(int $size) : voidSets the maximum stack size for items in this inventory.
slotExists()
public function slotExists(int $slot) : boolReturns whether the specified slot exists in the inventory.
swap()
public function swap(int $slot1, int $slot2) : voidSwaps the specified slots.
