World shape for dimension

This commit is contained in:
2026-11-06 22:49:43 -03:00
parent 7458a2d42a
commit 818ce22dd6
60 changed files with 749 additions and 349 deletions
+5 -3
View File
@@ -4,14 +4,15 @@
// the server sends the world in whole chunks, like minecraft java: nearest first, in batches the client paces, and
// only to players who can see them
import { assert, assertEquals } from "@std/assert";
import { CHUNK_AREA, CHUNK_HEIGHT, CHUNK_SIZE } from "@/common/constants.ts";
import { CHUNK_AREA, CHUNK_SIZE } from "@/common/constants.ts";
import { decode_level_chunk, encode_level_chunk, is_within_view } from "@/common/chunk_streaming.ts";
import { PROTOCOL_VERSION } from "@/common/protocol.ts";
import { sent_block, test_game } from "./helpers.ts";
Deno.test("a chunk comes back as it was encoded, whatever its sections hold", () => {
const blocks = new Uint32Array(CHUNK_AREA * CHUNK_HEIGHT);
// as tall as a dimension can be made, sections are counted in the message
const section = CHUNK_AREA * 16;
const blocks = new Uint32Array(section * 24);
// section 0 is all one block, 1 has 3 kinds, 2 has 16, 3 has 300 (more than a palette holds), the rest air
blocks.fill(7, 0, section);
for (let i = 0; i < section; i++) {
@@ -131,7 +132,8 @@ Deno.test("block changes only go to players who have the chunk, the others get t
// the chunk the server sends is what it has, with the ids join listed
assertEquals(alice.blocks[game.world.block_ids["bworld:stone"]], "bworld:stone");
const chunk = decode_level_chunk(game.world.level_chunk(0, 0));
assertEquals(chunk.blocks[120 * CHUNK_AREA + 5 * CHUNK_SIZE + 3], game.world.get_block_value(3, 120, 5));
const y = 120 - game.world.shape.min_y;
assertEquals(chunk.blocks[y * CHUNK_AREA + 5 * CHUNK_SIZE + 3], game.world.get_block_value(3, 120, 5));
});
Deno.test("/viewdistance caps every player's view distance, and raising it gives them what they asked for", async () => {