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

# world/WorldChangeSink

## Interfaces

### NamedSoundOptions

Defined in: [packages/prismarine/src/world/WorldChangeSink.ts:11](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldChangeSink.ts#L11)

How loud and how high a named sound plays, when the definition's own values are not wanted.

Vanilla varies a few throws this way: the eye of ender leaves the hand at half volume and a
low random pitch, which is what tells it apart from a bow.

#### Properties

##### follows?

> `readonly` `optional` **follows?**: `bigint`

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

The runtime id of the entity the sound comes from and follows as it moves.

##### madeBy?

> `readonly` `optional` **madeBy?**: `bigint`

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

The runtime id of the player whose click made the sound, whose Java client plays it itself.

##### pitch?

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

Defined in: [packages/prismarine/src/world/WorldChangeSink.ts:15](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldChangeSink.ts#L15)

A multiplier on the definition's pitch; one leaves it as written.

##### radius?

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

Defined in: [packages/prismarine/src/world/WorldChangeSink.ts:24](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldChangeSink.ts#L24)

How far away, in blocks, players are sent the sound, for one Java broadcasts further than
the usual sound radius, such as a level event's 64 blocks.

##### volume?

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

Defined in: [packages/prismarine/src/world/WorldChangeSink.ts:13](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldChangeSink.ts#L13)

A multiplier on the definition's volume; one leaves it as written.

***

### WorldChangeSink

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

Where a world reports what just happened in it.

The world's one outward-facing seam. Half of what has to reach a client is not state at all:
a sound, a burst of particles, a block cracking are transient facts that are gone by the end
of the tick, so nothing downstream could recover them by looking at the world afterwards. The
world logs them as occurrences in its change log, and the sink reads them from each sealed
tick with the block changes, so an occurrence made in a unit that throws is never sent.

What it must not do is say them in packets. Every method here is a fact about the world -
a block is now this, an entity moved - and turning that into bytes, deciding who is near
enough to receive it and putting it on a connection is the network layer's business. That
is what `NetworkWorldReplicator` is.

Every method is synchronous: a world that has just changed a block is not waiting to hear
whether the news went out. The tick-phase methods at the bottom queue their packets before
they return and do not wait for the transport, so the order the tick calls them in is the
order the packets leave in, which is a correctness guarantee - an entity that came into range
has to be spawned before the first packet that says it moved.

#### Methods

##### chunkEntered()

> **chunkEntered**(`x`, `z`, `blockEntities`): `void`

Defined in: [packages/prismarine/src/world/WorldChangeSink.ts:78](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldChangeSink.ts#L78)

A chunk entered the world, with the block entities it arrived with. The log names a chunk
that enters and does not carry it, so a reader that keeps block entities takes them here,
and the log's entries change them from then on.

###### Parameters

###### x

`number`

The chunk's x, in chunks.

###### z

`number`

The chunk's z, in chunks.

###### blockEntities

`Iterable`\<[`NBTTagCompound`](https://jsprismarine.dev/api/@jsprismarine/nbt/classes/NBTTagCompound.md)\>

Its block entities as it serializes them,
  produced as they are iterated, and only valid during the call.

###### Returns

`void`

##### chunkLeft()

> **chunkLeft**(`x`, `z`): `void`

Defined in: [packages/prismarine/src/world/WorldChangeSink.ts:85](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldChangeSink.ts#L85)

A chunk left the world.

###### Parameters

###### x

`number`

The chunk's x, in chunks.

###### z

`number`

The chunk's z, in chunks.

###### Returns

`void`

##### entityMoved()

> **entityMoved**(`entity`, `teleport?`): `void`

Defined in: [packages/prismarine/src/world/WorldChangeSink.ts:94](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldChangeSink.ts#L94)

A player's session moved its player, as a client's move or a teleport the server made.

Recorded rather than sent, and put on the wire once by [WorldChangeSink.flushMovement](#flushmovement).
Every other move of an entity is read from the change log.

###### Parameters

###### entity

[`ShownActor`](https://jsprismarine.dev/api/@jsprismarine/prismarine/world/ShownActor/index.md#shownactor)

The entity that moved.

###### teleport?

`boolean`

###### Returns

`void`

##### flushBlockChanges()

> **flushBlockChanges**(): `void`

Defined in: [packages/prismarine/src/world/WorldChangeSink.ts:166](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldChangeSink.ts#L166)

Tick phase: send the block changes this tick produced, as one batch each.

###### Returns

`void`

##### flushBlockEntities()

> **flushBlockEntities**(): `void`

Defined in: [packages/prismarine/src/world/WorldChangeSink.ts:175](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldChangeSink.ts#L175)

Tick phase: send the block entity changes this tick produced, one packet per position.

Runs after [WorldChangeSink.flushBlockChanges](#flushblockchanges) so that a block entity placed and
filled in the same tick is announced as a block before it is announced as a block
entity - see [WorldChangeSink.tickSealed](#ticksealed).

###### Returns

`void`

##### flushDepartures()

> **flushDepartures**(): `void`

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

Tick phase: take the entities that left off every client. Runs after
[WorldChangeSink.flushOccurrences](#flushoccurrences), so what happened to an entity in the tick it
left, such as the hurt flash of a killing blow, reaches the clients tracking it first.

###### Returns

`void`

##### flushEntities()

> **flushEntities**(): `void`

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

Tick phase: send what the sealed ticks did to the world's entities - which entered, and
the equipment, metadata and health of those whose fields they wrote - and queue their moves
for [WorldChangeSink.flushMovement](#flushmovement) and their departures for
[WorldChangeSink.flushDepartures](#flushdepartures). Runs after the seal, first of the sends, so an
entity that entered is shown before anything about it changes or happens to it.

###### Returns

`void`

##### flushLight()

> **flushLight**(): `void`

Defined in: [packages/prismarine/src/world/WorldChangeSink.ts:182](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldChangeSink.ts#L182)

Tick phase: send the light the block changes moved to the clients that keep their own copy
of it. Runs after [WorldChangeSink.flushBlockEntities](#flushblockentities), so a client has the blocks the
light is about.

###### Returns

`void`

##### flushMovement()

> **flushMovement**(): `void`

Defined in: [packages/prismarine/src/world/WorldChangeSink.ts:187](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldChangeSink.ts#L187)

Tick phase: send the movement this tick produced, as one batch each.

###### Returns

`void`

##### flushOccurrences()

> **flushOccurrences**(): `void`

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

Tick phase: send the occurrences of the ticks read since the last flush, such as sounds,
particles and actor events, in the order the log holds them.

Runs after [WorldChangeSink.flushEntities](#flushentities) and ahead of the block changes, so a
block's break particles still reach a client ahead of the block change, as they did when
they were sent the moment they happened, and an event about an entity that entered reaches
a client that was just shown it.

###### Returns

`void`

##### flushOwnerViews()

> **flushOwnerViews**(): `void`

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

Tick phase: send each player's client what the ticks read since the last flush changed in
its own view and that nothing else sends it: the offers of a trader it trades with, after
a `merchant` entry, and each slot a `slot-shown` occurrence names.

Runs after [WorldChangeSink.flushOccurrences](#flushoccurrences), as close to the input that made the
change as a send after the seal can be.

###### Returns

`void`

##### gameRuleChanged()

> **gameRuleChanged**(`name`, `value`, `editable`): `void`

Defined in: [packages/prismarine/src/world/WorldChangeSink.ts:109](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldChangeSink.ts#L109)

A game rule now has a different value, or may now be changed by a player when it could
not be before.

###### Parameters

###### name

`string`

The rule's name, spelled as the client spells it.

###### value

`number` \| `boolean`

What it is now.

###### editable

`boolean`

Whether a player may change it from the settings screen.

###### Returns

`void`

##### reconcile()

> **reconcile**(): `void`

Defined in: [packages/prismarine/src/world/WorldChangeSink.ts:134](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldChangeSink.ts#L134)

Tick phase: bring everyone's idea of what is visible in line with where things now are.

Runs after [WorldChangeSink.flushEntities](#flushentities) and before the movement goes out, so that
an entity that came into range this tick is spawned before the first packet that says it
moved.

###### Returns

`void`

##### shownEntities()

> **shownEntities**(): readonly [`ShownEntity`](https://jsprismarine.dev/api/@jsprismarine/prismarine/world/ShownActor/index.md#shownentity)[]

Defined in: [packages/prismarine/src/world/WorldChangeSink.ts:140](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldChangeSink.ts#L140)

Every entity of the world as tracking reads it, which a player's own pass shows from.

###### Returns

readonly [`ShownEntity`](https://jsprismarine.dev/api/@jsprismarine/prismarine/world/ShownActor/index.md#shownentity)[]

The entities.

##### tickSealed()

> **tickSealed**(`sealed`): `void`

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

One tick of the world's change log, sealed
([ADR 0016](https://jsprismarine.dev/adr/0016-replication-reads-the-change-log.md)). Its block and
block entity entries are what the world's content became, and the only way blocks reach
clients. Its occurrences, such as sounds, particles and actor events, are the only way
those reach clients, and go out by [WorldChangeSink.flushOccurrences](#flushoccurrences).

Read, not sent: the block changes go on the wire once, by
[WorldChangeSink.flushBlockChanges](#flushblockchanges), the same treatment [entityMoved](#entitymoved) gets and
for the same reason. A flood or a collapse changes thousands of blocks in one tick, and a
packet each is a compression pass each. The block entity changes go out by
[WorldChangeSink.flushBlockEntities](#flushblockentities), which runs after it. That order is a
correctness guarantee rather than an economy: a client drops a block entity update for a
position it has no block entity at, so the block has to be announced first.

A tick whose flush never ran, because the tick threw or the world was not updated, is
sent with the next flush.

###### Parameters

###### sealed

[`SealedTick`](https://jsprismarine.dev/api/@jsprismarine/prismarine/world/changelog/ChangeLog/index.md#sealedtick)

The tick's entries.

###### Returns

`void`

##### timeChanged()

> **timeChanged**(`ticks`): `void`

Defined in: [packages/prismarine/src/world/WorldChangeSink.ts:100](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/WorldChangeSink.ts#L100)

The world's clock has been read for broadcasting.

###### Parameters

###### ticks

`number`

The world's time of day.

###### Returns

`void`

## Variables

### NULL\_WORLD\_CHANGE\_SINK

> `const` **NULL\_WORLD\_CHANGE\_SINK**: [`WorldChangeSink`](#worldchangesink)

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

A sink that drops everything, which is what a world with nobody connected to it needs.

The default, so that a `World` is runnable - and testable - with no network layer anywhere
near it. A world built in a unit test does not have to be handed a replicator to be able
to place a block.
