Send chunks to players connected to server

This commit is contained in:
2026-09-28 11:14:40 -03:00
parent 677ad8115a
commit ded9a7e5d0
26 changed files with 920 additions and 357 deletions
+7 -3
View File
@@ -1,5 +1,5 @@
import { assert, assertEquals } from "@std/assert";
import { copy_dir, test_game } from "./helpers.ts";
import { copy_dir, sent_block, test_game } from "./helpers.ts";
import type { WorldSave } from "$/server/game/saves.ts";
// a mod that uses every part of the server api worth testing, and writes down what happened in its storage
@@ -218,6 +218,8 @@ Deno.test("block states start at their defaults, can be changed, and are synced
send(1, { type: "chat", text: `/state ${args}` });
return take(1).filter((m) => m.type === "chat").map((m) => m.text).at(-1);
};
// alice gets the chunks around her, and from then on changes to them
game.tick();
game.set_block(5, 100, 5, "testmod:lamp");
take(1);
assertEquals(state("5 100 5 power"), "state 2");
@@ -232,13 +234,15 @@ Deno.test("block states start at their defaults, can be changed, and are synced
assert(state("5 100 5 power 8").startsWith('error testmod:lamp state "power" has 3 bits'));
assert(state("5 100 5 color").startsWith('error testmod:lamp has no state "color"'));
// saved and loaded, and new players get it with the world's changes
// saved and loaded, and new players get it in the chunk
const saved = game.save();
Deno.removeSync(dir, { recursive: true });
const again = await setup(saved);
assertEquals(again.game.world.get_block_value(5, 100, 5) >>> 16, 5 | (1 << 3));
const joined = again.join(2, "bob");
assert(joined.changes.some((c: unknown[]) => c[0] === 5 && c[3] === "testmod:lamp" && c[4] === (5 | (1 << 3))));
again.send(2, { type: "move", x: 0.5, y: 100, z: 0.5, yaw: 0, pitch: 0 });
again.game.tick();
assertEquals(sent_block(again.take(2), joined, 5, 100, 5), ["testmod:lamp", 5 | (1 << 3)]);
Deno.removeSync(again.dir, { recursive: true });
});