Move world generation outside the engine and into mods and data files
This commit is contained in:
+21
-5
@@ -1,11 +1,11 @@
|
||||
import { assert, assertEquals } from "@std/assert";
|
||||
import { assert, assertEquals, assertRejects } 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, tree_wood } from "$/common/worldgen/biomes.ts";
|
||||
import { get_biome } from "$/common/worldgen/biomes.ts";
|
||||
import { update_crafting_result } from "$/server/game/crafting.ts";
|
||||
import { test_game } from "./helpers.ts";
|
||||
import { copy_dir, 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");
|
||||
@@ -54,7 +54,7 @@ Deno.test("trees grow the wood of their kind and biome", async () => {
|
||||
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);
|
||||
const { blocks, biomes } = generate_raw_chunk(cx, cz, "wood-test", ids, game.world.worldgen);
|
||||
blocks.forEach((block, i) => {
|
||||
const leaves = leaves_of.get(block);
|
||||
if (leaves) found_leaves.add(leaves);
|
||||
@@ -64,7 +64,9 @@ Deno.test("trees grow the wood of their kind and biome", async () => {
|
||||
const column = i % CHUNK_AREA;
|
||||
const biome = biomes[column];
|
||||
const info = get_biome(biome)!;
|
||||
const allowed = info.trees!.kinds.map((kind) => tree_wood(kind, info));
|
||||
const allowed = info.trees!.kinds.map((kind) =>
|
||||
info.trees!.wood[kind] ?? (kind === "big_oak" ? "oak" : kind)
|
||||
);
|
||||
assert(
|
||||
allowed.includes(wood as never),
|
||||
`${wood} in ${biome} at ${cx * CHUNK_SIZE}, ${cz * CHUNK_SIZE}`,
|
||||
@@ -77,3 +79,17 @@ 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 });
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user