Better world generation

This commit is contained in:
2026-09-25 17:14:26 -03:00
parent c750321ced
commit d07528bd0e
14 changed files with 1315 additions and 334 deletions
+40
View File
@@ -0,0 +1,40 @@
import { assert, assertEquals } from "@std/assert";
import { CHUNK_AREA, CHUNK_HEIGHT, SEA_LEVEL } from "$/common/constants.ts";
import { generate_raw_chunk } from "$/common/generation.ts";
import { test_game } from "./helpers.ts";
Deno.test("the overworld generates the same way every time, with water only below sea level", async () => {
const { game } = await test_game("mods");
const ids = game.world.block_ids;
const water = ids["bworld:water"];
for (let cx = -4; cx < 4; cx++) {
for (let cz = -4; cz < 4; cz++) {
const { blocks } = generate_raw_chunk(cx, cz, "worldgen-test", ids);
assertEquals(blocks, generate_raw_chunk(cx, cz, "worldgen-test", ids).blocks, "same chunk, same blocks");
for (let i = 0; i < CHUNK_AREA; i++) {
assert(blocks[i] !== 0, "the bottom of the world is solid");
assertEquals(blocks[(CHUNK_HEIGHT - 1) * CHUNK_AREA + i], 0, "nothing reaches the top of the world");
}
blocks.forEach((block, i) => {
if (block === water) {
assert(Math.floor(i / CHUNK_AREA) < SEA_LEVEL, "water above sea level");
}
});
}
}
});
Deno.test("new players spawn on dry land, all in the same place", async () => {
const { game, join } = await test_game("mods");
const joined = join(1, "alice");
const { x, y, z } = joined.spawn;
const ground = game.world.get_block_id(Math.floor(x), y - 1, Math.floor(z));
assert(ground !== "bworld:air" && ground !== "bworld:water", `spawned on ${ground}`);
assertEquals(game.world.get_block_id(Math.floor(x), y, Math.floor(z)), "bworld:air");
assert(y > SEA_LEVEL, "above the sea");
// the same place for the next new player
assertEquals(join(2, "bob").spawn, joined.spawn);
});