[API reference](https://jsprismarine.dev/api/index.md) / [@jsprismarine/prismarine](https://jsprismarine.dev/api/@jsprismarine/prismarine/index.md) / inventory/containerStore

# inventory/containerStore

## Interfaces

### ContainerViewer

Defined in: [packages/prismarine/src/inventory/containerStore.ts:116](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/inventory/containerStore.ts#L116)

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`](https://jsprismarine.dev/api/@jsprismarine/prismarine/inventory/HumanInventory/classes/HumanInventory.md), `"container"`\>

Defined in: [packages/prismarine/src/inventory/containerStore.ts:119](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/inventory/containerStore.ts#L119)

###### Returns

`Pick`\<[`HumanInventory`](https://jsprismarine.dev/api/@jsprismarine/prismarine/inventory/HumanInventory/classes/HumanInventory.md), `"container"`\>

##### getServer()

> **getServer**(): `object`

Defined in: [packages/prismarine/src/inventory/containerStore.ts:117](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/inventory/containerStore.ts#L117)

###### Returns

`object`

###### getContent()

> **getContent**(): [`ServerContent`](https://jsprismarine.dev/api/@jsprismarine/prismarine/content/ServerContent/index.md#servercontent) \| `undefined`

###### Returns

[`ServerContent`](https://jsprismarine.dev/api/@jsprismarine/prismarine/content/ServerContent/index.md#servercontent) \| `undefined`

##### getWorld()

> **getWorld**(): `object`

Defined in: [packages/prismarine/src/inventory/containerStore.ts:118](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/inventory/containerStore.ts#L118)

###### 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](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/inventory/containerStore.ts#L47)

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](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/inventory/containerStore.ts#L49)

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](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/inventory/containerStore.ts#L57)

Writes what changed back where it came from.

###### Returns

`void`

##### get()

> **get**(`slot`): [`Item`](https://jsprismarine.dev/api/@jsprismarine/prismarine/item/Item/classes/Item.md) \| `null`

Defined in: [packages/prismarine/src/inventory/containerStore.ts:51](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/inventory/containerStore.ts#L51)

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

###### Parameters

###### slot

`number`

###### Returns

[`Item`](https://jsprismarine.dev/api/@jsprismarine/prismarine/item/Item/classes/Item.md) \| `null`

##### rollBack()

> **rollBack**(): `void`

Defined in: [packages/prismarine/src/inventory/containerStore.ts:55](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/inventory/containerStore.ts#L55)

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](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/inventory/containerStore.ts#L53)

Puts something in a slot, or empties it.

###### Parameters

###### slot

`number`

###### item

[`Item`](https://jsprismarine.dev/api/@jsprismarine/prismarine/item/Item/classes/Item.md) \| `null`

###### Returns

`void`

## Functions

### containerAnchorOf()

> **containerAnchorOf**(`player`, `at`, `identifier`): [`ContentPosition`](https://jsprismarine.dev/api/@jsprismarine/prismarine/content/world/adapter/index.md#contentposition)

Defined in: [packages/prismarine/src/inventory/containerStore.ts:233](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/inventory/containerStore.ts#L233)

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](#opencontainerslots-1) reads first.

#### Parameters

##### player

[`ContainerViewer`](#containerviewer)

##### at

[`ContentPosition`](https://jsprismarine.dev/api/@jsprismarine/prismarine/content/world/adapter/index.md#contentposition)

##### identifier

`string`

#### Returns

[`ContentPosition`](https://jsprismarine.dev/api/@jsprismarine/prismarine/content/world/adapter/index.md#contentposition)

***

### halvesOf()

> **halvesOf**(`world`, `at`, `identifier`): [`ContentPosition`](https://jsprismarine.dev/api/@jsprismarine/prismarine/content/world/adapter/index.md#contentposition)[]

Defined in: [packages/prismarine/src/inventory/containerStore.ts:89](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/inventory/containerStore.ts#L89)

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

#### Parameters

##### world

[`WorldActions`](https://jsprismarine.dev/api/@jsprismarine/block-behaviors/index.md#worldactions)

##### at

[`ContentPosition`](https://jsprismarine.dev/api/@jsprismarine/prismarine/content/world/adapter/index.md#contentposition)

##### identifier

`string`

#### Returns

[`ContentPosition`](https://jsprismarine.dev/api/@jsprismarine/prismarine/content/world/adapter/index.md#contentposition)[]

***

### isPerPlayerContainer()

> **isPerPlayerContainer**(`identifier`): `boolean`

Defined in: [packages/prismarine/src/inventory/containerStore.ts:110](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/inventory/containerStore.ts#L110)

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`](https://jsprismarine.dev/api/@jsprismarine/prismarine/item/Item/classes/Item.md) \| `null`)[]

Defined in: [packages/prismarine/src/inventory/containerStore.ts:252](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/inventory/containerStore.ts#L252)

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`](#containerviewer)

##### at

[`ContentPosition`](https://jsprismarine.dev/api/@jsprismarine/prismarine/content/world/adapter/index.md#contentposition)

##### identifier

`string`

#### Returns

([`Item`](https://jsprismarine.dev/api/@jsprismarine/prismarine/item/Item/classes/Item.md) \| `null`)[]

***

### openContainerSlots()

> **openContainerSlots**(`player`, `at`, `identifier`): [`OpenContainerSlots`](#opencontainerslots) \| `undefined`

Defined in: [packages/prismarine/src/inventory/containerStore.ts:161](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/inventory/containerStore.ts#L161)

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

#### Parameters

##### player

[`ContainerViewer`](#containerviewer)

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

##### at

[`ContentPosition`](https://jsprismarine.dev/api/@jsprismarine/prismarine/content/world/adapter/index.md#contentposition)

The block the screen was opened from.

##### identifier

`string`

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

#### Returns

[`OpenContainerSlots`](#opencontainerslots) \| `undefined`

***

### restorePlacedContents()

> **restorePlacedContents**(`world`, `at`, `identifier`, `placed`): `void`

Defined in: [packages/prismarine/src/inventory/containerStore.ts:210](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/inventory/containerStore.ts#L210)

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`](https://jsprismarine.dev/api/@jsprismarine/block-behaviors/index.md#worldactions)

##### at

[`ContentPosition`](https://jsprismarine.dev/api/@jsprismarine/prismarine/content/world/adapter/index.md#contentposition)

Where the block went down.

##### identifier

`string`

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

##### placed

[`Item`](https://jsprismarine.dev/api/@jsprismarine/prismarine/item/Item/classes/Item.md)

The stack that placed it.

#### Returns

`void`
