Files
bworld/tests/worm_bin_test.ts
T
2026-10-11 23:10:28 -03:00

52 lines
2.1 KiB
TypeScript

// the worm bin: 5 worms every morning into its one slot, for the crab pot's bait
import { assert, assertEquals } from "@std/assert";
import { CYCLE_TICKS } from "$/common/time.ts";
import { ItemStack } from "$/common/inventory.ts";
import { opened_menu, test_game } from "./helpers.ts";
async function setup() {
const t = await test_game("mods");
t.join(1, "alice");
t.game.set_block(0, 99, 0, "bworld:stone");
t.game.set_block(0, 100, 0, "bworld:worm_bin");
t.send(1, { type: "move", x: 0.5, y: 100, z: 2.5, yaw: 0, pitch: 0 });
const data = t.game.world.get_tile(0, 100, 0)!.mod_data as { container: string };
const container = t.game.containers.get(data.container)!;
const next_morning = () => {
t.game.set_time((t.game.world.day + 1) * CYCLE_TICKS - 1);
t.game.tick();
};
return { t, container, next_morning };
}
Deno.test("right clicking a worm bin opens its one output slot", async () => {
const { t } = await setup();
t.take(1);
t.send(1, { type: "use_block", x: 0, y: 100, z: 0, face: "south", hit: [0.5, 0.5, 1] });
const opened = opened_menu(t.take(1));
assertEquals([opened.menu_type, opened.title], ["bworld:worm_bin", "Worm Bin"]);
assertEquals(opened.slots.length, 1 + 36);
assertEquals(opened.slots[0], { x: 79, y: 34, output: true });
});
Deno.test("a worm bin makes 5 worms every morning, up to a full stack", async () => {
const { container, next_morning } = await setup();
assertEquals(container.get_item(0), undefined);
next_morning();
assertEquals(container.get_item(0)?.to_data(), { id: "bworld:worms", count: 5 });
next_morning();
assertEquals(container.get_item(0)?.amount, 10);
container.set_item(0, new ItemStack("bworld:worms", 62));
next_morning();
assertEquals(container.get_item(0)?.amount, 64);
});
Deno.test("breaking a worm bin drops it and its worms", async () => {
const { t, next_morning } = await setup();
next_morning();
t.send(1, { type: "break_block", x: 0, y: 100, z: 0 });
const dropped = t.game.item_entities().map((e) => `${e.item.type_id} ${e.item.amount}`).sort();
assertEquals(dropped, ["bworld:worm_bin 1", "bworld:worms 5"]);
assert(t.game.world.get_block_id(0, 100, 0) === "bworld:air");
});