Biome as data
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
// biomes are data, worldgen/biomes/<name>.json in a mod. see common/worldgen/biomes.ts
|
||||
import { assert, assertEquals } from "@std/assert";
|
||||
import { biome_from_json, biome_ids, get_biome, validate_biome } from "$/common/worldgen/biomes.ts";
|
||||
import { test_game } from "./helpers.ts";
|
||||
|
||||
const PLAIN = { id: "my_mod:flat", surface: { top: "bworld:grass", filler: "bworld:dirt", filler_depth: 3 } };
|
||||
|
||||
Deno.test("the bworld mod registers every biome the overworld picks", async () => {
|
||||
await test_game("mods");
|
||||
assertEquals(biome_ids().length, 26);
|
||||
assertEquals(get_biome("bworld:dark_forest")?.trees?.wood.big_oak, "dark_oak");
|
||||
assertEquals(get_biome("bworld:river")?.surface.underwater_top, "bworld:sand");
|
||||
});
|
||||
|
||||
Deno.test("a biome is in spring unless it says otherwise", async () => {
|
||||
await test_game("mods");
|
||||
assertEquals(get_biome("bworld:plains")?.season, "spring");
|
||||
assertEquals(biome_from_json(PLAIN).season, "spring");
|
||||
assertEquals(biome_from_json({ ...PLAIN, season: "winter" }).season, "winter");
|
||||
});
|
||||
|
||||
Deno.test("a biome's surface defaults: underwater is its filler, cliffs aren't bare", () => {
|
||||
const { surface, colors, trees } = biome_from_json(PLAIN);
|
||||
assertEquals(surface.underwater_top, "bworld:dirt");
|
||||
assertEquals(surface.underwater_filler, "bworld:dirt");
|
||||
assertEquals(surface.bare_cliffs, false);
|
||||
assertEquals(colors, { grass: undefined, foliage: undefined, water: undefined });
|
||||
assertEquals(trees, undefined);
|
||||
});
|
||||
|
||||
Deno.test("bad biome json is reported", () => {
|
||||
assertEquals(validate_biome(PLAIN), []);
|
||||
assert(validate_biome({ ...PLAIN, season: "monsoon" }).some((p) => p.startsWith("season")));
|
||||
assert(validate_biome({ ...PLAIN, colors: { grass: "green" } }).some((p) => p.startsWith("colors.grass")));
|
||||
assert(validate_biome({ ...PLAIN, trees: { chance: 2, kinds: ["palm"] } }).length === 2);
|
||||
assert(validate_biome({ id: "my_mod:flat" }).some((p) => p.startsWith("surface")));
|
||||
});
|
||||
@@ -39,6 +39,7 @@ export function mod_sources(mods_dir: string): ServerModSource[] {
|
||||
effects: mod.effects.map((e) => e.json),
|
||||
tags: mod.tags.map((t) => t.json),
|
||||
loot_tables: mod.loot_tables.map((t) => t.json),
|
||||
biomes: mod.biomes.map((b) => b.json),
|
||||
},
|
||||
server_url: url(scripts.server),
|
||||
worldgen_url: url(scripts.worldgen),
|
||||
|
||||
+5
-4
@@ -3,7 +3,7 @@ import { assert, assertEquals } from "@std/assert";
|
||||
import { BlockRegistry, EverythingRegistry } from "$/common/everything_registry.ts";
|
||||
import { CHUNK_AREA, CHUNK_HEIGHT, CHUNK_SIZE } from "$/common/constants.ts";
|
||||
import { generate_raw_chunk } from "$/common/generation.ts";
|
||||
import { BIOME_FOLIAGE_COLORS, BIOME_GRASS_COLORS, BIOME_WATER_COLORS } from "$/common/worldgen/biome_colors.ts";
|
||||
import { get_biome } from "$/common/worldgen/biomes.ts";
|
||||
import { type LayerMesh, TERRAIN_VERTEX_BYTES } from "$/client/workers/chunk_messages.ts";
|
||||
import { test_game } from "./helpers.ts";
|
||||
|
||||
@@ -121,9 +121,10 @@ Deno.test("every column the overworld generates has a biome with grass, foliage
|
||||
const { biomes } = generate_raw_chunk(x, z, game.world.seed, block_ids);
|
||||
assertEquals(biomes.length, CHUNK_AREA);
|
||||
for (const biome of biomes) {
|
||||
assert(biome in BIOME_GRASS_COLORS, `${biome} has no grass color`);
|
||||
assert(biome in BIOME_FOLIAGE_COLORS, `${biome} has no foliage color`);
|
||||
assert(biome in BIOME_WATER_COLORS, `${biome} has no water color`);
|
||||
const { colors } = get_biome(biome)!;
|
||||
assert(colors.grass !== undefined, `${biome} has no grass color`);
|
||||
assert(colors.foliage !== undefined, `${biome} has no foliage color`);
|
||||
assert(colors.water !== undefined, `${biome} has no water color`);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
+3
-2
@@ -3,7 +3,7 @@ import { CHUNK_AREA, CHUNK_SIZE } from "$/common/constants.ts";
|
||||
import { Container, ItemStack } from "$/common/inventory.ts";
|
||||
import { CRAFTING_RESULT_SLOT } from "$/common/protocol.ts";
|
||||
import { generate_raw_chunk } from "$/common/generation.ts";
|
||||
import { BIOME_TREES, tree_wood } from "$/common/worldgen/trees.ts";
|
||||
import { get_biome, tree_wood } from "$/common/worldgen/biomes.ts";
|
||||
import { update_crafting_result } from "$/server/game/crafting.ts";
|
||||
import { test_game } from "./helpers.ts";
|
||||
|
||||
@@ -63,7 +63,8 @@ Deno.test("trees grow the wood of their kind and biome", async () => {
|
||||
if (!wood || !ground.has(blocks[i - CHUNK_AREA])) return;
|
||||
const column = i % CHUNK_AREA;
|
||||
const biome = biomes[column];
|
||||
const allowed = BIOME_TREES[biome].kinds.map((kind) => tree_wood(kind, biome));
|
||||
const info = get_biome(biome)!;
|
||||
const allowed = info.trees!.kinds.map((kind) => tree_wood(kind, info));
|
||||
assert(
|
||||
allowed.includes(wood as never),
|
||||
`${wood} in ${biome} at ${cx * CHUNK_SIZE}, ${cz * CHUNK_SIZE}`,
|
||||
|
||||
Reference in New Issue
Block a user