Skip to content

Inventory ​

interface · pocketmine\inventory\Inventory · source

Constants ​

MAX_STACK ​

php
public const MAX_STACK = 64

Methods ​

addItem() ​

php
public function addItem(\pocketmine\item\Item ...$slots) : array

Stores 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() ​

php
public function all(\pocketmine\item\Item $item) : array

Returns 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() ​

php
public function canAddItem(\pocketmine\item\Item $item) : bool

Checks if a given Item can be added to the inventory

clear() ​

php
public function clear(int $index) : void

Will clear a specific slot

clearAll() ​

php
public function clearAll() : void

Clears all the slots

contains() ​

php
public function contains(\pocketmine\item\Item $item) : bool

Returns 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() ​

php
public function first(\pocketmine\item\Item $item, bool $exact = false) : int

Returns 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() ​

php
public function firstEmpty() : int

Returns the first empty slot, or -1 if not found

getAddableItemQuantity() ​

php
public function getAddableItemQuantity(\pocketmine\item\Item $item) : int

Returns how many items from the given itemstack can be added to this inventory.

getContents() ​

php
public function getContents(bool $includeEmpty = false) : array

Returns an array of all the itemstacks in the inventory, indexed by their slot number. Empty slots are not included unless includeEmpty is true.

getItem() ​

php
public function getItem(int $index) : \pocketmine\item\Item

Returns the item in the specified slot.

getListeners() ​

php
public function getListeners() : \pocketmine\utils\ObjectSet

getMaxStackSize() ​

php
public function getMaxStackSize() : int

Returns 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() ​

php
public function getSize() : int

Returns the number of slots in the inventory.

getViewers() ​

php
public function getViewers() : array

Gets all the Players viewing the inventory Players will view their inventory at all times, even when not open.

isSlotEmpty() ​

php
public function isSlotEmpty(int $index) : bool

Returns whether the given slot is empty.

onClose() ​

php
public function onClose(\pocketmine\player\Player $who) : void

onOpen() ​

php
public function onOpen(\pocketmine\player\Player $who) : void

Called when a player opens this inventory.

remove() ​

php
public function remove(\pocketmine\item\Item $item) : void

Clears 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() ​

php
public function removeItem(\pocketmine\item\Item ...$slots) : array

Removes 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() ​

php
public function setContents(array $items) : void

Sets the contents of the inventory. Non-numeric offsets or offsets larger than the size of the inventory are ignored.

setItem() ​

php
public function setItem(int $index, \pocketmine\item\Item $item) : void

Puts an Item in a slot.

setMaxStackSize() ​

php
public function setMaxStackSize(int $size) : void

Sets the maximum stack size for items in this inventory.

slotExists() ​

php
public function slotExists(int $slot) : bool

Returns whether the specified slot exists in the inventory.

swap() ​

php
public function swap(int $slot1, int $slot2) : void

Swaps the specified slots.

VanillaMine is a fork of PocketMine-MP, maintained by Luxury Nodes. Not affiliated with the PMMP team or Mojang.