Juices on the mechanical press !

This commit is contained in:
2026-10-31 00:03:03 -03:00
parent 3734f5707a
commit 23d02c5229
11 changed files with 381 additions and 62 deletions
+79 -1
View File
@@ -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);
});