Recipe types from shared scripts and stuff
This commit is contained in:
@@ -10,6 +10,7 @@ import { block_variant } from "$/common/block_models.ts";
|
||||
import { load_worldgen } from "$/common/worldgen_loader.ts";
|
||||
import { create_mod } from "$/tools/new_mod.ts";
|
||||
import { PLAYER_MENU_CRAFTING, PROTOCOL_VERSION } from "$/common/protocol.ts";
|
||||
import { recipe_lookup } from "$/common/mod_loader.ts";
|
||||
import { container_items, copy_dir, test_game } from "./helpers.ts";
|
||||
|
||||
// mods/bworld plus a mod made from the template, in a temp folder
|
||||
@@ -31,8 +32,8 @@ Deno.test("the base game loads from mods/bworld", async () => {
|
||||
assert(EverythingRegistry.get<ItemRegistry>("items", "bworld:stone"));
|
||||
assert(EverythingRegistry.get<ItemRegistry>("items", "bworld:coal"));
|
||||
assert(game.recipes.shaped.some((recipe) => recipe.result.id === "bworld:oak_planks"));
|
||||
assert(game.recipes.furnace.has("bworld:iron_ore"));
|
||||
assert(game.recipes.fuel.has("bworld:coal"));
|
||||
assert(recipe_lookup(() => game.recipes).find("bworld:smelting", "bworld:iron_ore"));
|
||||
assert(recipe_lookup(() => game.recipes).find("bworld:fuel", "bworld:coal"));
|
||||
assertEquals(EverythingRegistry.get<BlockRegistry>("blocks", "bworld:water")?.replaceable, true);
|
||||
// still has its code until it's a component
|
||||
assert(EverythingRegistry.get<ItemRegistry>("items", "bworld:copper_watering_can")?.on_create);
|
||||
|
||||
@@ -78,12 +78,16 @@ Deno.test("the recipe viewer finds what makes and uses an item, in any recipe ty
|
||||
const served_in_bowls = using("bworld:bowl").map((r) => outputs(r)[0].ids[0]);
|
||||
assert(served_in_bowls.includes("bworld:cooked_rice"));
|
||||
assert(served_in_bowls.includes("bworld:tomato_sauce"));
|
||||
assert(using("bworld:coal").some((r) => r.type === "fuel"));
|
||||
assert(using("bworld:coal").some((r) => r.type === "bworld:fuel"));
|
||||
assert(using("bworld:coal").some((r) => r.type === "shaped" && outputs(r)[0].ids[0] === "bworld:stove"));
|
||||
assert(using("bworld:potato").includes(rolls));
|
||||
|
||||
// smelting and smithing
|
||||
assert(using("bworld:iron_ore").some((r) => r.type === "furnace" && outputs(r)[0].ids[0] === "bworld:iron_ingot"));
|
||||
assert(
|
||||
using("bworld:iron_ore").some((r) =>
|
||||
r.type === "bworld:smelting" && outputs(r)[0].ids[0] === "bworld:iron_ingot"
|
||||
),
|
||||
);
|
||||
assertEquals(ids(inputs(making("bworld:stone_pickaxe")[0])), ["bworld:wood_pickaxe", "bworld:stone"]);
|
||||
assertEquals(category_name("bworld:smithing"), "Smithing");
|
||||
});
|
||||
@@ -104,8 +108,14 @@ Deno.test("recipes are found by category in jei's order, and a catalyst's uses a
|
||||
{ category, recipes },
|
||||
) => [category.type, recipes]);
|
||||
const all = game.recipes.all;
|
||||
assertEquals(furnace_uses.find(([type]) => type === "furnace")?.[1], all.filter((r) => r.type === "furnace"));
|
||||
assertEquals(furnace_uses.find(([type]) => type === "fuel")?.[1], all.filter((r) => r.type === "fuel"));
|
||||
assertEquals(
|
||||
furnace_uses.find(([type]) => type === "bworld:smelting")?.[1],
|
||||
all.filter((r) => r.type === "bworld:smelting"),
|
||||
);
|
||||
assertEquals(
|
||||
furnace_uses.find(([type]) => type === "bworld:fuel")?.[1],
|
||||
all.filter((r) => r.type === "bworld:fuel"),
|
||||
);
|
||||
assertEquals(index.find(item("bworld:air"), "recipes"), []);
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// the base game's bworld:smelting and bworld:fuel recipes, as another mod adding to them sees them
|
||||
import { assertEquals, assertRejects } from "@std/assert";
|
||||
import { recipe_lookup } from "$/common/mod_loader.ts";
|
||||
import { copy_dir, test_game } from "./helpers.ts";
|
||||
|
||||
// the base game, and a mod after it with these recipes
|
||||
function kiln_mod(recipes: Record<string, unknown>) {
|
||||
const dir = Deno.makeTempDirSync({ prefix: "bworld_smelting_" });
|
||||
copy_dir("mods/bworld", `${dir}/bworld`);
|
||||
const write = (path: string, json: unknown) => {
|
||||
Deno.mkdirSync(`${dir}/kiln/${path.split("/").slice(0, -1).join("/")}`, { recursive: true });
|
||||
Deno.writeTextFileSync(`${dir}/kiln/${path}`, JSON.stringify(json));
|
||||
};
|
||||
write("manifest.json", {
|
||||
format_version: 1,
|
||||
id: "kiln",
|
||||
name: "Kiln",
|
||||
version: "1.0.0",
|
||||
dependencies: [{ id: "bworld", version: "*" }],
|
||||
});
|
||||
for (const [name, recipe] of Object.entries(recipes)) write(`recipes/${name}.json`, { format_version: 1, recipe });
|
||||
return dir;
|
||||
}
|
||||
|
||||
Deno.test("a later fuel recipe for an item changes how long it burns, and leaves the rest of the earlier one", async () => {
|
||||
const dir = kiln_mod({ coal: { type: "bworld:fuel", item: ["bworld:coal", "bworld:oak_log"], burn_time: 50 } });
|
||||
const { game } = await test_game(dir);
|
||||
Deno.removeSync(dir, { recursive: true });
|
||||
const recipes = recipe_lookup(() => game.recipes);
|
||||
const burn_time = (id: string) => recipes.find<{ burn_time: number }>("bworld:fuel", id)?.burn_time;
|
||||
assertEquals(burn_time("bworld:coal"), 50);
|
||||
assertEquals(burn_time("bworld:oak_log"), 50);
|
||||
assertEquals(burn_time("bworld:spruce_log"), 100);
|
||||
});
|
||||
|
||||
Deno.test("two smelting recipes for one item stop the mod loading", async () => {
|
||||
const dir = kiln_mod({
|
||||
iron: {
|
||||
type: "bworld:smelting",
|
||||
input: "bworld:iron_ore",
|
||||
output: { id: "bworld:stone", count: 1 },
|
||||
cook_time: 10,
|
||||
},
|
||||
});
|
||||
await assertRejects(() => test_game(dir), Error, "there's already one for bworld:iron_ore");
|
||||
Deno.removeSync(dir, { recursive: true });
|
||||
});
|
||||
+6
-1
@@ -183,7 +183,12 @@ Deno.test("check-mods finds broken tags and tags nobody defines", async () => {
|
||||
write("tags/fluids/maple/sap.json", { format_version: 1, tag: { values: [] } });
|
||||
write("recipes/uses_missing_tag.json", {
|
||||
format_version: 1,
|
||||
recipe: { type: "fuel", item: "#maple:nothing_here", burn_time: 100 },
|
||||
recipe: {
|
||||
type: "shaped",
|
||||
pattern: ["#"],
|
||||
key: { "#": "#maple:nothing_here" },
|
||||
result: { id: "maple:maple_planks", count: 1 },
|
||||
},
|
||||
});
|
||||
// another mod's namespace, without depending on it
|
||||
write("tags/items/kitchen/knives.json", { format_version: 1, tag: { values: ["maple:maple_planks"] } });
|
||||
|
||||
+4
-2
@@ -8,6 +8,7 @@ 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";
|
||||
|
||||
Deno.test("recipes that take planks take any kind, even mixed, but nothing else", async () => {
|
||||
@@ -30,9 +31,10 @@ Deno.test("recipes that take planks take any kind, even mixed, but nothing else"
|
||||
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(game.recipes.fuel.has(log), log);
|
||||
assert(game.recipes.furnace.has(log), log);
|
||||
assert(recipes.find("bworld:fuel", log), log);
|
||||
assert(recipes.find("bworld:smelting", log), log);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user