World sections

This commit is contained in:
2026-11-06 23:13:34 -03:00
parent 818ce22dd6
commit 1fa47c027d
21 changed files with 392 additions and 127 deletions
+5 -4
View File
@@ -3,7 +3,7 @@
// the base game's worldgen features, see mods/bworld/scripts/worldgen.ts
import { assert, assertEquals } from "@std/assert";
import { CHUNK_AREA, CHUNK_SIZE, ID_MASK } from "@/common/constants.ts";
import { CHUNK_SIZE, ID_MASK } from "@/common/constants.ts";
import { generate_raw_chunk } from "@/common/generation.ts";
import { test_game } from "./helpers.ts";
@@ -21,8 +21,9 @@ Deno.test("cacti grow 1 to 3 tall on desert sand, 2 or 3 tries a chunk", async (
for (let dz = -3; dz <= 3; dz++) {
const chunk = generate_raw_chunk(DESERT_CHUNK.x + dx, DESERT_CHUNK.z + dz, SEED, ids, game.world.worldgen);
const { min_y, max_y } = game.world.shape;
const at = (x: number, y: number, z: number) =>
chunk.blocks[(y - min_y) * CHUNK_AREA + z * CHUNK_SIZE + x] & ID_MASK;
const x0 = chunk.column.x * CHUNK_SIZE;
const z0 = chunk.column.z * CHUNK_SIZE;
const at = (x: number, y: number, z: number) => chunk.column.get(x0 + x, y, z0 + z) & ID_MASK;
let in_chunk = 0;
for (let x = 0; x < CHUNK_SIZE; x++) {
for (let z = 0; z < CHUNK_SIZE; z++) {
@@ -30,7 +31,7 @@ Deno.test("cacti grow 1 to 3 tall on desert sand, 2 or 3 tries a chunk", async (
// the bottom of each cactus
if (at(x, y, z) !== cactus || at(x, y - 1, z) === cactus) continue;
assertEquals(at(x, y - 1, z), sand, "on sand");
assertEquals(chunk.biomes[z * CHUNK_SIZE + x], "bworld:desert");
assertEquals(chunk.column.biomes[z * CHUNK_SIZE + x], "bworld:desert");
let height = 0;
while (at(x, y + height, z) === cactus) height++;
heights.push(height);