Documentation

PlayerCraftingInventory extends CraftingGrid
in package
implements TemporaryInventory

This class provides a complete implementation of a regular inventory.

Interfaces, Classes, Traits and Enums

TemporaryInventory

Table of Contents

SIZE_BIG  = 3
SIZE_SMALL  = 2
$listeners  : array<string|int, InventoryListener>|ObjectSet
$maxStackSize  : int
$slots  : SplFixedArray
$viewers  : array<string|int, Player>
$gridWidth  : int
$holder  : Player
$startX  : int|null
$startY  : int|null
$xLen  : int|null
$yLen  : int|null
__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>
getGridWidth()  : int
getHolder()  : Player
getIngredient()  : Item
Returns the item at offset x,y, offset by where the starts of the recipe rectangle are.
getItem()  : Item
getListeners()  : array<string|int, InventoryListener>|ObjectSet
getMaxStackSize()  : int
getRecipeHeight()  : int
Returns the height of the recipe we're trying to craft, based on items currently in the grid.
getRecipeWidth()  : int
Returns the width of the recipe we're trying to craft, based on items currently in the grid.
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
seekRecipeBounds()  : void

Constants

Properties

$maxStackSize

protected int $maxStackSize = \pocketmine\inventory\Inventory::MAX_STACK

$slots

protected SplFixedArray $slots
Tags
phpstan-var

\SplFixedArray<Item|null>

Methods

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>

getGridWidth()

public getGridWidth() : int
Return values
int

getIngredient()

Returns the item at offset x,y, offset by where the starts of the recipe rectangle are.

public getIngredient(int $x, int $y) : Item
Parameters
$x : int
$y : int
Return values
Item

getMaxStackSize()

public getMaxStackSize() : int
Return values
int

getRecipeHeight()

Returns the height of the recipe we're trying to craft, based on items currently in the grid.

public getRecipeHeight() : int
Return values
int

getRecipeWidth()

Returns the width of the recipe we're trying to craft, based on items currently in the grid.

public getRecipeWidth() : 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

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
phpstan-param

array<int, Item> $itemsBefore

Return values
void

onSlotChange()

protected onSlotChange(int $index, Item $before) : void
Parameters
$index : int
$before : Item
Return values
void

seekRecipeBounds()

private seekRecipeBounds() : void
Return values
void

Search results