Make cactus generare in deserts
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
// 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 { generate_raw_chunk } from "$/common/generation.ts";
|
||||
import { test_game } from "./helpers.ts";
|
||||
|
||||
// a desert on this seed, found with estimate_biome
|
||||
const SEED = "cactus-seed";
|
||||
const DESERT_CHUNK = { x: -256, z: -128 };
|
||||
|
||||
Deno.test("cacti grow 1 to 3 tall on desert sand, 2 or 3 tries a chunk", async () => {
|
||||
const { game } = await test_game("mods", undefined, SEED);
|
||||
const ids = game.world.block_ids;
|
||||
const cactus = ids["bworld:cactus"];
|
||||
const sand = ids["bworld:sand"];
|
||||
const heights: number[] = [];
|
||||
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;
|
||||
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++) {
|
||||
// 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");
|
||||
let height = 0;
|
||||
while (at(x, y + height, z) === cactus) height++;
|
||||
heights.push(height);
|
||||
in_chunk++;
|
||||
}
|
||||
}
|
||||
}
|
||||
assert(in_chunk <= 3, `${in_chunk} cacti in one chunk`);
|
||||
}
|
||||
}
|
||||
// 49 chunks, mostly desert
|
||||
assert(heights.length >= 40, `only ${heights.length} cacti`);
|
||||
assert(heights.every((h) => h >= 1 && h <= 3));
|
||||
const share = (h: number) => heights.filter((x) => x === h).length / heights.length;
|
||||
assert(share(1) > 0.4 && share(3) < 0.3, `heights ${JSON.stringify([share(1), share(2), share(3)])}`);
|
||||
});
|
||||
Reference in New Issue
Block a user