[API reference](https://jsprismarine.dev/api/index.md) / [@jsprismarine/prismarine](https://jsprismarine.dev/api/@jsprismarine/prismarine/index.md) / world/providers/SavePass

# world/providers/SavePass

## Interfaces

### LevelRecords

Defined in: [packages/prismarine/src/world/providers/SavePass.ts:16](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/providers/SavePass.ts#L16)

The level-wide records a save keeps apart from `level.dat` and the world data record: the
world's script dynamic properties and the scoreboard, in Bedrock's form, and the command
storage, the maps and the structures explorer maps point at, which Bedrock has no record for.

#### Properties

##### commandStorage

> `readonly` **commandStorage**: `SavedCommandStorage`

Defined in: [packages/prismarine/src/world/providers/SavePass.ts:19](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/providers/SavePass.ts#L19)

##### dynamicProperties

> `readonly` **dynamicProperties**: [`DynamicProperties`](https://jsprismarine.dev/api/@jsprismarine/prismarine/world/dynamicProperties/index.md#dynamicproperties)

Defined in: [packages/prismarine/src/world/providers/SavePass.ts:17](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/providers/SavePass.ts#L17)

##### maps

> `readonly` **maps**: `ReadonlyMap`\<`number`, [`SavedMap`](https://jsprismarine.dev/api/@jsprismarine/prismarine/world/savedMap/index.md#savedmap)\>

Defined in: [packages/prismarine/src/world/providers/SavePass.ts:21](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/providers/SavePass.ts#L21)

Every map the level made, by `minecraft:map_id`; see `Level.createMap`.

##### referencedStructures

> `readonly` **referencedStructures**: readonly [`StructureReference`](https://jsprismarine.dev/api/@jsprismarine/prismarine/world/WorldPersistence/index.md#structurereference)[]

Defined in: [packages/prismarine/src/world/providers/SavePass.ts:23](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/providers/SavePass.ts#L23)

The structure starts explorer maps point at, which a skipping search passes over.

##### scoreboard

> `readonly` **scoreboard**: [`SavedScoreboard`](https://jsprismarine.dev/api/@jsprismarine/prismarine/world/Scoreboard/index.md#savedscoreboard)

Defined in: [packages/prismarine/src/world/providers/SavePass.ts:18](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/providers/SavePass.ts#L18)

***

### ProviderSavePass

Defined in: [packages/prismarine/src/world/providers/SavePass.ts:60](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/providers/SavePass.ts#L60)

One save pass's writes to a provider (ADR 0018).

The level takes the cut at one tick boundary: it hands every chunk that changed or holds
entities, every player record and the level record to the pass in one synchronous run. The
pass encodes what it can right away and holds back each chunk's changed sub chunks, which it
encodes on [ProviderSavePass.encode](#encode) or first when a write is about to reach one. Once
nothing is held back, [ProviderSavePass.commit](#commit) writes the pass as one atomic write where
the provider can, and marks each chunk saved as it was at the cut.

#### Properties

##### pendingEncodes

> `readonly` **pendingEncodes**: `number`

Defined in: [packages/prismarine/src/world/providers/SavePass.ts:79](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/providers/SavePass.ts#L79)

How many sub chunks are still to encode.

##### stats

> `readonly` **stats**: [`SavePassStats`](#savepassstats)

Defined in: [packages/prismarine/src/world/providers/SavePass.ts:97](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/providers/SavePass.ts#L97)

#### Methods

##### abandon()

> **abandon**(): `void`

Defined in: [packages/prismarine/src/world/providers/SavePass.ts:96](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/providers/SavePass.ts#L96)

Lets go of every chunk without writing, so they stay dirty for the next pass, and hands the
writes held for this pass to the next one.

###### Returns

`void`

##### commit()

> **commit**(`options`): `Promise`\<`void`\>

Defined in: [packages/prismarine/src/world/providers/SavePass.ts:91](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/providers/SavePass.ts#L91)

Writes the pass, once nothing is held back, with the writes held for it ahead of its own.
A pass that holds nothing writes nothing.

###### Parameters

###### options

`sync` to have the write on disk, not only handed to the operating system.

###### sync

`boolean`

###### Returns

`Promise`\<`void`\>

###### Throws

When the write fails. Every chunk stays dirty, and the next pass writes it again.

##### cutChunk()

> **cutChunk**(`chunk`, `context`, `fresh?`): `void`

Defined in: [packages/prismarine/src/world/providers/SavePass.ts:68](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/providers/SavePass.ts#L68)

Plans a chunk's write as the chunk is now. The chunk then reports writes to the pass until
the pass has encoded it.

###### Parameters

###### chunk

[`Chunk`](https://jsprismarine.dev/api/@jsprismarine/prismarine/world/chunk/Chunk/classes/Chunk.md)

###### context

[`ChunkSaveContext`](https://jsprismarine.dev/api/@jsprismarine/prismarine/world/providers/ChunkSaveContext/index.md#chunksavecontext)

###### fresh?

readonly [`EntitySpawn`](https://jsprismarine.dev/api/@jsprismarine/prismarine/world/EntitySpawn/index.md#entityspawn)[]

For a chunk generated since the last pass and untouched by gameplay (ADR
  0018), the mobs its generation left: they are written as the chunk's pending record in
  place of actor records and a digest, which a chunk whose mobs are not live yet has none of.

###### Returns

`void`

##### encode()

> **encode**(`budget`): `number`

Defined in: [packages/prismarine/src/world/providers/SavePass.ts:84](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/providers/SavePass.ts#L84)

Encodes up to `budget` held-back sub chunks.

###### Parameters

###### budget

`number`

###### Returns

`number`

How many it encoded.

##### putLevelRecord()

> **putLevelRecord**(`data`): `void`

Defined in: [packages/prismarine/src/world/providers/SavePass.ts:75](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/providers/SavePass.ts#L75)

Holds the level record, merged over the one the save holds.

###### Parameters

###### data

[`WorldPersistenceData`](https://jsprismarine.dev/api/@jsprismarine/prismarine/world/WorldPersistence/index.md#worldpersistencedata)

###### Returns

`void`

##### putLevelRecords()

> **putLevelRecords**(`records`): `void`

Defined in: [packages/prismarine/src/world/providers/SavePass.ts:77](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/providers/SavePass.ts#L77)

Holds the level-wide records, in place of the ones the save holds.

###### Parameters

###### records

[`LevelRecords`](#levelrecords)

###### Returns

`void`

##### putPlayer()

> **putPlayer**(`key`, `record`): `boolean`

Defined in: [packages/prismarine/src/world/providers/SavePass.ts:73](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/providers/SavePass.ts#L73)

Holds a player record.

###### Parameters

###### key

`string`

###### record

[`WorldPlayerData`](https://jsprismarine.dev/api/@jsprismarine/prismarine/config/JsonConfigTypes/index.md#worldplayerdata)

###### Returns

`boolean`

False when the provider keeps no player records, and the level writes it elsewhere.

***

### SavePassStats

Defined in: [packages/prismarine/src/world/providers/SavePass.ts:27](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/providers/SavePass.ts#L27)

What one save pass wrote, in keys and bytes; see [ProviderSavePass.stats](#stats).

#### Properties

##### bypassedWrites

> `readonly` **bypassedWrites**: `number`

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

Sub chunks that had changed when their turn came although no write told the cut, which
means something wrote around the chunk and the pass saved a later tick's content.

Zero for TypeScript callers: a chunk hands out its sub chunks read-only. It stays as a
check that costs one comparison per encode, because a plugin in plain JavaScript can still
reach a sub chunk's own `setBlock`, and so can a generator that kept a sub chunk it handed
to a chunk. The save pass tests assert it stays zero.

##### bytes

> `readonly` **bytes**: `number`

Defined in: [packages/prismarine/src/world/providers/SavePass.ts:31](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/providers/SavePass.ts#L31)

The batch's approximate size, keys and values together.

##### forcedSubChunkEncodes

> `readonly` **forcedSubChunkEncodes**: `number`

Defined in: [packages/prismarine/src/world/providers/SavePass.ts:37](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/providers/SavePass.ts#L37)

Sub chunks a write made the pass encode before their turn.

##### heldWrites

> `readonly` **heldWrites**: `number`

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

Keys written outside a pass and held for this one, which it commits ahead of its own.

##### keys

> `readonly` **keys**: `number`

Defined in: [packages/prismarine/src/world/providers/SavePass.ts:29](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/providers/SavePass.ts#L29)

Keys put or deleted.

##### subChunkEncodes

> `readonly` **subChunkEncodes**: `number`

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

Sub chunks encoded after the cut, whether on the pass's own schedule or before a write.
