Send chunks to players connected to server
This commit is contained in:
@@ -2,7 +2,7 @@ import { assert, assertEquals, assertNotEquals } from "@std/assert";
|
||||
import { AIR_ID } from "$/common/protocol.ts";
|
||||
import { CHUNK_VOLUME, decode_chunk, encode_chunk, is_changed, SavedChunk } from "$/server/game/saves.ts";
|
||||
import { read_regions, region_file, write_chunks } from "$/server/regions.ts";
|
||||
import { test_game } from "./helpers.ts";
|
||||
import { sent_block, test_game } from "./helpers.ts";
|
||||
|
||||
function chunk_data(seed: number, palette_size = 3) {
|
||||
const palette: [string, number][] = [];
|
||||
@@ -77,9 +77,11 @@ Deno.test("changed blocks are saved as whole chunks, and only chunks that change
|
||||
assertEquals(loaded.game.world.get_block_id(3, 120, 5), "bworld:stone");
|
||||
assertEquals(loaded.game.world.get_block_id(-20, 120, 40), "bworld:planks");
|
||||
assertEquals(loaded.game.world.get_block_value(-20, 121, 40) >>> 16, 1);
|
||||
// players get the changes, not the whole chunks
|
||||
// players get the whole chunks, with what was saved in them
|
||||
const join = loaded.join(1, "alice");
|
||||
assertEquals(join.changes.length, 3);
|
||||
loaded.send(1, { type: "move", x: 3.5, y: 130, z: 5.5, yaw: 0, pitch: 0 });
|
||||
loaded.game.tick();
|
||||
assertEquals(sent_block(loaded.take(1), join, 3, 120, 5), ["bworld:stone", 0]);
|
||||
// nothing to save again after loading
|
||||
assertEquals(loaded.game.save().chunks, []);
|
||||
});
|
||||
@@ -108,10 +110,9 @@ Deno.test("when world generation is the same, blocks it made come from it", asyn
|
||||
Deno.test("when world generation changed, saved chunks keep their terrain and are saved again", async () => {
|
||||
const { saved, level } = await saved_with_old_terrain();
|
||||
saved.level = JSON.stringify({ ...level, worldgen: "older" });
|
||||
const { game, join } = await test_game("mods", saved);
|
||||
const { game } = await test_game("mods", saved);
|
||||
assertEquals(game.world.get_block_id(3, 121, 5), "bworld:stone");
|
||||
assertEquals(game.world.get_block_id(3, 120, 5), "bworld:stone");
|
||||
assertEquals(join(1, "alice").changes.length, 2);
|
||||
|
||||
const again = game.save();
|
||||
assertNotEquals(JSON.parse(again.level).worldgen, "older");
|
||||
|
||||
Reference in New Issue
Block a user