diff --git a/MODS.md b/MODS.md index 1cfccd0..a9e63eb 100644 --- a/MODS.md +++ b/MODS.md @@ -72,7 +72,7 @@ deno task build && deno task server # packs the mods and starts a se **Everything else** - [World Generation](docs/modding/worldgen/index.md): ores and features -- [Biomes](docs/modding/worldgen/biomes.md): surfaces, colors, trees and seasons +- [Biomes](docs/modding/worldgen/biomes.md): surfaces, colors and seasons - [Screens](docs/modding/gui/index.md): plain screens, inventory overlays and drawing with `Graphics` - [Networking](docs/modding/networking/index.md): how players get mods and the world - [Saving Data](docs/modding/datastorage/index.md): where a mod keeps what should last diff --git a/client/benchmark/bench_level.ts b/client/benchmark/bench_level.ts index 5f700c8..00d45b6 100644 --- a/client/benchmark/bench_level.ts +++ b/client/benchmark/bench_level.ts @@ -94,11 +94,15 @@ export function bench_blocks(visual_blocks: ReadonlySet): BenchBlocks { const solid = all.filter((b) => plain(b) && cube(b) && layer(b) === "solid" && b.block.has_collision); if (solid.length === 0) throw new Error("The benchmark needs a solid block to build its level with"); - // what the world generator fills the ground with, and a biome with trees for its cover + // what the world generator fills the ground with, and a grassy biome for its cover const by_key = ([a]: [string, unknown], [b]: [string, unknown]) => a.localeCompare(b); const settings = EverythingRegistry.entries("noise_settings").sort(by_key)[0]?.[1]; const biomes = EverythingRegistry.entries("biomes").sort(by_key).map(([, biome]) => biome); - const biome = biomes.find((biome) => biome.trees) ?? biomes[0]; + const grassy = (biome: Biome) => { + const top = by_id(biome.surface.top); + return top !== undefined && tinted(top, "grass"); + }; + const biome = biomes.find(grassy) ?? biomes[0]; const stone = by_id(settings?.default_block) ?? solid[0]; const top = by_id(biome?.surface.top) ?? solid.find((b) => tinted(b, "grass")) ?? stone; const filler = by_id(biome?.surface.filler) ?? stone; diff --git a/common/mod_api/worldgen.ts b/common/mod_api/worldgen.ts index 5231957..3541a5a 100644 --- a/common/mod_api/worldgen.ts +++ b/common/mod_api/worldgen.ts @@ -18,8 +18,6 @@ export interface WorldgenContext { id: Id, modify: (chunk: FeatureChunk, config: C, positions: Position[]) => Position[], ): void; - // every biome mods added, for what features read from them, like which trees grow - biomes(): FeatureBiome[]; } // the order features run in, minecraft's decoration steps. features without one run in the last @@ -42,13 +40,6 @@ export interface FeatureOptions { biomes?: Id | Id[]; } -// a biome, as features see it -export interface FeatureBiome { - id: Id; - // its json's trees, see docs/modding/worldgen/biomes.md - trees?: { chance: number; kinds: string[]; wood: Record }; -} - export interface FeatureChunk { // chunk coordinates readonly x: number; diff --git a/common/worldgen/biomes.ts b/common/worldgen/biomes.ts index 443892f..685b39d 100644 --- a/common/worldgen/biomes.ts +++ b/common/worldgen/biomes.ts @@ -34,15 +34,6 @@ const biome_schema = z.object({ surface: surface_schema, // minecraft's grass, foliage and water colors, which blocks pick with "tint". plains' when not set colors: z.strictObject({ grass: color.optional(), foliage: color.optional(), water: color.optional() }).optional(), - // how likely each tree cell is to have a tree, and which kinds grow, picked evenly (list one twice to make it - // twice as likely). wood is the logs and leaves a kind grows here when it isn't its own, like big oaks being dark - // oak in the dark forest. the trees feature reads it (bworld's, in its worldgen script), which says what kinds - // and woods there are, and checks them when it loads - trees: z.object({ - chance: z.number().min(0).max(1), - kinds: z.array(z.string()).min(1), - wood: z.record(z.string(), z.string()).optional(), - }).optional(), }); export type BiomeJson = z.infer; @@ -54,11 +45,10 @@ export interface Biome { surface: Required; // 0xRRGGBB colors: { grass?: number; foliage?: number; water?: number }; - trees?: { chance: number; kinds: string[]; wood: Record }; } export function biome_from_json(json: BiomeJson): Biome { - const { surface, colors = {}, trees } = json; + const { surface, colors = {} } = json; const color = (value: string | undefined) => value === undefined ? undefined : parseInt(value.slice(1), 16); return { id: json.id, @@ -72,7 +62,6 @@ export function biome_from_json(json: BiomeJson): Biome { bare_cliffs: surface.bare_cliffs ?? false, }, colors: { grass: color(colors.grass), foliage: color(colors.foliage), water: color(colors.water) }, - trees: trees && { chance: trees.chance, kinds: trees.kinds, wood: trees.wood ?? {} }, }; } diff --git a/common/worldgen_loader.ts b/common/worldgen_loader.ts index b2fdd38..2296516 100644 --- a/common/worldgen_loader.ts +++ b/common/worldgen_loader.ts @@ -3,7 +3,7 @@ // imports mods' worldgen scripts and collects what they and mods' data add to generation: the generator, ores, and // features, code and data, in the order they run. used by the game server -import type { FeatureBiome, FeatureChunk, FeatureStep, WorldgenContext } from "@/common/mod_api/worldgen.ts"; +import type { FeatureChunk, FeatureStep, WorldgenContext } from "@/common/mod_api/worldgen.ts"; import type { OreJson } from "@/common/mod_data.ts"; import type { SetupFeature, WorldgenSetup } from "./generation.ts"; import { EverythingRegistry } from "./everything_registry.ts"; @@ -11,7 +11,6 @@ import { ModLoadError } from "./mod_loader.ts"; import { loading_mod } from "./hooks.ts"; import { compile_generator } from "./worldgen/generator.ts"; import type { WorldShape } from "./world_shape.ts"; -import type { Biome } from "./worldgen/biomes.ts"; import { compile_feature, DEFAULT_STEP, @@ -54,14 +53,6 @@ export async function load_worldgen(sources: WorldgenSources): Promise(); const modifiers = new Map(); const data_features = (EverythingRegistry.get_registry("features") ?? []).filter((f) => f); - const biomes = (EverythingRegistry.get_registry("biomes") ?? []).filter((b) => b).map(( - biome, - ): FeatureBiome => ({ - id: biome.id, - ...(biome.trees - ? { trees: { ...biome.trees, kinds: [...biome.trees.kinds], wood: { ...biome.trees.wood } } } - : {}), - })); for (const { mod, url, engine_access } of sources.scripts) { const own = (id: string, what: string) => { @@ -98,7 +89,6 @@ export async function load_worldgen(sources: WorldgenSources): Promise biomes, register_terrain(id) { throw new ModLoadError( mod, diff --git a/docs/modding/worldgen/biomes.md b/docs/modding/worldgen/biomes.md index bd76dc5..9fd5153 100644 --- a/docs/modding/worldgen/biomes.md +++ b/docs/modding/worldgen/biomes.md @@ -1,8 +1,9 @@ # Biomes A biome says what the ground looks like where it's picked: the blocks on top, the colors grass, leaves and water are -tinted, which trees grow, and whether it has a season of its own. Biomes are data, one file each in a mod's -`worldgen/biomes/` folder. The base game's are in `mods/bworld/worldgen/biomes/`. +tinted, and whether it has a season of its own. What grows on it is up to features, see [Features](index.md#features). +Biomes are data, one file each in a mod's `worldgen/biomes/` folder. The base game's are in +`mods/bworld/worldgen/biomes/`. Which biome a place gets is up to the generator's biome rules, from the column's climate, the ground's height and how far under it the place is. A mod's biome generates where a rule it adds puts it, see @@ -32,37 +33,27 @@ so is the filler under them. "grass": "#507a32", "foliage": "#59ae30", "water": "#3f76e4" - }, - "trees": { - "chance": 1, - "kinds": ["big_oak", "big_oak", "oak"], - "wood": { "big_oak": "dark_oak" } } } } ``` -| Field | What it does | When not set | -| --------------------------- | ---------------------------------------------------------------------------------------- | ------------ | -| `id` | in your mod's namespace | required | -| `season` | `spring`, `summer`, `autumn` or `winter`, always, see [Seasons](#seasons) | the calendar | -| `surface.top` | the block on top of the ground | required | -| `surface.filler` | the blocks under it | required | -| `surface.filler_depth` | how many blocks of filler, 0 to 32. Stone is below | required | -| `surface.underwater_top` | the top block where the ground is under water | `filler` | -| `surface.underwater_filler` | the filler under water | `filler` | -| `surface.bare_cliffs` | steep ground shows stone instead of `top` | `false` | -| `colors.grass` | what blocks with `"tint": { "color": "grass" }` are drawn in, as `#rrggbb` | plains' | -| `colors.foliage` | the same for `"foliage"`, like leaves | plains' | -| `colors.water` | the same for `"water"` | plains' | -| `trees.chance` | how likely each tree spot is to get a tree, 0 to 1. Spots are at least 4 blocks apart | no trees | -| `trees.kinds` | which trees grow, picked evenly: list one twice to make it twice as likely | | -| `trees.wood` | the logs and leaves a kind grows here when it isn't its own, like dark oak for `big_oak` | | +| Field | What it does | When not set | +| --------------------------- | -------------------------------------------------------------------------- | ------------ | +| `id` | in your mod's namespace | required | +| `season` | `spring`, `summer`, `autumn` or `winter`, always, see [Seasons](#seasons) | the calendar | +| `surface.top` | the block on top of the ground | required | +| `surface.filler` | the blocks under it | required | +| `surface.filler_depth` | how many blocks of filler, 0 to 32. Stone is below | required | +| `surface.underwater_top` | the top block where the ground is under water | `filler` | +| `surface.underwater_filler` | the filler under water | `filler` | +| `surface.bare_cliffs` | steep ground shows stone instead of `top` | `false` | +| `colors.grass` | what blocks with `"tint": { "color": "grass" }` are drawn in, as `#rrggbb` | plains' | +| `colors.foliage` | the same for `"foliage"`, like leaves | plains' | +| `colors.water` | the same for `"water"` | plains' | -Tree kinds are `oak`, `big_oak`, `birch`, `spruce`, `jungle`, `acacia` and `cherry`. Woods are `oak`, `spruce`, `birch`, -`jungle`, `acacia`, `dark_oak` and `cherry`. Trees only grow on grass, dirt or snow with air above. They're the base -game's trees feature (`mods/bworld/scripts/trees.ts`), which reads every biome's `trees`. It checks the kinds and woods -when the server starts, so `check-mods` doesn't. +The base game's trees are a feature of its own, not part of biomes: `BIOME_TREES` in `mods/bworld/scripts/trees.ts` says +which kinds grow in each of its biomes, how often, and in which wood. Above the snow line, around y 176, the top block is snow whatever the biome says. diff --git a/docs/modding/worldgen/index.md b/docs/modding/worldgen/index.md index 68676be..dd7a340 100644 --- a/docs/modding/worldgen/index.md +++ b/docs/modding/worldgen/index.md @@ -125,9 +125,6 @@ cell agrees on where its tree is. `set_block` can write up to one chunk away, so a tree near the border can grow into the next chunk. Writes into another chunk only fill air, so the result doesn't depend on which chunk generates first. -`gen.biomes()` lists every biome mods added, with their `trees`, for features that read biomes' data the way the base -game's trees do. - Generated blocks don't run `on_create`, and worldgen scripts can't use the server or client API. ### Data Features diff --git a/docs/modding/worldgen/terrain.md b/docs/modding/worldgen/terrain.md index a04111f..598cf03 100644 --- a/docs/modding/worldgen/terrain.md +++ b/docs/modding/worldgen/terrain.md @@ -30,8 +30,7 @@ Ids can have folders, like `bworld:overworld/erosion` in `worldgen/density_funct steep. 3. Each solid block goes through the `surface_rule`, which gives grass, sand, snow and so on, or `default_block`. 4. Each empty block below the surface of a `fluid` gets it, like water up to sea level. -5. Then [ores](index.md#ores) and [features](index.md#features), like the base game's trees, which grow as the biome's - `trees` say. +5. Then [ores](index.md#ores) and [features](index.md#features), like the base game's trees. ## Noises diff --git a/mods/bworld/scripts/trees.ts b/mods/bworld/scripts/trees.ts index 4b6cc7b..6b0c1c8 100644 --- a/mods/bworld/scripts/trees.ts +++ b/mods/bworld/scripts/trees.ts @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: 2026 Paula Wisnievski // SPDX-License-Identifier: AGPL-3.0-or-later -// the base game's trees, a feature that's code. biomes say which kinds grow and how often (their json's "trees"), this +// the base game's trees, a feature that's code. BIOME_TREES says which kinds grow in each biome and how often, the rest // says what the kinds are. it isn't data features: each kind would need placers drawing random numbers in exactly // the order grow_tree does, for the world to stay the same, to say what this already says. it runs after ores, which // only replace stone, while trees only fill air or replace leaves, so that order changes nothing. where they grow can't depend on which chunk generates first, so it only depends on the @@ -9,7 +9,7 @@ // other candidate within MIN_DISTANCE has a higher priority (then its biome may still say no). that spreads trees out // like poisson disk sampling: never closer than MIN_DISTANCE, but without lining up in a grid. a tree is placed by the // chunk its trunk is in, leaves that reach into the next chunk only fill air there -import type { FeatureBiome, FeatureChunk, WorldgenContext } from "cubi/worldgen"; +import type { FeatureChunk, WorldgenContext } from "cubi/worldgen"; const CHUNK_SIZE = 16; @@ -26,6 +26,36 @@ export type TreeKind = typeof TREE_KINDS[number]; export const WOODS = ["oak", "spruce", "birch", "jungle", "acacia", "dark_oak", "cherry"] as const; export type Wood = typeof WOODS[number]; +export interface BiomeTrees { + // how likely each cell's spot is to get a tree, 0 to 1 + chance: number; + // picked evenly, so one listed twice is twice as likely + kinds: TreeKind[]; + // the logs and leaves a kind grows here when it isn't its own, like big oaks being dark oak in the dark forest + wood?: Partial>; +} + +// biomes not listed have no trees +export const BIOME_TREES: Record = { + "bworld:dark_forest": { chance: 1, kinds: ["big_oak", "big_oak", "oak"], wood: { big_oak: "dark_oak" } }, + "bworld:forest": { chance: 0.85, kinds: ["oak", "oak", "big_oak", "birch"] }, + "bworld:jungle": { chance: 1, kinds: ["jungle", "jungle", "big_oak"] }, + "bworld:meadow": { chance: 0.06, kinds: ["oak", "birch", "cherry", "cherry"] }, + "bworld:plains": { chance: 0.05, kinds: ["oak"] }, + "bworld:river": { chance: 0.05, kinds: ["oak"] }, + "bworld:savanna": { chance: 0.15, kinds: ["acacia", "acacia", "oak"] }, + "bworld:snowy_plains": { chance: 0.03, kinds: ["spruce"] }, + "bworld:snowy_slopes": { chance: 0.06, kinds: ["spruce"] }, + "bworld:snowy_taiga": { chance: 0.6, kinds: ["spruce"] }, + "bworld:swamp": { chance: 0.4, kinds: ["big_oak"] }, + "bworld:taiga": { chance: 0.75, kinds: ["spruce"] }, +}; + +// the wood a kind grows in a biome: its own, big oaks' is oak, unless the biome says +export function wood_of(trees: BiomeTrees, kind: TreeKind): Wood { + return trees.wood?.[kind] ?? (kind === "big_oak" ? "oak" : kind); +} + type Random = { next(): number }; export interface TreeSite { @@ -200,25 +230,6 @@ const SOIL = new Set(["bworld:grass_block", "bworld:dirt", "bworld:snow_block"]) const LEAVES = new Set(WOODS.map((wood) => `bworld:${wood}_leaves`)); export function register_trees(gen: WorldgenContext) { - const trees = new Map>(); - for (const biome of gen.biomes()) { - if (!biome.trees) continue; - for (const kind of biome.trees.kinds) { - if (!TREE_KINDS.includes(kind as TreeKind)) { - throw new Error(`biome ${biome.id}: trees.kinds: ${kind} isn't one of ${TREE_KINDS.join(", ")}`); - } - } - for (const [kind, wood] of Object.entries(biome.trees.wood)) { - if (!TREE_KINDS.includes(kind as TreeKind)) { - throw new Error(`biome ${biome.id}: trees.wood: ${kind} isn't a kind of tree`); - } - if (!WOODS.includes(wood as Wood)) { - throw new Error(`biome ${biome.id}: trees.wood.${kind} must be one of ${WOODS.join(", ")}`); - } - } - trees.set(biome.id, biome.trees); - } - gen.register_feature("bworld:trees", (chunk) => { const x0 = chunk.x * CHUNK_SIZE; const z0 = chunk.z * CHUNK_SIZE; @@ -237,7 +248,7 @@ export function register_trees(gen: WorldgenContext) { for (const site of tree_sites(chunk)) { // the biome of the ground it grows from const ground_y = chunk.height_at(site.x, site.z); - const here = trees.get(chunk.biome_at(site.x, ground_y, site.z)); + const here = BIOME_TREES[chunk.biome_at(site.x, ground_y, site.z)]; if (!here || site.rng.next() >= here.chance) continue; // on soil with air above it, so never under water or on bare rock @@ -245,9 +256,8 @@ export function register_trees(gen: WorldgenContext) { const above = chunk.get_block(site.x, ground_y + 1, site.z); if (!SOIL.has(ground!) || above !== "cubi:air") continue; - const kind = here.kinds[Math.floor(site.rng.next() * here.kinds.length)] as TreeKind; - // big oaks grow oak, every other kind its own wood, unless the biome says - const wood = here.wood[kind] ?? (kind === "big_oak" ? "oak" : kind); + const kind = here.kinds[Math.floor(site.rng.next() * here.kinds.length)]; + const wood = wood_of(here, kind); grow_tree( kind, site.x, diff --git a/mods/bworld/worldgen/biomes/dark_forest.json b/mods/bworld/worldgen/biomes/dark_forest.json index 768a10d..0649ccd 100644 --- a/mods/bworld/worldgen/biomes/dark_forest.json +++ b/mods/bworld/worldgen/biomes/dark_forest.json @@ -12,17 +12,6 @@ "grass": "#507a32", "foliage": "#59ae30", "water": "#3f76e4" - }, - "trees": { - "chance": 1, - "kinds": [ - "big_oak", - "big_oak", - "oak" - ], - "wood": { - "big_oak": "dark_oak" - } } } } diff --git a/mods/bworld/worldgen/biomes/forest.json b/mods/bworld/worldgen/biomes/forest.json index 2a4b0c9..94ea898 100644 --- a/mods/bworld/worldgen/biomes/forest.json +++ b/mods/bworld/worldgen/biomes/forest.json @@ -12,15 +12,6 @@ "grass": "#79c05a", "foliage": "#59ae30", "water": "#3f76e4" - }, - "trees": { - "chance": 0.85, - "kinds": [ - "oak", - "oak", - "big_oak", - "birch" - ] } } } diff --git a/mods/bworld/worldgen/biomes/jungle.json b/mods/bworld/worldgen/biomes/jungle.json index 3058779..1db3c4d 100644 --- a/mods/bworld/worldgen/biomes/jungle.json +++ b/mods/bworld/worldgen/biomes/jungle.json @@ -12,14 +12,6 @@ "grass": "#59c93c", "foliage": "#30bb0b", "water": "#3f76e4" - }, - "trees": { - "chance": 1, - "kinds": [ - "jungle", - "jungle", - "big_oak" - ] } } } diff --git a/mods/bworld/worldgen/biomes/meadow.json b/mods/bworld/worldgen/biomes/meadow.json index a343c8a..331a391 100644 --- a/mods/bworld/worldgen/biomes/meadow.json +++ b/mods/bworld/worldgen/biomes/meadow.json @@ -12,15 +12,6 @@ "grass": "#83bb6d", "foliage": "#63a948", "water": "#0e4ecf" - }, - "trees": { - "chance": 0.06, - "kinds": [ - "oak", - "birch", - "cherry", - "cherry" - ] } } } diff --git a/mods/bworld/worldgen/biomes/plains.json b/mods/bworld/worldgen/biomes/plains.json index a07dae1..7e0a85f 100644 --- a/mods/bworld/worldgen/biomes/plains.json +++ b/mods/bworld/worldgen/biomes/plains.json @@ -12,12 +12,6 @@ "grass": "#91bd59", "foliage": "#77ab2f", "water": "#3f76e4" - }, - "trees": { - "chance": 0.05, - "kinds": [ - "oak" - ] } } } diff --git a/mods/bworld/worldgen/biomes/river.json b/mods/bworld/worldgen/biomes/river.json index 093a63f..6c95898 100644 --- a/mods/bworld/worldgen/biomes/river.json +++ b/mods/bworld/worldgen/biomes/river.json @@ -14,12 +14,6 @@ "grass": "#8eb971", "foliage": "#71a74d", "water": "#3f76e4" - }, - "trees": { - "chance": 0.05, - "kinds": [ - "oak" - ] } } } diff --git a/mods/bworld/worldgen/biomes/savanna.json b/mods/bworld/worldgen/biomes/savanna.json index 542a12e..6952504 100644 --- a/mods/bworld/worldgen/biomes/savanna.json +++ b/mods/bworld/worldgen/biomes/savanna.json @@ -12,14 +12,6 @@ "grass": "#bfb755", "foliage": "#aea42a", "water": "#3f76e4" - }, - "trees": { - "chance": 0.15, - "kinds": [ - "acacia", - "acacia", - "oak" - ] } } } diff --git a/mods/bworld/worldgen/biomes/snowy_plains.json b/mods/bworld/worldgen/biomes/snowy_plains.json index 2f6b28a..4b1e2f7 100644 --- a/mods/bworld/worldgen/biomes/snowy_plains.json +++ b/mods/bworld/worldgen/biomes/snowy_plains.json @@ -13,12 +13,6 @@ "foliage": "#60a17b", "water": "#3f76e4" }, - "trees": { - "chance": 0.03, - "kinds": [ - "spruce" - ] - }, "season": "winter" } } diff --git a/mods/bworld/worldgen/biomes/snowy_slopes.json b/mods/bworld/worldgen/biomes/snowy_slopes.json index adb0d47..b335920 100644 --- a/mods/bworld/worldgen/biomes/snowy_slopes.json +++ b/mods/bworld/worldgen/biomes/snowy_slopes.json @@ -13,12 +13,6 @@ "foliage": "#60a17b", "water": "#3f76e4" }, - "trees": { - "chance": 0.06, - "kinds": [ - "spruce" - ] - }, "season": "winter" } } diff --git a/mods/bworld/worldgen/biomes/snowy_taiga.json b/mods/bworld/worldgen/biomes/snowy_taiga.json index 8c84eeb..154cc2d 100644 --- a/mods/bworld/worldgen/biomes/snowy_taiga.json +++ b/mods/bworld/worldgen/biomes/snowy_taiga.json @@ -13,12 +13,6 @@ "foliage": "#60a17b", "water": "#3d57d6" }, - "trees": { - "chance": 0.6, - "kinds": [ - "spruce" - ] - }, "season": "winter" } } diff --git a/mods/bworld/worldgen/biomes/swamp.json b/mods/bworld/worldgen/biomes/swamp.json index 1139e0e..69f44b2 100644 --- a/mods/bworld/worldgen/biomes/swamp.json +++ b/mods/bworld/worldgen/biomes/swamp.json @@ -11,12 +11,6 @@ "grass": "#6a7039", "foliage": "#6a7039", "water": "#617b64" - }, - "trees": { - "chance": 0.4, - "kinds": [ - "big_oak" - ] } } } diff --git a/mods/bworld/worldgen/biomes/taiga.json b/mods/bworld/worldgen/biomes/taiga.json index 68379a3..2c4b350 100644 --- a/mods/bworld/worldgen/biomes/taiga.json +++ b/mods/bworld/worldgen/biomes/taiga.json @@ -12,12 +12,6 @@ "grass": "#86b783", "foliage": "#68a464", "water": "#3f76e4" - }, - "trees": { - "chance": 0.75, - "kinds": [ - "spruce" - ] } } } diff --git a/tests/biome_test.ts b/tests/biome_test.ts index 55b3ec4..7318151 100644 --- a/tests/biome_test.ts +++ b/tests/biome_test.ts @@ -19,7 +19,6 @@ const PLAIN = { id: "my_mod:flat", surface: { top: "bworld:grass_block", filler: 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"); }); @@ -49,22 +48,16 @@ Deno.test("a biome follows the calendar unless it says otherwise", async () => { }); Deno.test("a biome's surface defaults: underwater is its filler, cliffs aren't bare", () => { - const { surface, colors, trees } = biome_from_json(PLAIN); + const { surface, colors } = 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"))); - // which kinds of tree there are is up to the trees feature, see tests/wood_test.ts - assertEquals(validate_biome({ ...PLAIN, trees: { chance: 2, kinds: ["palm"] } }), [ - "trees.chance must be at most 1", - ]); - assert(validate_biome({ ...PLAIN, trees: { chance: 1, kinds: [] } }).some((p) => p.startsWith("trees.kinds"))); assert(validate_biome({ id: "my_mod:flat" }).some((p) => p.startsWith("surface"))); }); diff --git a/tests/wood_test.ts b/tests/wood_test.ts index cda0f20..841f118 100644 --- a/tests/wood_test.ts +++ b/tests/wood_test.ts @@ -1,15 +1,15 @@ // SPDX-FileCopyrightText: 2026 Paula Wisnievski // SPDX-License-Identifier: AGPL-3.0-or-later -import { assert, assertEquals, assertRejects } from "@std/assert"; +import { assert, assertEquals } from "@std/assert"; 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 { get_biome } from "@/common/worldgen/biomes.ts"; import { update_crafting_result } from "@/server/game/crafting.ts"; import { recipe_lookup } from "@/common/mod_loader.ts"; -import { copy_dir, test_game } from "./helpers.ts"; +import { BIOME_TREES, wood_of as tree_wood } from "@/mods/bworld/scripts/trees.ts"; +import { test_game } from "./helpers.ts"; Deno.test("recipes that take planks take any kind, even mixed, but nothing else", async () => { const { game } = await test_game("mods"); @@ -70,10 +70,8 @@ Deno.test("trees grow the wood of their kind and biome", async () => { // the trunk's ground's biome const y = game.world.shape.min_y + Math.floor(i / CHUNK_AREA) - 1; const biome = column.biome_at(cx * 16 + i % 16, y, cz * 16 + Math.floor(i / 16) % 16); - const info = get_biome(biome)!; - const allowed = info.trees!.kinds.map((kind) => - info.trees!.wood[kind] ?? (kind === "big_oak" ? "oak" : kind) - ); + const trees = BIOME_TREES[biome]; + const allowed = trees ? trees.kinds.map((kind) => tree_wood(trees, kind)) : []; assert( allowed.includes(wood as never), `${wood} in ${biome} at ${cx * CHUNK_SIZE}, ${cz * CHUNK_SIZE}`, @@ -86,17 +84,3 @@ Deno.test("trees grow the wood of their kind and biome", async () => { // each tree's leaves are its own wood's assertEquals([...found_leaves].sort(), [...found].sort()); }); - -Deno.test("a biome with a kind of tree bworld's trees don't have stops the server", async () => { - const dir = Deno.makeTempDirSync({ prefix: "bworld_trees_" }); - copy_dir("mods/bworld", `${dir}/bworld`); - const path = `${dir}/bworld/worldgen/biomes/forest.json`; - const json = JSON.parse(Deno.readTextFileSync(path)); - json.biome.trees.kinds.push("palm"); - Deno.writeTextFileSync(path, JSON.stringify(json)); - try { - await assertRejects(() => test_game(dir), Error, "biome bworld:forest: trees.kinds: palm isn't one of oak"); - } finally { - Deno.removeSync(dir, { recursive: true }); - } -});