API reference / @jsprismarine/prismarine / world/WorldChangeSink
world/WorldChangeSink
Interfaces
NamedSoundOptions
Defined in: packages/prismarine/src/world/WorldChangeSink.ts:11
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?
readonlyoptionalfollows?:bigint
Defined in: packages/prismarine/src/world/WorldChangeSink.ts:19
The runtime id of the entity the sound comes from and follows as it moves.
madeBy?
readonlyoptionalmadeBy?:bigint
Defined in: packages/prismarine/src/world/WorldChangeSink.ts:17
The runtime id of the player whose click made the sound, whose Java client plays it itself.
pitch?
readonlyoptionalpitch?:number
Defined in: packages/prismarine/src/world/WorldChangeSink.ts:15
A multiplier on the definition's pitch; one leaves it as written.
radius?
readonlyoptionalradius?:number
Defined in: packages/prismarine/src/world/WorldChangeSink.ts:24
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?
readonlyoptionalvolume?:number
Defined in: packages/prismarine/src/world/WorldChangeSink.ts:13
A multiplier on the definition's volume; one leaves it as written.
WorldChangeSink
Defined in: packages/prismarine/src/world/WorldChangeSink.ts:47
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
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>
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
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
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. Every other move of an entity is read from the change log.
Parameters
entity
The entity that moved.
teleport?
boolean
Returns
void
flushBlockChanges()
flushBlockChanges():
void
Defined in: packages/prismarine/src/world/WorldChangeSink.ts:166
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
Tick phase: send the block entity changes this tick produced, one packet per position.
Runs after WorldChangeSink.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.
Returns
void
flushDepartures()
flushDepartures():
void
Defined in: packages/prismarine/src/world/WorldChangeSink.ts:125
Tick phase: take the entities that left off every client. Runs after WorldChangeSink.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
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 and their departures for WorldChangeSink.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
Tick phase: send the light the block changes moved to the clients that keep their own copy of it. Runs after WorldChangeSink.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
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
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 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
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, 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
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
Tick phase: bring everyone's idea of what is visible in line with where things now are.
Runs after WorldChangeSink.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[]
Defined in: packages/prismarine/src/world/WorldChangeSink.ts:140
Every entity of the world as tracking reads it, which a player's own pass shows from.
Returns
readonly ShownEntity[]
The entities.
tickSealed()
tickSealed(
sealed):void
Defined in: packages/prismarine/src/world/WorldChangeSink.ts:67
One tick of the world's change log, sealed (ADR 0016). 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.
Read, not sent: the block changes go on the wire once, by WorldChangeSink.flushBlockChanges, the same treatment 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, 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
The tick's entries.
Returns
void
timeChanged()
timeChanged(
ticks):void
Defined in: packages/prismarine/src/world/WorldChangeSink.ts:100
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
constNULL_WORLD_CHANGE_SINK:WorldChangeSink
Defined in: packages/prismarine/src/world/WorldChangeSink.ts:197
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.