Fluids on the recipeviewer !

This commit is contained in:
2026-10-28 13:26:56 -03:00
parent 3cc33ea10c
commit e525681328
7 changed files with 151 additions and 83 deletions
+24 -11
View File
@@ -47,6 +47,9 @@ function client_ctx(recipes: any[] = []) {
} as unknown as ClientContext;
}
const item = (id: string) => ({ kind: "item" as const, id });
const fluid = (id: string) => ({ kind: "fluid" as const, id });
// a recipe layout that keeps nothing, for the parts a test doesn't look at
const ignore: RecipeLayout = { slot: () => {}, fluid: () => {}, texture: () => {}, text: () => {} };
@@ -97,18 +100,20 @@ Deno.test("recipes are found by category in jei's order, and a catalyst's uses a
"farmersdelight:cooking_pot",
]);
const furnace_uses = index.find("bworld:furnace", "uses").map(({ category, recipes }) => [category.type, recipes]);
const furnace_uses = index.find(item("bworld:furnace"), "uses").map((
{ 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(index.find("bworld:air", "recipes"), []);
assertEquals(index.find(item("bworld:air"), "recipes"), []);
});
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 = client_ctx();
const index = new RecipeIndex(ctx);
const [fishing] = index.find("bworld:red_mullet", "recipes");
const [fishing] = index.find(item("bworld:red_mullet"), "recipes");
assertEquals(fishing.category.title, "Fishing");
assertEquals(fishing.category.catalysts, ["bworld:fishing_rod"]);
const lines: string[] = [];
@@ -124,13 +129,13 @@ 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");
const [lava] = index.find(item("bworld:prismfish"), "recipes");
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);
const fish = index.find(item("bworld:fishing_rod"), "uses")[0].recipes.map((recipe) => recipe.result);
assert(fish.includes("bworld:cod") && fish.includes("bworld:prismfish"));
// a fish isn't a use of the water it lives in
assertEquals(index.find("bworld:water", "uses"), []);
assertEquals(index.find(item("bworld:water"), "uses"), []);
});
Deno.test("a crab pot's recipes are what each bait catches in fresh and salt water, with their chances", async () => {
@@ -139,13 +144,13 @@ Deno.test("a crab pot's recipes are what each bait catches in fresh and salt wat
const index = new RecipeIndex(ctx);
// grubs are bait for both waters, under the crab pot's tab
const [grubs] = index.find("bworld:grubs", "uses");
const [grubs] = index.find(item("bworld:grubs"), "uses");
assertEquals(grubs.category.title, "Crab Pot");
assertEquals(grubs.category.catalysts, ["bworld:crabpot"]);
assertEquals(grubs.recipes.map((recipe) => recipe.crabpot.water), ["freshwater", "saltwater"]);
// a seashroom comes from grubs in salt water, one in 16
const [seashroom] = index.find("bworld:red_seashroom", "recipes");
const [seashroom] = index.find(item("bworld:red_seashroom"), "recipes");
assertEquals(seashroom.recipes.length, 1);
const recipe = seashroom.recipes[0];
assertEquals(recipe.bait, "bworld:grubs");
@@ -163,7 +168,7 @@ Deno.test("a crab pot's recipes are what each bait catches in fresh and salt wat
assertEquals(slots.find(([id]) => id === "bworld:red_seashroom")?.[1], ["6.3% chance"]);
// worms in fresh water catch a third each of three things
const worms = index.find("bworld:worms", "uses").find((found) => found.category.title === "Crab Pot")!;
const worms = index.find(item("bworld:worms"), "uses").find((found) => found.category.title === "Crab Pot")!;
const freshwater = worms.recipes.find((r) => r.crabpot.water === "freshwater");
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]);
@@ -174,7 +179,7 @@ Deno.test("each juiceable item has a juicing recipe that presses it into its own
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")!;
const juicing = index.find(item("bworld:strawberry"), "uses").find((found) => found.category.title === "Juicing")!;
assertEquals(juicing.category.catalysts, ["bworld:juicer"]);
assertEquals(juicing.recipes.length, 1);
const slots: string[] = [];
@@ -191,6 +196,14 @@ Deno.test("each juiceable item has a juicing recipe that presses it into its own
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);
const pressed = index.find(item("bworld:juicer"), "uses")[0].recipes.map((recipe) => recipe.input);
assert(pressed.includes("bworld:strawberry") && pressed.includes("bworld:melon"));
// juice, whatever it's from, is made by every one of them, and nothing uses it yet
const [making_juice] = index.find(fluid("bworld:juice"), "recipes");
assertEquals(making_juice.category.title, "Juicing");
assertEquals(making_juice.recipes.map((recipe) => recipe.input), pressed);
assertEquals(index.find(fluid("bworld:juice"), "uses"), []);
// a fluid isn't an item of the same id
assertEquals(index.find(item("bworld:juice"), "recipes"), []);
});