// SPDX-FileCopyrightText: 2026 Paula Wisnievski // SPDX-License-Identifier: AGPL-3.0-or-later 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 { update_crafting_result } from "@/server/game/crafting.ts"; import { recipe_lookup } from "@/common/mod_loader.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"); const craft = (top: string, bottom: string) => { const grid = new Container(10); grid.set_item(0, new ItemStack(top, 1)); grid.set_item(3, new ItemStack(bottom, 1)); update_crafting_result(grid, game.recipes.shaped); return grid.get_item(CRAFTING_RESULT_SLOT); }; assertEquals(craft("bworld:oak_planks", "bworld:oak_planks")?.type_id, "bworld:stick"); assertEquals(craft("bworld:birch_planks", "bworld:cherry_planks")?.type_id, "bworld:stick"); assertEquals(craft("bworld:birch_planks", "bworld:stone"), undefined); // and each log makes its own planks const grid = new Container(10); grid.set_item(4, new ItemStack("bworld:dark_oak_log", 1)); update_crafting_result(grid, game.recipes.shaped); assertEquals(grid.get_item(CRAFTING_RESULT_SLOT)?.type_id, "bworld:dark_oak_planks"); // every log burns and smelts const recipes = recipe_lookup(() => game.recipes); for (const log of ["bworld:oak_log", "bworld:spruce_log", "bworld:cherry_log"]) { assert(recipes.find("bworld:fuel", log), log); assert(recipes.find("bworld:smelting", log), log); } }); Deno.test("trees grow the wood of their kind and biome", async () => { const { game } = await test_game("mods"); const ids = game.world.block_ids; const woods: Record = { "bworld:oak_log": "oak", "bworld:spruce_log": "spruce", "bworld:birch_log": "birch", "bworld:jungle_log": "jungle", "bworld:acacia_log": "acacia", "bworld:dark_oak_log": "dark_oak", }; const wood_of = new Map(Object.entries(woods).map(([id, wood]) => [ids[id], wood])); const ground = new Set([ids["bworld:grass_block"], ids["bworld:dirt"], ids["bworld:snow_block"]]); const leaves_of = new Map( Object.entries(woods).map(([id, wood]) => [ids[id.replace("log", "leaves")], wood]), ); const found = new Set(); const found_leaves = new Set(); for (let cx = -8; cx < 8; cx++) { for (let cz = -8; cz < 8; cz++) { const { column } = generate_raw_chunk(cx, cz, "wood-test", ids, game.world.worldgen); const blocks = column.to_flat(); blocks.forEach((block, i) => { const leaves = leaves_of.get(block); if (leaves) found_leaves.add(leaves); const wood = wood_of.get(block); // the bottom of a trunk if (!wood || !ground.has(blocks[i - CHUNK_AREA])) return; // 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 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}`, ); found.add(wood); }); } } assert(found.size >= 3, `only found ${[...found]}`); // each tree's leaves are its own wood's assertEquals([...found_leaves].sort(), [...found].sort()); });