Juices on the mechanical press !
This commit is contained in:
@@ -7,6 +7,7 @@ import { assert, assertEquals } from "@std/assert";
|
||||
import { ItemStack } from "$/common/inventory.ts";
|
||||
import type { ItemStack as Stack } from "bworld/shared";
|
||||
import {
|
||||
apply_basin_recipe,
|
||||
BASIN_SLOTS,
|
||||
BASIN_TANK_CAPACITY,
|
||||
BASIN_TANKS,
|
||||
@@ -56,6 +57,33 @@ Deno.test("a basin keeps each fluid in a tank of its own, and drains the first",
|
||||
assertEquals(drained.tanks.length, BASIN_TANKS - 1);
|
||||
});
|
||||
|
||||
Deno.test("a basin recipe takes an item for each ingredient, and puts what it makes where recipes don't take it", () => {
|
||||
const max = () => 64;
|
||||
const basin = {
|
||||
items: [{ id: "a:flint", count: 3 }, { id: "a:gravel", count: 1 }],
|
||||
outputs: [{ id: "a:andesite", count: 1 }],
|
||||
tanks: [],
|
||||
};
|
||||
const andesite = {
|
||||
ingredients: [["a:flint"], ["a:flint"], ["a:gravel", "a:sand"]],
|
||||
results: [{ id: "a:andesite", count: 1 }],
|
||||
fluid_results: [{ fluid: juice("a:stone"), amount: 10 }],
|
||||
};
|
||||
const made = apply_basin_recipe(basin, andesite, max, same)!;
|
||||
assertEquals(made.items, [{ id: "a:flint", count: 1 }]);
|
||||
assertEquals(made.outputs, [{ id: "a:andesite", count: 2 }]);
|
||||
assertEquals(made.tanks, [{ fluid: juice("a:stone"), amount: 10 }]);
|
||||
// what it made isn't taken again, and the one flint left isn't enough
|
||||
assertEquals(apply_basin_recipe(made, andesite, max, same), undefined);
|
||||
assertEquals(
|
||||
apply_basin_recipe({ ...basin, outputs: [] }, { ...andesite, ingredients: [["a:andesite"]] }, max, same),
|
||||
undefined,
|
||||
);
|
||||
// nothing is made when what it makes doesn't all fit
|
||||
const full = { ...basin, tanks: [{ fluid: juice("a:stone"), amount: BASIN_TANK_CAPACITY }] };
|
||||
assertEquals(apply_basin_recipe(full, andesite, max, same), undefined);
|
||||
});
|
||||
|
||||
// a basin at 0 100 0, and what's in it
|
||||
async function basin() {
|
||||
const t = await setup();
|
||||
|
||||
@@ -2,9 +2,12 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// the mechanical press: turned, it slams down on items lying on the ground under it and presses them with create's
|
||||
// pressing recipes, one at a time, and it only ticks while it turns
|
||||
// pressing recipes, one at a time, or with a basin under it makes compacting recipes in that, and it only ticks while
|
||||
// it turns
|
||||
import { assert, assertEquals } from "@std/assert";
|
||||
import { ItemStack } from "$/common/inventory.ts";
|
||||
import { BASIN_TANK_CAPACITY } from "$/mods/create/scripts/processing/basin.ts";
|
||||
import { BASIN_TRAVEL, PRESS_AT } from "$/mods/create/scripts/processing/press.ts";
|
||||
import { FACING, setup, visual_for } from "./helpers.ts";
|
||||
|
||||
// a press at 1 101 0 along x, turned by a crank on its west side, with the floor two blocks under it
|
||||
@@ -113,3 +116,78 @@ Deno.test("a press's head comes down to press halfway through its cycle and goes
|
||||
visual.on_frame!(70);
|
||||
assertEquals(down(), 0);
|
||||
});
|
||||
|
||||
// a press at 1 102 0 turned by a crank, over a basin at 1 100 0 with a block between them, and what's in the basin
|
||||
async function press_over_basin() {
|
||||
const t = await setup();
|
||||
t.place(1, 100, 0, "create:basin", "facing", 4);
|
||||
t.place(0, 102, 0, "create:hand_crank", "facing", FACING.west);
|
||||
t.place(1, 102, 0, "create:mechanical_press", "facing", FACING.east);
|
||||
const crank = (ticks: number) => {
|
||||
for (let i = 0; i < ticks; i += 4) {
|
||||
t.use(0, 102, 0);
|
||||
t.ticks(4);
|
||||
}
|
||||
};
|
||||
const client_data = (field: string) => t.game.world.get_tile(1, 100, 0)?.client_data?.[field];
|
||||
const tanks = () => client_data("tanks") as { fluid: unknown; amount: number }[] | undefined ?? [];
|
||||
const count = (id: string) =>
|
||||
(client_data("items") as { id: string; count: number }[] | undefined ?? [])
|
||||
.find((item) => item.id === id)?.count ?? 0;
|
||||
const drop = (id: string, count: number) => t.game.spawn_item(1.5, 101.5, 0.5, new ItemStack(id, count));
|
||||
// the compacting recipe for id's juice, which bworld makes for every juicing recipe while create is there
|
||||
const juice_of = (id: string) => {
|
||||
const recipe = t.game.recipes.by_type.get("create:compacting")!
|
||||
.find((recipe) => (recipe.ingredients as string[])[0] === id)!;
|
||||
return (recipe.results as { fluid: unknown; amount: number }[])[0];
|
||||
};
|
||||
return { ...t, crank, tanks, count, drop, juice_of };
|
||||
}
|
||||
|
||||
Deno.test("a press over a basin makes compacting recipes in it, like juice out of carrots, one each time", async () => {
|
||||
const t = await press_over_basin();
|
||||
t.drop("bworld:carrot", 3);
|
||||
// with something no compacting recipe takes beside them, which it leaves
|
||||
t.drop("bworld:iron_ingot", 1);
|
||||
t.ticks(20);
|
||||
assertEquals([t.count("bworld:carrot"), t.count("bworld:iron_ingot")], [3, 1]);
|
||||
assertEquals(t.tanks(), []);
|
||||
|
||||
for (let i = 0; i < 200 && t.count("bworld:carrot") === 3; i++) t.crank(4);
|
||||
assertEquals(t.count("bworld:carrot"), 2);
|
||||
const juice = t.juice_of("bworld:carrot");
|
||||
assertEquals(t.tanks(), [juice]);
|
||||
|
||||
t.crank(600);
|
||||
assertEquals([t.count("bworld:carrot"), t.count("bworld:iron_ingot")], [0, 1]);
|
||||
assertEquals(t.tanks(), [{ ...juice, amount: 3 * juice.amount }]);
|
||||
// it presses into the basin, not on what's around it, so the iron isn't pressed into a sheet
|
||||
assertEquals(t.game.item_entities().length, 0);
|
||||
});
|
||||
|
||||
Deno.test("a press over a basin stops once what a recipe makes won't fit", async () => {
|
||||
const t = await press_over_basin();
|
||||
const per_melon = t.juice_of("bworld:melon").amount;
|
||||
const fit = Math.floor(BASIN_TANK_CAPACITY / per_melon);
|
||||
t.drop("bworld:melon", fit + 1);
|
||||
t.ticks(20);
|
||||
t.crank(400 * (fit + 1));
|
||||
assertEquals(t.count("bworld:melon"), 1);
|
||||
// turning on, it doesn't come down on the one left
|
||||
t.crank(100);
|
||||
assertEquals(t.game.world.get_tile(1, 102, 0)?.client_data?.press, undefined);
|
||||
});
|
||||
|
||||
Deno.test("a press's head comes further down into a basin", async () => {
|
||||
const { visual, transforms, data } = await visual_for("create:mechanical_press", { facing: FACING.east }, {
|
||||
speed: 32,
|
||||
press: { steps: PRESS_AT, rate: 0, basin: true },
|
||||
});
|
||||
const down = () => -[...transforms].find(([model]) => model.includes("head"))![1][13];
|
||||
visual.on_frame!(0);
|
||||
assertEquals(down(), BASIN_TRAVEL);
|
||||
data.press = { steps: PRESS_AT, rate: 0 };
|
||||
visual.update!();
|
||||
visual.on_frame!(1);
|
||||
assertEquals(down(), 1);
|
||||
});
|
||||
|
||||
@@ -6,7 +6,12 @@ import { assert, assertEquals, assertThrows } from "@std/assert";
|
||||
import { EverythingRegistry } from "$/common/everything_registry.ts";
|
||||
import { tag_api } from "$/common/tags.ts";
|
||||
import type { ClientContext } from "$/common/mod_api/client.ts";
|
||||
import { parse_processing, PRESSING, processing_recipes } from "$/mods/create/scripts/recipes/processing.ts";
|
||||
import {
|
||||
COMPACTING,
|
||||
parse_processing,
|
||||
PRESSING,
|
||||
processing_recipes,
|
||||
} from "$/mods/create/scripts/recipes/processing.ts";
|
||||
import { inputs, outputs } from "$/mods/recipe_viewer/scripts/recipes.ts";
|
||||
import { RecipeIndex } from "$/mods/recipe_viewer/scripts/recipes_screen.ts";
|
||||
import { test_game } from "../helpers.ts";
|
||||
@@ -14,6 +19,7 @@ import { test_game } from "../helpers.ts";
|
||||
const lookup = () => ({
|
||||
expand: (choice: string | string[]) => tag_api().expand(choice),
|
||||
item_exists: (id: string) => EverythingRegistry.get("items", id) !== undefined,
|
||||
fluid_exists: (id: string) => EverythingRegistry.get("fluids", id) !== undefined,
|
||||
});
|
||||
|
||||
Deno.test("create's pressing recipes are read with every item each ingredient stands for", async () => {
|
||||
@@ -52,6 +58,31 @@ Deno.test("a pressing recipe that a press couldn't make says what's wrong with i
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test("compacting recipes can make fluids as well as items, and pressing ones can't", async () => {
|
||||
await test_game("mods");
|
||||
const juice = { fluid: { id: "bworld:juice", data: { item: "bworld:carrot" } }, amount: 200 };
|
||||
const parsed = parse_processing({ ingredients: ["bworld:carrot"], results: [juice] }, COMPACTING, lookup());
|
||||
assertEquals(parsed, { ingredients: [["bworld:carrot"]], results: [], fluid_results: [juice] });
|
||||
const problems = (json: unknown, type = COMPACTING) => {
|
||||
const parsed = parse_processing(json, type, lookup());
|
||||
return "problems" in parsed ? parsed.problems : [];
|
||||
};
|
||||
assertEquals(problems({ ingredients: ["bworld:carrot"], results: [juice] }, PRESSING).length, 1);
|
||||
assertEquals(problems({ ingredients: ["bworld:carrot"], results: [juice, juice, juice] }).length, 1);
|
||||
assertEquals(
|
||||
problems({ ingredients: ["bworld:carrot"], results: [{ ...juice, fluid: { id: "a:none" } }] }).length,
|
||||
1,
|
||||
);
|
||||
assertEquals(problems({ ingredients: ["bworld:carrot"], results: [{ ...juice, amount: 0 }] }).length, 1);
|
||||
// fluids going in aren't supported yet
|
||||
assertEquals(
|
||||
problems({ ingredients: [{ fluid: "bworld:juice", amount: 10 }], results: [{ id: "bworld:carrot" }] }),
|
||||
[
|
||||
"fluid ingredients aren't supported yet",
|
||||
],
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test("the recipe viewer shows pressing recipes under the press, with what they take and make", async () => {
|
||||
const { game } = await test_game("mods");
|
||||
const pressing = game.recipes.all.filter((recipe) => recipe.type === PRESSING.id);
|
||||
@@ -70,6 +101,21 @@ Deno.test("the recipe viewer shows pressing recipes under the press, with what t
|
||||
blocks: { exists: () => false, components: () => ({}) },
|
||||
loot: { table: () => undefined },
|
||||
} as unknown as ClientContext;
|
||||
const category = new RecipeIndex(ctx).categories.find((category) => category.type === PRESSING.id);
|
||||
const index = new RecipeIndex(ctx);
|
||||
const category = index.categories.find((category) => category.type === PRESSING.id);
|
||||
assertEquals([category?.title, category?.catalysts], ["Pressing", ["create:mechanical_press"]]);
|
||||
|
||||
// juice is made by compacting too, by the press over a basin, and drawn as a fluid
|
||||
const compacting = index.find({ kind: "fluid", id: "bworld:juice" }, "recipes")
|
||||
.find((found) => found.category.type === COMPACTING.id)!;
|
||||
assertEquals(compacting.category.catalysts, ["create:mechanical_press", "create:basin"]);
|
||||
const fluids: unknown[] = [];
|
||||
const ignore = () => {};
|
||||
compacting.category.draw(compacting.recipes[0], {
|
||||
slot: ignore,
|
||||
texture: ignore,
|
||||
text: ignore,
|
||||
fluid: (fluid) => fluids.push(fluid),
|
||||
});
|
||||
assertEquals(fluids.length, 1);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user