This commit is contained in:
2026-10-25 16:57:38 -03:00
parent feb1ddd1f7
commit 08df7f1b6b
16 changed files with 306 additions and 19 deletions
+71 -6
View File
@@ -1,12 +1,14 @@
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
// SPDX-License-Identifier: AGPL-3.0-or-later
// juice: one fluid named and colored after the bworld:juiceable item in its data
// juice: one fluid named and colored after the bworld:juiceable item in its data, and the juicer that makes it
import { assert, assertEquals } from "@std/assert";
import { EverythingRegistry, type ItemRegistry } from "$/common/everything_registry.ts";
import type { FluidJson } from "$/common/mod_data.ts";
import { display_name } from "$/common/utils.ts";
import { copy_dir, test_game } from "./helpers.ts";
import { copy_dir, stone_floor, test_game } from "./helpers.ts";
const CLOUDBERRY = "testberries:cloudberry";
// mods/bworld and another mod with a juiceable berry, so there's always one whatever bworld's items have
async function setup() {
@@ -26,18 +28,18 @@ async function setup() {
write("items/cloudberry.json", {
format_version: 1,
item: {
id: "testberries:cloudberry",
id: CLOUDBERRY,
texture: "engine:missing",
components: { "bworld:juiceable": { juice: 100, color: "#e0a030" } },
},
});
const { game } = await test_game(dir);
const t = await test_game(dir);
Deno.removeSync(dir, { recursive: true });
return game.mods.fluid_rules.api();
return { ...t, fluids: t.game.mods.fluid_rules.api() };
}
Deno.test("juice made from any item with bworld:juiceable is named after it, in the component's color", async () => {
const fluids = await setup();
const { fluids } = await setup();
const juiceable = EverythingRegistry.entries<ItemRegistry>("items")
.filter(([, item]) => item.components?.["bworld:juiceable"]);
assert(juiceable.length > 0);
@@ -54,3 +56,66 @@ Deno.test("juice made from any item with bworld:juiceable is named after it, in
plain.color,
]);
});
Deno.test("the juicer takes juiceable items, juices one every 4 presses, and fills empty containers from it", async () => {
const t = await setup();
t.join(1, "alice");
stone_floor(t.game);
const move = (sneaking: boolean) =>
t.send(1, { type: "move", x: 0.5, y: 100, z: 0.5, yaw: 0, pitch: 0, ...(sneaking && { sneaking }) });
move(false);
const player = t.game.players()[0];
const api = t.game.mods.player(player);
api.give_item(CLOUDBERRY, 4);
api.give_item("bworld:glass_bottle", 2);
// selects the slot with id, or an empty one without
const hold = (id?: string) =>
t.send(1, {
type: "select_slot",
slot: player.inventory.to_data().findIndex((item) => (item?.id ?? null) === (id ?? null)),
});
const use = () => t.send(1, { type: "use_block", x: 1, y: 100, z: 0, face: "top" });
const press = (times: number) => {
hold();
move(true);
for (let i = 0; i < times; i++) use();
move(false);
};
// the bottles, empty ones first
const bottles = () =>
player.inventory.to_data().filter((item) => item?.id === "bworld:glass_bottle")
.sort((a, b) => Number(a!.data !== undefined) - Number(b!.data !== undefined));
t.game.set_block(1, 100, 0, "bworld:juicer");
hold(CLOUDBERRY);
use();
assertEquals(player.inventory.to_data().filter((item) => item?.id === CLOUDBERRY), []);
// right clicking with an empty hand without sneaking doesn't press it
hold();
use();
// 2 cloudberries and 3 presses toward the next are 200 mB, not a bottle's 250
press(11);
hold("bworld:glass_bottle");
use();
assertEquals(bottles(), [{ id: "bworld:glass_bottle", count: 2 }]);
// the 3rd makes 300 mB, a bottle and 50 mB left, which isn't another
press(1);
hold("bworld:glass_bottle");
use();
use();
const juice = { id: "bworld:juice", data: { item: CLOUDBERRY } };
assertEquals(bottles(), [
{ id: "bworld:glass_bottle", count: 1 },
{ id: "bworld:glass_bottle", count: 1, data: { fluid: juice } },
]);
// the cloudberry it didn't press yet comes out when it's broken
t.send(1, { type: "break_block", x: 1, y: 100, z: 0 });
const dropped = t.game.item_entities().map((entity) => entity.item.to_data());
assertEquals(dropped.sort((a, b) => a.id.localeCompare(b.id)), [
{ id: "bworld:juicer", count: 1 },
{ id: CLOUDBERRY, count: 1 },
]);
});