Improve a buuuunch of textures and some reworks
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
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 { BIOME_TREES, tree_wood } from "$/common/worldgen/trees.ts";
|
||||
import { update_crafting_result } from "$/server/game/crafting.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:planks", "bworld: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
|
||||
for (const log of ["bworld:log", "bworld:spruce_log", "bworld:cherry_log"]) {
|
||||
assert(game.recipes.fuel.has(log), log);
|
||||
assert(game.recipes.furnace.has(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<string, string> = {
|
||||
"bworld: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"], ids["bworld:dirt"], ids["bworld:snow"]]);
|
||||
|
||||
const leaves_of = new Map(
|
||||
Object.entries(woods).map(([id, wood]) => [ids[id.replace("log", "leaves")], wood]),
|
||||
);
|
||||
const found = new Set<string>();
|
||||
const found_leaves = new Set<string>();
|
||||
for (let cx = -8; cx < 8; cx++) {
|
||||
for (let cz = -8; cz < 8; cz++) {
|
||||
const { blocks, biomes } = generate_raw_chunk(cx, cz, "wood-test", ids);
|
||||
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;
|
||||
const column = i % CHUNK_AREA;
|
||||
const biome = biomes[column];
|
||||
const allowed = BIOME_TREES[biome].kinds.map((kind) => tree_wood(kind, biome));
|
||||
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());
|
||||
});
|
||||
Reference in New Issue
Block a user