From 3734f5707a8f40e4825a65d27f058264a03b5126 Mon Sep 17 00:00:00 2001 From: Paula Date: Fri, 30 Oct 2026 23:22:57 -0300 Subject: [PATCH] Register create:compacting recipes for juices --- mods/bworld/scripts/juicing.ts | 18 +++++++++++++++++- tests/juice_test.ts | 20 ++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/mods/bworld/scripts/juicing.ts b/mods/bworld/scripts/juicing.ts index be25fd5..0fc7cdd 100644 --- a/mods/bworld/scripts/juicing.ts +++ b/mods/bworld/scripts/juicing.ts @@ -3,7 +3,8 @@ // juicing recipes: what the juicer presses an item into. the shared script registers one for every item with // bworld:juiceable, its own juice, and mods can add more like any recipe, as files or from their shared scripts. -// whatever makes juice reads them, like the juicer and create's press over a basin +// whatever makes juice reads them, like the juicer. with create installed, each is also a create:compacting recipe, +// so its press can make juice in a basin import type { FluidVariant, SharedContext, TagApi } from "bworld/shared"; import type { JuiceableParams } from "./shared.ts"; @@ -24,6 +25,21 @@ export function register_juicing(ctx: SharedContext) { const juice = { fluid: { id: "bworld:juice", data: { item: id } }, amount: params.juice }; ctx.recipes.register(JUICING, { input: id, fluid_results: [juice] }); } + if (ctx.blocks.exists("create:mechanical_press") && ctx.blocks.exists("create:basin")) { + register_compacting(ctx); + } +} + +// a create:compacting recipe for every juicing recipe there is so far, so create's press squashes the item into its +// juice in a basin under it. create's recipes take a list of item choices and give a list of results, a fluid's as +// { fluid, amount }. juicing recipes other mods' shared scripts register later aren't seen here +function register_compacting(ctx: SharedContext) { + for (const juicing of ctx.recipes.list(JUICING)) { + ctx.recipes.register("create:compacting", { + ingredients: [juicing.input], + results: juicing.fluid_results, + }); + } } // what reading them needs, which server scripts have diff --git a/tests/juice_test.ts b/tests/juice_test.ts index fec84ae..a373303 100644 --- a/tests/juice_test.ts +++ b/tests/juice_test.ts @@ -192,6 +192,26 @@ Deno.test("the juicer juices by bworld:juicing recipes: one for each juiceable i assertEquals(t.game.world.get_tile(1, 100, 0)?.client_data?.tank, pebble_juice); }); +Deno.test("with create's press and basin there, every juicing recipe is also a create:compacting one", async () => { + // every mod in mods/, create among them + const { game } = await test_game("mods"); + const juicing = game.recipes.by_type.get("bworld:juicing")!; + const compacting = game.recipes.by_type.get("create:compacting") ?? []; + assert(juicing.length > 0); + assertEquals( + compacting as unknown, + juicing.map((recipe) => ({ + type: "create:compacting", + ingredients: [recipe.input], + results: recipe.fluid_results, + })), + ); + + // without create there are none + const t = await setup(); + assertEquals(t.game.recipes.by_type.get("create:compacting"), undefined); +}); + Deno.test("a broken juicing recipe stops the server from starting", async () => { const broken = { type: "bworld:juicing",