Juicer recipes register

This commit is contained in:
2026-10-30 22:35:44 -03:00
parent 43521b3675
commit 4717e45a9a
9 changed files with 171 additions and 42 deletions
+51 -6
View File
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// juice: one fluid named, colored and valued after the bworld:juiceable item in its data, and the juicer that makes it
import { assert, assertEquals } from "@std/assert";
import { assert, assertEquals, assertRejects } from "@std/assert";
import { EverythingRegistry, type ItemRegistry } from "$/common/everything_registry.ts";
import type { FluidJson } from "$/common/mod_data.ts";
import type { ClientContext, Instances, Visual, VisualBlock } from "$/common/mod_api/client.ts";
@@ -17,9 +17,11 @@ import { JUICE_VALUE, type JuiceableParams } from "$/mods/bworld/scripts/shared.
import { copy_dir, stone_floor, test_game } from "./helpers.ts";
const CLOUDBERRY = "testberries:cloudberry";
const PEBBLE = "testberries:pebble";
// mods/bworld and another mod with a juiceable berry, so there's always one whatever bworld's items have
async function setup() {
// mods/bworld and another mod with a juiceable berry, so there's always one whatever bworld's items have, a pebble
// that isn't juiceable, and recipes files by name
async function setup(recipes: Record<string, unknown> = {}) {
const dir = Deno.makeTempDirSync({ prefix: "bworld_juice_" });
copy_dir("mods/bworld", `${dir}/bworld`);
const write = (path: string, json: unknown) => {
@@ -41,9 +43,14 @@ async function setup() {
components: { "bworld:juiceable": { juice: 100, color: "#e0a030" } },
},
});
const t = await test_game(dir);
Deno.removeSync(dir, { recursive: true });
return { ...t, fluids: t.game.mods.fluid_rules.api() };
write("items/pebble.json", { format_version: 1, item: { id: PEBBLE, texture: "engine:missing" } });
for (const [name, recipe] of Object.entries(recipes)) write(`recipes/${name}`, { format_version: 1, recipe });
try {
const t = await test_game(dir);
return { ...t, fluids: t.game.mods.fluid_rules.api() };
} finally {
Deno.removeSync(dir, { recursive: true });
}
}
Deno.test("juice made from any item with bworld:juiceable is named after it, in the component's color", async () => {
@@ -156,6 +163,44 @@ Deno.test("the juicer takes juiceable items, juices one every 4 presses, and fil
]);
});
Deno.test("the juicer juices by bworld:juicing recipes: one for each juiceable item, and any a mod adds", async () => {
const pebble_juice = { fluid: { id: "bworld:juice", data: { item: PEBBLE } }, amount: 500 };
const t = await setup({
"pebble_juice.json": { type: "bworld:juicing", input: PEBBLE, fluid_results: [pebble_juice] },
});
const juicing = t.game.recipes.by_type.get("bworld:juicing")!;
const cloudberry = juicing.find((recipe) => recipe.input === CLOUDBERRY)!;
assertEquals(cloudberry.fluid_results, [{
fluid: { id: "bworld:juice", data: { item: CLOUDBERRY } },
amount: 100,
}]);
// the pebble isn't juiceable, but its recipe juices it
t.join(1, "alice");
stone_floor(t.game);
const move = (sneaking: boolean) =>
t.send(1, { type: "move", x: 0.5, y: 100, z: 0.5, yaw: 0, pitch: 0, ...(sneaking && { sneaking }) });
move(false);
const player = t.game.players()[0];
t.game.mods.player(player).give_item(PEBBLE, 1);
t.game.set_block(1, 100, 0, "bworld:juicer");
const use = () => t.send(1, { type: "use_block", x: 1, y: 100, z: 0, face: "top" });
use();
t.send(1, { type: "select_slot", slot: 1 });
move(true);
for (let i = 0; i < 4; i++) use();
assertEquals(t.game.world.get_tile(1, 100, 0)?.client_data?.tank, pebble_juice);
});
Deno.test("a broken juicing recipe stops the server from starting", async () => {
const broken = {
type: "bworld:juicing",
input: PEBBLE,
fluid_results: [{ fluid: { id: "nope:nothing" }, amount: 1 }],
};
await assertRejects(() => setup({ "broken.json": broken }), Error, "bworld:juicing recipe");
});
// a juicer at 1 100 1 drawn by bworld's client script, and a way to set a field of its client data. its fluids have the
// server's rules, the same as a client's
async function drawn_juicer() {
+3 -2
View File
@@ -175,8 +175,9 @@ Deno.test("a crab pot's recipes are what each bait catches in fresh and salt wat
});
Deno.test("each juiceable item has a juicing recipe that presses it into its own juice", async () => {
await test_game("mods");
const index = new RecipeIndex(client_ctx());
// registered by the base game's shared script, see mods/bworld/scripts/juicing.ts
const { game } = await test_game("mods");
const index = new RecipeIndex(client_ctx(game.recipes.all));
// a strawberry's uses include the juicer pressing it into strawberry juice, shown in a fluid slot
const juicing = index.find(item("bworld:strawberry"), "uses").find((found) => found.category.title === "Juicing")!;