Proper cutting board
This commit is contained in:
@@ -123,6 +123,8 @@ interface SavedTile {
|
||||
z: number;
|
||||
// what BlockRef.data holds
|
||||
mod_data?: unknown;
|
||||
// what it shows, see ServerWorld.set_block_item in the mod api
|
||||
item?: ItemData;
|
||||
}
|
||||
|
||||
// the loaded mods, see load_mods.ts
|
||||
@@ -197,7 +199,14 @@ export class GameServer {
|
||||
this.containers.set(id, container);
|
||||
}
|
||||
for (const tile of saved?.tiles ?? []) {
|
||||
this.world.add_tile({ id: tile.id, x: tile.x, y: tile.y, z: tile.z, mod_data: tile.mod_data });
|
||||
this.world.add_tile({
|
||||
id: tile.id,
|
||||
x: tile.x,
|
||||
y: tile.y,
|
||||
z: tile.z,
|
||||
mod_data: tile.mod_data,
|
||||
item: tile.item,
|
||||
});
|
||||
}
|
||||
this.entities.load(saved?.version === 4 ? upgrade_v4_entities(saved.entities) : saved?.entities ?? []);
|
||||
this.#saved_players = saved?.players ?? {};
|
||||
@@ -218,6 +227,16 @@ 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,
|
||||
);
|
||||
for (const player of this.#players.values()) {
|
||||
if (player.chunks.has_block(x, z)) {
|
||||
this.#host.send(player.conn, data);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// connections
|
||||
@@ -331,6 +350,7 @@ export class GameServer {
|
||||
y: tile.y,
|
||||
z: tile.z,
|
||||
mod_data: tile.mod_data,
|
||||
item: tile.item,
|
||||
})),
|
||||
containers: Object.fromEntries(
|
||||
[...this.containers].map(([id, container]) => [id, container.to_data()]),
|
||||
@@ -1458,6 +1478,9 @@ 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! });
|
||||
}
|
||||
}
|
||||
this.#send(player, { type: "chunk_batch_finished", size: batch.length });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user