Blocks interacting on the world api

This commit is contained in:
2026-10-15 12:49:44 -03:00
parent 7faa070d83
commit b43e8fe8b8
15 changed files with 493 additions and 28 deletions
+14
View File
@@ -146,6 +146,9 @@ export class ClientLevel {
// the client data of blocks that have some, see BlockRef.set_client_data, by chunk_key then position_key "x,y,z"
block_data = new Map<number, Map<string, BlockData>>();
visuals = new Visuals(this);
// cracks on blocks machines are breaking, the stage to draw by position_key "x,y,z", see break_progress in
// common/protocol.ts
break_progress = new Map<string, { x: number; y: number; z: number; stage: number }>();
// server_blocks is the server's block id for each of its numeric ids
constructor(server_blocks: string[], view_distance: number) {
@@ -533,6 +536,17 @@ export class ClientLevel {
this.#dirty.delete(chunk);
this.block_data.delete(key);
this.visuals.unload(cx, cz);
for (const [position, { x, z }] of this.break_progress) {
if (Math.floor(x / CHUNK_SIZE) === cx && Math.floor(z / CHUNK_SIZE) === cz) {
this.break_progress.delete(position);
}
}
}
// see break_progress in common/protocol.ts
set_break_progress(x: number, y: number, z: number, stage: number | undefined) {
if (stage === undefined) this.break_progress.delete(`${x},${y},${z}`);
else this.break_progress.set(`${x},${y},${z}`, { x, y, z, stage });
}
// see block_data in common/protocol.ts