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

# inventory/persistence

## Interfaces

### StoredInventory

Defined in: [packages/prismarine/src/inventory/persistence.ts:147](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/inventory/persistence.ts#L147)

Every container a player carries, by the slot numbering each one uses.

#### Properties

##### armor

> `readonly` **armor**: readonly ([`StoredItemStack`](#storeditemstack) \| `null`)[]

Defined in: [packages/prismarine/src/inventory/persistence.ts:153](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/inventory/persistence.ts#L153)

Helmet, chestplate, leggings, boots.

##### enderChest

> `readonly` **enderChest**: readonly ([`StoredItemStack`](#storeditemstack) \| `null`)[]

Defined in: [packages/prismarine/src/inventory/persistence.ts:157](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/inventory/persistence.ts#L157)

The player's own 27 ender chest slots.

##### handSlot

> `readonly` **handSlot**: `number`

Defined in: [packages/prismarine/src/inventory/persistence.ts:151](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/inventory/persistence.ts#L151)

Which hotbar slot the hand points at.

##### items

> `readonly` **items**: readonly ([`StoredItemStack`](#storeditemstack) \| `null`)[]

Defined in: [packages/prismarine/src/inventory/persistence.ts:149](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/inventory/persistence.ts#L149)

The 36 main slots; the first nine are the hotbar.

##### offhand

> `readonly` **offhand**: readonly ([`StoredItemStack`](#storeditemstack) \| `null`)[]

Defined in: [packages/prismarine/src/inventory/persistence.ts:155](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/inventory/persistence.ts#L155)

One slot.

***

### StoredItemStack

Defined in: [packages/prismarine/src/inventory/persistence.ts:30](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/inventory/persistence.ts#L30)

One stack as a player data record holds it.

#### Properties

##### canDestroy?

> `readonly` `optional` **canDestroy?**: readonly `string`[]

Defined in: [packages/prismarine/src/inventory/persistence.ts:59](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/inventory/persistence.ts#L59)

The Bedrock block identifiers the stack may destroy, which adventure mode reads.

##### canPlaceOn?

> `readonly` `optional` **canPlaceOn?**: readonly `string`[]

Defined in: [packages/prismarine/src/inventory/persistence.ts:57](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/inventory/persistence.ts#L57)

The Bedrock block identifiers the stack may be placed on, which adventure mode reads.

##### components?

> `readonly` `optional` **components?**: `Readonly`\<`Record`\<`string`, `unknown`\>\>

Defined in: [packages/prismarine/src/inventory/persistence.ts:72](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/inventory/persistence.ts#L72)

The stack's other Java components in Java's JSON form, such as `minecraft:trim` or
`minecraft:firework_explosion`; see `Item.getComponents`.

##### contents?

> `readonly` `optional` **contents?**: readonly ([`StoredItemStack`](#storeditemstack) \| `null`)[]

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

What a container item holds, one entry per slot, which is a shulker box's inventory.

Null for an empty slot rather than undefined, for the reason the module comment gives:
`JSON.stringify` turns an undefined array element into null, so the two forms would not
match across the fallback path.

##### count

> `readonly` **count**: `number`

Defined in: [packages/prismarine/src/inventory/persistence.ts:33](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/inventory/persistence.ts#L33)

##### customName?

> `readonly` `optional` **customName?**: `string`

Defined in: [packages/prismarine/src/inventory/persistence.ts:44](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/inventory/persistence.ts#L44)

##### damage?

> `readonly` `optional` **damage?**: `number`

Defined in: [packages/prismarine/src/inventory/persistence.ts:43](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/inventory/persistence.ts#L43)

Durability spent, which is Java's `minecraft:damage` and Bedrock's `tag.Damage`.

Spent rather than remaining, so a stack of an item whose maximum durability changed
between versions comes back as damaged by the same amount instead of as a different
fraction of a different total.

##### dynamicProperties?

> `readonly` `optional` **dynamicProperties?**: `Readonly`\<`Record`\<`string`, `Readonly`\<`Record`\<`string`, [`ItemDynamicPropertyValue`](https://jsprismarine.dev/api/@jsprismarine/block-behaviors/index.md#itemdynamicpropertyvalue)\>\>\>\>

Defined in: [packages/prismarine/src/inventory/persistence.ts:65](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/inventory/persistence.ts#L65)

The script dynamic properties set on the stack, by pack UUID and then by property id.

##### enchantments?

> `readonly` `optional` **enchantments?**: `Readonly`\<`Record`\<`string`, `number`\>\>

Defined in: [packages/prismarine/src/inventory/persistence.ts:47](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/inventory/persistence.ts#L47)

Namespaced Java enchantment id to level, which is `minecraft:enchantments`.

##### keepOnDeath?

> `readonly` `optional` **keepOnDeath?**: `boolean`

Defined in: [packages/prismarine/src/inventory/persistence.ts:61](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/inventory/persistence.ts#L61)

Whether the stack stays with its owner when they die.

##### lockMode?

> `readonly` `optional` **lockMode?**: `"slot"` \| `"inventory"`

Defined in: [packages/prismarine/src/inventory/persistence.ts:63](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/inventory/persistence.ts#L63)

Where the stack is locked: in its slot or in the inventory.

##### lore?

> `readonly` `optional` **lore?**: readonly `string`[]

Defined in: [packages/prismarine/src/inventory/persistence.ts:45](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/inventory/persistence.ts#L45)

##### mapId?

> `readonly` `optional` **mapId?**: `number`

Defined in: [packages/prismarine/src/inventory/persistence.ts:67](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/inventory/persistence.ts#L67)

Which saved map a filled map shows, Java's `minecraft:map_id`.

##### meta?

> `readonly` `optional` **meta?**: `number`

Defined in: [packages/prismarine/src/inventory/persistence.ts:35](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/inventory/persistence.ts#L35)

The aux value, which is Bedrock's top-level `Damage`.

##### name

> `readonly` **name**: `string`

Defined in: [packages/prismarine/src/inventory/persistence.ts:32](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/inventory/persistence.ts#L32)

The item identifier, namespaced.

## Functions

### dropOfItem()

> **dropOfItem**(`item`): [`ItemDrop`](https://jsprismarine.dev/api/@jsprismarine/block-behaviors/index.md#itemdrop) \| `undefined`

Defined in: [packages/prismarine/src/inventory/persistence.ts:236](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/inventory/persistence.ts#L236)

An item stack as a block behavior's drop, which is [itemOfDrop](#itemofdrop) backwards.

#### Parameters

##### item

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

#### Returns

[`ItemDrop`](https://jsprismarine.dev/api/@jsprismarine/block-behaviors/index.md#itemdrop) \| `undefined`

The drop, or undefined for an empty slot, air or an empty stack.

***

### isStoredItemStack()

> **isStoredItemStack**(`value`): `value is StoredItemStack`

Defined in: [packages/prismarine/src/inventory/persistence.ts:88](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/inventory/persistence.ts#L88)

Whether an unknown value, such as JSON read from actor NBT, has the shape of a stored stack.

#### Parameters

##### value

`unknown`

#### Returns

`value is StoredItemStack`

***

### itemDropOf()

> **itemDropOf**(`stored`): [`ItemDrop`](https://jsprismarine.dev/api/@jsprismarine/block-behaviors/index.md#itemdrop)

Defined in: [packages/prismarine/src/inventory/persistence.ts:125](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/inventory/persistence.ts#L125)

The same stack as a block behavior carries one.

[ItemDrop](https://jsprismarine.dev/api/@jsprismarine/block-behaviors/index.md#itemdrop) and [StoredItemStack](#storeditemstack) describe the same thing and differ in one
name: a drop calls the item `identifier` and a stored stack calls it `name`. Neither can
be renamed - the drop's spelling is `@jsprismarine/block-behaviors`' published interface,
and the stored one's is in every player file already written - so the rename happens here,
once, for both directions.

#### Parameters

##### stored

[`StoredItemStack`](#storeditemstack)

#### Returns

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

***

### itemOfDrop()

> **itemOfDrop**(`drop`, `content?`): [`Item`](https://jsprismarine.dev/api/@jsprismarine/prismarine/item/Item/classes/Item.md) \| `null`

Defined in: [packages/prismarine/src/inventory/persistence.ts:229](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/inventory/persistence.ts#L229)

A block behavior's drop as the item stack it names, or null when the drop is empty.

#### Parameters

##### drop

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

##### content?

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

The content build, which decides the item's maximum durability.

#### Returns

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

***

### restoreInventory()

> **restoreInventory**(`inventory`, `stored`, `content?`): `void`

Defined in: [packages/prismarine/src/inventory/persistence.ts:271](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/inventory/persistence.ts#L271)

Puts a stored record back into a player's containers.

#### Parameters

##### inventory

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

##### stored

[`StoredInventory`](#storedinventory) \| `undefined`

##### content?

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

#### Returns

`void`

***

### restoredItem()

> **restoredItem**(`stored`, `content?`): [`Item`](https://jsprismarine.dev/api/@jsprismarine/prismarine/item/Item/classes/Item.md) \| `null`

Defined in: [packages/prismarine/src/inventory/persistence.ts:197](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/inventory/persistence.ts#L197)

One stored stack back as an item, or null when the record held nothing.

#### Parameters

##### stored

[`StoredItemStack`](#storeditemstack) \| `null` \| `undefined`

##### content?

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

The content build, so a pack that redefines an item decides its maximum
  durability rather than Java's committed table doing it.

#### Returns

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

***

### storedInventory()

> **storedInventory**(`inventory`): [`StoredInventory`](#storedinventory)

Defined in: [packages/prismarine/src/inventory/persistence.ts:262](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/inventory/persistence.ts#L262)

Everything a player carries, ready to be written to a player data record.

#### Parameters

##### inventory

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

#### Returns

[`StoredInventory`](#storedinventory)

***

### storedItem()

> **storedItem**(`item`): [`StoredItemStack`](#storeditemstack) \| `null`

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

One stack as a record holds it, or null for air or an empty stack, which a record never holds.

#### Parameters

##### item

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

#### Returns

[`StoredItemStack`](#storeditemstack) \| `null`

***

### storedItemDrop()

> **storedItemDrop**(`drop`): [`StoredItemStack`](#storeditemstack)

Defined in: [packages/prismarine/src/inventory/persistence.ts:137](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/inventory/persistence.ts#L137)

The same drop as a player data record stores one, which is [itemDropOf](#itemdropof) backwards.

#### Parameters

##### drop

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

#### Returns

[`StoredItemStack`](#storeditemstack)
