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
@@ -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_HEIGHT, CHUNK_SIZE, ID_MASK } from "@/common/constants.ts";
import { CHUNK_AREA, CHUNK_SIZE, ID_MASK } from "@/common/constants.ts";
import { generate_raw_chunk } from "@/common/generation.ts";
import { test_game } from "./helpers.ts";
@@ -20,11 +20,13 @@ Deno.test("cacti grow 1 to 3 tall on desert sand, 2 or 3 tries a chunk", async (
for (let dx = -3; dx <= 3; dx++) {
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 at = (x: number, y: number, z: number) => chunk.blocks[y * CHUNK_AREA + z * CHUNK_SIZE + x] & ID_MASK;
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;
let in_chunk = 0;
for (let x = 0; x < CHUNK_SIZE; x++) {
for (let z = 0; z < CHUNK_SIZE; z++) {
for (let y = 1; y < CHUNK_HEIGHT; y++) {
for (let y = min_y + 1; y < max_y; y++) {
// 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");