Stonecutter

This commit is contained in:
2026-10-12 20:52:41 -03:00
parent 02cbeda0a0
commit bea5f10a12
20 changed files with 411 additions and 6 deletions
+52
View File
@@ -294,6 +294,58 @@ Deno.test("a smithing result can't be taken once its inputs are gone, even befor
assertEquals(menu_items(t.take(1))[3], null);
});
Deno.test("a stonecutter cuts its input into the recipe picked with a button, one at a time", async () => {
const t = await setup([["bworld:cobblestone", 3], ["bworld:dirt", 1]]);
t.game.set_block(1, 100, 0, "bworld:stonecutter");
const messages = t.take(1);
const cobblestone = slot_of(messages, "bworld:cobblestone");
const dirt = slot_of(messages, "bworld:dirt");
t.send(1, { type: "use_block", x: 1, y: 100, z: 0, face: "top" });
const opened = opened_menu(t.take(1));
const press = (button: number) => t.send(1, { type: "menu_button", menu: opened.id, button });
const cursor = (messages: Msg[]) => messages.filter((m) => m.type === "cursor").at(-1)?.item ?? null;
// nothing to take until a recipe is picked, and a button with no recipe picks nothing. data is only sent when it
// changes
assertEquals(opened.data.selected, -1);
move_to_menu(t, opened, cobblestone, 0);
t.game.tick();
press(99);
t.game.tick();
let latest = t.take(1);
assertEquals(menu_data(latest), undefined);
assertEquals(menu_items(latest)[1], null);
press(0);
t.game.tick();
latest = t.take(1);
assertEquals(menu_data(latest).selected, 0);
const result = menu_items(latest)[1];
assert(result, "the picked recipe's output shows");
// taking it uses up one, and the next is ready a tick later
click(t, opened, 1);
latest = t.take(1);
assertEquals(cursor(latest), result);
assertEquals(menu_items(latest)[0], { id: "bworld:cobblestone", count: 2 });
t.game.tick();
assertEquals(menu_items(t.take(1))[1], result);
// another item forgets the pick, and closing gives back what's in the input
click(t, opened, inventory_slot(opened, 20));
move_to_menu(t, opened, dirt, 0);
t.game.tick();
latest = t.take(1);
assertEquals(menu_data(latest).selected, -1);
assertEquals(menu_items(latest)[1], null);
t.send(1, { type: "close_menu", menu: opened.id });
const inventory = last_container(t.take(1), "inventory").filter((i: Msg) => i);
assertEquals(
inventory.map((i: Msg) => i.id).sort(),
["bworld:cobblestone", "bworld:dirt", result.id].sort(),
);
});
Deno.test("a bucket picks up a water source but not flowing water, and a water bucket puts a source back", async () => {
const t = await setup([["bworld:bucket", 1]]);
const held = () => t.game.players()[0].held_item?.type_id;
+21
View File
@@ -0,0 +1,21 @@
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
// SPDX-License-Identifier: AGPL-3.0-or-later
import { assertEquals } from "@std/assert";
import { ClientMenu } from "$/client/menu.ts";
import { ItemStack } from "$/common/inventory.ts";
Deno.test("a mod's screen reads its menu's slots as copies", () => {
const menu = ClientMenu.opened(1, "testmod:box", "Box", null, [{ x: 0, y: 0 }, { x: 18, y: 0 }]);
const stack = new ItemStack("testmod:gem", 3);
stack.data = { shiny: true };
menu.slots[0].container.set_item(0, stack);
const item = menu.item(0)!;
assertEquals(item, { id: "testmod:gem", count: 3, data: { shiny: true } });
item.count = 1;
(item.data as { shiny: boolean }).shiny = false;
assertEquals(menu.item(0), { id: "testmod:gem", count: 3, data: { shiny: true } });
assertEquals(menu.item(1), undefined);
assertEquals(menu.item(5), undefined);
});