Skip to content

API reference / @jsprismarine/prismarine / inventory/containerStore

inventory/containerStore ​

Interfaces ​

ContainerViewer ​

Defined in: packages/prismarine/src/inventory/containerStore.ts:116

What a container screen reads of the player who opened it: the content and the dimension a block's slots are read from, and the ender chest, whose slots are the player's own.

Methods ​

getInventory() ​

getInventory(): Pick<HumanInventory, "container">

Defined in: packages/prismarine/src/inventory/containerStore.ts:119

Returns ​

Pick<HumanInventory, "container">

getServer() ​

getServer(): object

Defined in: packages/prismarine/src/inventory/containerStore.ts:117

Returns ​

object

getContent() ​

getContent(): ServerContent | undefined

Returns ​

ServerContent | undefined

getWorld() ​

getWorld(): object

Defined in: packages/prismarine/src/inventory/containerStore.ts:118

Returns ​

object

getDimension() ​

getDimension(): object

Returns ​

object

name ​

readonly name: string

getLevel() ​

getLevel(): object

Returns ​

object

name ​

readonly name: string


OpenContainerSlots ​

Defined in: packages/prismarine/src/inventory/containerStore.ts:47

The slots one open screen owns, read on first use and written back once.

Every member is synchronous, because import('../input/handlers/MoveStacksHandler') and a Java click apply a whole request without awaiting: a refusal has to be able to roll the request back before anything else runs.

Properties ​

size ​

readonly size: number

Defined in: packages/prismarine/src/inventory/containerStore.ts:49

How many slots the screen shows, which is how many the client was sent.

Methods ​

commit() ​

commit(): void

Defined in: packages/prismarine/src/inventory/containerStore.ts:57

Writes what changed back where it came from.

Returns ​

void

get() ​

get(slot): Item | null

Defined in: packages/prismarine/src/inventory/containerStore.ts:51

What is in one slot, or null when it is empty or out of range.

Parameters ​
slot ​

number

Returns ​

Item | null

rollBack() ​

rollBack(): void

Defined in: packages/prismarine/src/inventory/containerStore.ts:55

Throws away everything this request changed, which is what a refusal does.

Returns ​

void

set() ​

set(slot, item): void

Defined in: packages/prismarine/src/inventory/containerStore.ts:53

Puts something in a slot, or empties it.

Parameters ​
slot ​

number

item ​

Item | null

Returns ​

void

Functions ​

containerAnchorOf() ​

containerAnchorOf(player, at, identifier): ContentPosition

Defined in: packages/prismarine/src/inventory/containerStore.ts:233

Which block a screen's slots are filed under, which is not always the block that was clicked.

Either half of a double chest opens the same 54 slots, so a caller comparing two open screens has to compare what they hold rather than where they were opened from. The answer is the half the slots are ordered from, which is the one openContainerSlots reads first.

Parameters ​

player ​

ContainerViewer

at ​

ContentPosition

identifier ​

string

Returns ​

ContentPosition


halvesOf() ​

halvesOf(world, at, identifier): ContentPosition[]

Defined in: packages/prismarine/src/inventory/containerStore.ts:89

The two halves of a double chest, lowest on x and then z first, or the one block on its own.

Parameters ​

world ​

WorldActions

at ​

ContentPosition

identifier ​

string

Returns ​

ContentPosition[]


isPerPlayerContainer() ​

isPerPlayerContainer(identifier): boolean

Defined in: packages/prismarine/src/inventory/containerStore.ts:110

Whether a block's screen draws slots that belong to the player rather than to the block.

The ender chest, and nothing else: two players at one ender chest are looking at two different inventories, so neither one's change is anything the other has to be told about.

Parameters ​

identifier ​

string

Returns ​

boolean


openContainerContents() ​

openContainerContents(player, at, identifier): (Item | null)[]

Defined in: packages/prismarine/src/inventory/containerStore.ts:252

What a block is holding, one stack or null per slot, for the InventoryContent that follows an open.

The same read the request path uses, so the slots a player is shown and the slots they can then move a stack through are the same slots in the same order. A double chest is 54 entries here for the same reason.

Parameters ​

player ​

ContainerViewer

at ​

ContentPosition

identifier ​

string

Returns ​

(Item | null)[]


openContainerSlots() ​

openContainerSlots(player, at, identifier): OpenContainerSlots | undefined

Defined in: packages/prismarine/src/inventory/containerStore.ts:161

The slots the screen a player has open owns, or undefined when it owns none.

Parameters ​

player ​

ContainerViewer

Whose screen it is, which decides an ender chest and names the dimension.

at ​

ContentPosition

The block the screen was opened from.

identifier ​

string

The block standing there, which decides how many slots it has.

Returns ​

OpenContainerSlots | undefined


restorePlacedContents() ​

restorePlacedContents(world, at, identifier, placed): void

Defined in: packages/prismarine/src/inventory/containerStore.ts:210

Puts what a container item was holding into the block it just placed.

A shulker box carries its slots with it, so breaking one and putting it back down has to give the block the same items back. The block's own family cannot do it: onPlace reads the item's declared components, and what the stack is carrying is on the stack rather than on its type. So the family gives the block an empty record and this writes over it.

Does nothing for a stack holding nothing, which is every item but a filled container.

Parameters ​

world ​

WorldActions

at ​

ContentPosition

Where the block went down.

identifier ​

string

The block standing there, which decides how many slots it has.

placed ​

Item

The stack that placed it.

Returns ​

void