Send block data to clients
This commit is contained in:
@@ -279,10 +279,8 @@ export class GameServer {
|
||||
}
|
||||
}
|
||||
};
|
||||
this.world.on_tile_item_change = (x, y, z, item) => {
|
||||
const data = JSON.stringify(
|
||||
{ type: "set_block_item", x, y, z, item: item ?? null } satisfies ServerMessage,
|
||||
);
|
||||
this.world.on_client_data_change = (x, y, z, changed) => {
|
||||
const data = JSON.stringify({ type: "block_data", x, y, z, data: changed } satisfies ServerMessage);
|
||||
for (const player of this.#players.values()) {
|
||||
if (player.chunks.has_block(x, z)) {
|
||||
this.#host.send(player.conn, data);
|
||||
@@ -688,6 +686,15 @@ export class GameServer {
|
||||
this.world.dirty = true;
|
||||
}
|
||||
|
||||
// BlockRef.set_client_data. a block without a tile only gets one when a field is set, not removed
|
||||
set_tile_client_data(x: number, y: number, z: number, field: string, value: unknown) {
|
||||
if (this.world.get_block_id(x, y, z) === AIR_ID) {
|
||||
return;
|
||||
}
|
||||
const tile = value === undefined ? this.world.get_tile(x, y, z) : this.get_or_create_tile(x, y, z);
|
||||
if (tile) this.world.set_tile_client_data(tile, field, value);
|
||||
}
|
||||
|
||||
// a component turning ticking off for one block, or back on, see BlockRef.set_ticking. it stays off when saved
|
||||
set_tile_ticking(x: number, y: number, z: number, ticking: boolean) {
|
||||
if (this.world.get_block_id(x, y, z) === AIR_ID) {
|
||||
@@ -2108,8 +2115,14 @@ export class GameServer {
|
||||
this.#send(player, { type: "chunk_batch_start" });
|
||||
for (const [x, z] of batch) {
|
||||
this.#host.send(player.conn, this.world.level_chunk(x, z));
|
||||
for (const tile of this.world.item_tiles(x, z)) {
|
||||
this.#send(player, { type: "set_block_item", x: tile.x, y: tile.y, z: tile.z, item: tile.item! });
|
||||
for (const tile of this.world.client_tiles(x, z)) {
|
||||
this.#send(player, {
|
||||
type: "block_data",
|
||||
x: tile.x,
|
||||
y: tile.y,
|
||||
z: tile.z,
|
||||
data: tile.client_data!,
|
||||
});
|
||||
}
|
||||
}
|
||||
this.#send(player, { type: "chunk_batch_finished", size: batch.length });
|
||||
|
||||
Reference in New Issue
Block a user