Juicer recipes

This commit is contained in:
2026-10-28 12:40:30 -03:00
parent bcd0690ef5
commit 1539cf6933
5 changed files with 127 additions and 28 deletions
+50 -23
View File
@@ -3,10 +3,11 @@
// the recipe viewer mod reads every mod's recipes, its own types included
import { assert, assertEquals } from "@std/assert";
import { category_name } from "../mods/recipe_viewer/scripts/categories.ts";
import { category_name, type RecipeLayout } from "../mods/recipe_viewer/scripts/categories.ts";
import { inputs as recipe_inputs, outputs } from "../mods/recipe_viewer/scripts/recipes.ts";
import { RecipeIndex } from "../mods/recipe_viewer/scripts/recipes_screen.ts";
import { tag_api } from "$/common/tags.ts";
import { FluidRules } from "$/common/fluids.ts";
import { type BlockRegistry, EverythingRegistry, type ItemRegistry } from "$/common/everything_registry.ts";
import type { ClientContext } from "bworld/client";
import { test_game } from "./helpers.ts";
@@ -33,6 +34,22 @@ function client_blocks() {
}
const client_loot = () => ({ table: (id: string) => EverythingRegistry.get("loot_tables", id) });
// the context the recipe viewer gets, with these recipes from the mods' files
// deno-lint-ignore no-explicit-any
function client_ctx(recipes: any[] = []) {
return {
recipes: { list: () => recipes },
tags: tag_api(),
items: client_items(),
blocks: client_blocks(),
loot: client_loot(),
fluids: new FluidRules(() => undefined).api(),
} as unknown as ClientContext;
}
// a recipe layout that keeps nothing, for the parts a test doesn't look at
const ignore: RecipeLayout = { slot: () => {}, fluid: () => {}, texture: () => {}, text: () => {} };
Deno.test("the recipe viewer finds what makes and uses an item, in any recipe type", async () => {
const { game } = await test_game("mods");
const all = game.recipes.all;
@@ -70,13 +87,7 @@ Deno.test("the recipe viewer finds what makes and uses an item, in any recipe ty
Deno.test("recipes are found by category in jei's order, and a catalyst's uses are everything made in it", async () => {
const { game } = await test_game("mods");
const ctx = {
recipes: { list: () => game.recipes.all },
tags: tag_api(),
items: client_items(),
blocks: client_blocks(),
loot: client_loot(),
} as unknown as ClientContext;
const ctx = client_ctx(game.recipes.all);
const index = new RecipeIndex(ctx);
const titles = index.categories.map((category) => category.title);
@@ -95,13 +106,7 @@ Deno.test("recipes are found by category in jei's order, and a catalyst's uses a
Deno.test("clicking a fish shows when and where it bites, and the fishing rod's uses are every fish", async () => {
await test_game("mods");
const ctx = {
recipes: { list: () => [] },
tags: tag_api(),
items: client_items(),
blocks: client_blocks(),
loot: client_loot(),
} as unknown as ClientContext;
const ctx = client_ctx();
const index = new RecipeIndex(ctx);
const [fishing] = index.find("bworld:red_mullet", "recipes");
assertEquals(fishing.category.title, "Fishing");
@@ -109,6 +114,7 @@ Deno.test("clicking a fish shows when and where it bites, and the fishing rod's
const lines: string[] = [];
const slots: string[] = [];
fishing.category.draw(fishing.recipes[0], {
...ignore,
slot: (ingredient) => slots.push(ingredient!.ids[0]),
texture: () => {},
text: (text) => lines.push(text),
@@ -119,7 +125,7 @@ Deno.test("clicking a fish shows when and where it bites, and the fishing rod's
// a lava fish without limits, and every fish under the rod
const lava_lines: string[] = [];
const [lava] = index.find("bworld:prismfish", "recipes");
lava.category.draw(lava.recipes[0], { slot: () => {}, texture: () => {}, text: (text) => lava_lines.push(text) });
lava.category.draw(lava.recipes[0], { ...ignore, text: (text) => lava_lines.push(text) });
assertEquals(lava_lines, ["Seasons: all", "Biomes: all", "Time: all day", "In: Lava"]);
const fish = index.find("bworld:fishing_rod", "uses")[0].recipes.map((recipe) => recipe.result);
assert(fish.includes("bworld:cod") && fish.includes("bworld:prismfish"));
@@ -129,13 +135,7 @@ Deno.test("clicking a fish shows when and where it bites, and the fishing rod's
Deno.test("a crab pot's recipes are what each bait catches in fresh and salt water, with their chances", async () => {
await test_game("mods");
const ctx = {
recipes: { list: () => [] },
tags: tag_api(),
items: client_items(),
blocks: client_blocks(),
loot: client_loot(),
} as unknown as ClientContext;
const ctx = client_ctx();
const index = new RecipeIndex(ctx);
// grubs are bait for both waters, under the crab pot's tab
@@ -152,6 +152,7 @@ Deno.test("a crab pot's recipes are what each bait catches in fresh and salt wat
const slots: [string, string[] | undefined][] = [];
const lines: string[] = [];
seashroom.category.draw(recipe, {
...ignore,
slot: (ingredient, _x, _y, tooltip) => slots.push([ingredient!.ids[0], tooltip]),
texture: () => {},
text: (text) => lines.push(text),
@@ -167,3 +168,29 @@ Deno.test("a crab pot's recipes are what each bait catches in fresh and salt wat
assertEquals(freshwater.result.toSorted(), ["bworld:chorus_snail", "bworld:crayfish", "bworld:leech"]);
assertEquals(freshwater.crabpot.catches.map((c: { chance: number }) => c.chance), [1 / 3, 1 / 3, 1 / 3]);
});
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());
// a strawberry's uses include the juicer pressing it into strawberry juice, shown in a fluid slot
const juicing = index.find("bworld:strawberry", "uses").find((found) => found.category.title === "Juicing")!;
assertEquals(juicing.category.catalysts, ["bworld:juicer"]);
assertEquals(juicing.recipes.length, 1);
const slots: string[] = [];
const fluids: [unknown, number][] = [];
juicing.category.draw(juicing.recipes[0], {
...ignore,
slot: (ingredient) => slots.push(ingredient!.ids[0]),
fluid: (fluid, amount) => fluids.push([fluid, amount]),
});
assertEquals(slots, ["bworld:strawberry"]);
const { juice } = EverythingRegistry.get<ItemRegistry>("items", "bworld:strawberry")!.components![
"bworld:juiceable"
] as { juice: number };
assertEquals(fluids, [[{ id: "bworld:juice", data: { item: "bworld:strawberry" } }, juice]]);
// the juicer's uses are every juiceable item
const pressed = index.find("bworld:juicer", "uses")[0].recipes.map((recipe) => recipe.input);
assert(pressed.includes("bworld:strawberry") && pressed.includes("bworld:melon"));
});