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;