AnvilInventory
extends SimpleInventory
in package
implements
BlockInventory, TemporaryInventory
Uses
BlockInventoryTrait
This class provides a complete implementation of a regular inventory.
Interfaces, Classes, Traits and Enums
Table of Contents
- SLOT_INPUT = 0
- SLOT_MATERIAL = 1
- $holder : Position
- $listeners : array<string|int, InventoryListener>|ObjectSet
- $maxStackSize : int
- $slots : SplFixedArray
- $viewers : array<string|int, Player>
- __construct() : mixed
- addItem() : array<string|int, Item>
- Stores the given Items in the inventory. This will try to fill existing stacks and empty slots as well as it can.
- all() : array<string|int, Item>
- Will return all the Items that has the same id and metadata (if not null).
- canAddItem() : bool
- Checks if a given Item can be added to the inventory
- clear() : void
- Will clear a specific slot
- clearAll() : void
- Clears all the slots
- contains() : bool
- Checks if the inventory contains any Item with the same material data.
- first() : int
- Returns the first slot number containing an item with the same ID, damage (if not any-damage), NBT (if not empty) and count >= to the count of the specified item stack.
- firstEmpty() : int
- Returns the first empty slot, or -1 if not found
- getAddableItemQuantity() : int
- Returns how many items from the given itemstack can be added to this inventory.
- getContents() : array<string|int, Item>
- getHolder() : Position
- getItem() : Item
- getListeners() : array<string|int, InventoryListener>|ObjectSet
- getMaxStackSize() : int
- getSize() : int
- Returns the size of the inventory.
- getViewers() : array<string|int, Player>
- Gets all the Players viewing the inventory Players will view their inventory at all times, even when not open.
- isSlotEmpty() : bool
- Returns whether the given slot is empty.
- onClose() : void
- onOpen() : void
- Called when a player opens this inventory.
- remove() : void
- Will remove all the Items that has the same id and metadata (if not null)
- removeAllViewers() : void
- Removes the inventory window from all players currently viewing it.
- removeItem() : array<string|int, Item>
- Removes the given Item from the inventory.
- setContents() : void
- setItem() : void
- Puts an Item in a slot.
- setMaxStackSize() : void
- slotExists() : bool
- Returns whether the specified slot exists in the inventory.
- swap() : void
- Swaps the specified slots.
- internalSetContents() : void
- internalSetItem() : void
- onContentChange() : void
- onSlotChange() : void
- internalAddItem() : Item
Constants
SLOT_INPUT
public
mixed
SLOT_INPUT
= 0
SLOT_MATERIAL
public
mixed
SLOT_MATERIAL
= 1
Properties
$holder
protected
Position
$holder
$listeners
protected
array<string|int, InventoryListener>|ObjectSet
$listeners
Tags
$maxStackSize
protected
int
$maxStackSize
= \pocketmine\inventory\Inventory::MAX_STACK
$slots
protected
SplFixedArray
$slots
Tags
$viewers
protected
array<string|int, Player>
$viewers
= []
Methods
__construct()
public
__construct(Position $holder) : mixed
Parameters
- $holder : Position
Return values
mixed —addItem()
Stores the given Items in the inventory. This will try to fill existing stacks and empty slots as well as it can.
public
addItem(Item ...$slots) : array<string|int, Item>
Returns the Items that did not fit.
Parameters
- $slots : Item
Return values
array<string|int, Item> —all()
Will return all the Items that has the same id and metadata (if not null).
public
all(Item $item) : array<string|int, Item>
Won't check amount
Parameters
- $item : Item
Return values
array<string|int, Item> —canAddItem()
Checks if a given Item can be added to the inventory
public
canAddItem(Item $item) : bool
Parameters
- $item : Item
Return values
bool —clear()
Will clear a specific slot
public
clear(int $index) : void
Parameters
- $index : int
Return values
void —clearAll()
Clears all the slots
public
clearAll() : void
Return values
void —contains()
Checks if the inventory contains any Item with the same material data.
public
contains(Item $item) : bool
It will check id, amount, and metadata (if not null)
Parameters
- $item : Item
Return values
bool —first()
Returns the first slot number containing an item with the same ID, damage (if not any-damage), NBT (if not empty) and count >= to the count of the specified item stack.
public
first(Item $item[, bool $exact = false ]) : int
If $exact is true, only items with equal ID, damage, NBT and count will match.
Parameters
- $item : Item
- $exact : bool = false
Return values
int —firstEmpty()
Returns the first empty slot, or -1 if not found
public
firstEmpty() : int
Return values
int —getAddableItemQuantity()
Returns how many items from the given itemstack can be added to this inventory.
public
getAddableItemQuantity(Item $item) : int
Parameters
- $item : Item
Return values
int —getContents()
public
getContents([bool $includeEmpty = false ]) : array<string|int, Item>
Parameters
- $includeEmpty : bool = false
Return values
array<string|int, Item> —getHolder()
public
getHolder() : Position
Return values
Position —getItem()
public
getItem(int $index) : Item
Parameters
- $index : int
Return values
Item —getListeners()
public
getListeners() : array<string|int, InventoryListener>|ObjectSet
Return values
array<string|int, InventoryListener>|ObjectSet —getMaxStackSize()
public
getMaxStackSize() : int
Return values
int —getSize()
Returns the size of the inventory.
public
getSize() : int
Return values
int —getViewers()
Gets all the Players viewing the inventory Players will view their inventory at all times, even when not open.
public
getViewers() : array<string|int, Player>
Return values
array<string|int, Player> —isSlotEmpty()
Returns whether the given slot is empty.
public
isSlotEmpty(int $index) : bool
Parameters
- $index : int
Return values
bool —onClose()
public
onClose(Player $who) : void
Parameters
- $who : Player
Return values
void —onOpen()
Called when a player opens this inventory.
public
onOpen(Player $who) : void
Parameters
- $who : Player
Return values
void —remove()
Will remove all the Items that has the same id and metadata (if not null)
public
remove(Item $item) : void
Parameters
- $item : Item
Return values
void —removeAllViewers()
Removes the inventory window from all players currently viewing it.
public
removeAllViewers() : void
Return values
void —removeItem()
Removes the given Item from the inventory.
public
removeItem(Item ...$slots) : array<string|int, Item>
It will return the Items that couldn't be removed.
Parameters
- $slots : Item
Return values
array<string|int, Item> —setContents()
public
setContents(array<string|int, Item> $items) : void
Parameters
- $items : array<string|int, Item>
Return values
void —setItem()
Puts an Item in a slot.
public
setItem(int $index, Item $item) : void
Parameters
- $index : int
- $item : Item
Return values
void —setMaxStackSize()
public
setMaxStackSize(int $size) : void
Parameters
- $size : int
Return values
void —slotExists()
Returns whether the specified slot exists in the inventory.
public
slotExists(int $slot) : bool
Parameters
- $slot : int
Return values
bool —swap()
Swaps the specified slots.
public
swap(int $slot1, int $slot2) : void
Parameters
- $slot1 : int
- $slot2 : int
Return values
void —internalSetContents()
protected
abstract internalSetContents(array<string|int, Item> $items) : void
Parameters
- $items : array<string|int, Item>
Return values
void —internalSetItem()
protected
abstract internalSetItem(int $index, Item $item) : void
Parameters
- $index : int
- $item : Item
Return values
void —onContentChange()
protected
onContentChange(array<string|int, Item> $itemsBefore) : void
Parameters
- $itemsBefore : array<string|int, Item>
Tags
Return values
void —onSlotChange()
protected
onSlotChange(int $index, Item $before) : void
Parameters
- $index : int
- $before : Item
Return values
void —internalAddItem()
private
internalAddItem(Item $slot) : Item
Parameters
- $slot : Item