Shipping bin block

This commit is contained in:
2026-10-04 16:18:03 -03:00
parent 6a6abae0d5
commit 4cdf48c9fb
8 changed files with 147 additions and 3 deletions
+34
View File
@@ -1,6 +1,7 @@
// the base game's block and item behavior: hoeing, chests, furnaces, crops and the watering can
import { assert, assertEquals } from "@std/assert";
import { BlockRegistry, EverythingRegistry, ItemRegistry } from "$/common/everything_registry.ts";
import { CYCLE_TICKS } from "$/common/time.ts";
import { display_name, get_state_value } from "$/common/utils.ts";
import { menu_data, menu_items, opened_menu, test_game } from "./helpers.ts";
@@ -99,6 +100,39 @@ Deno.test("a chest keeps items, shows them to everyone, and drops them when brok
);
});
Deno.test("a shipping bin sells what's in it every morning for as few coins as it can", async () => {
// oak planks sell for 2, so 70 of them and 5 copper are 145: 2 brass, 2 nickel and 1 copper
const t = await setup([["bworld:oak_planks", 64], ["bworld:oak_planks", 6], ["bworld:copper_coin", 5]]);
assertEquals(EverythingRegistry.get<ItemRegistry>("items", "bworld:oak_planks")?.base_sell_value, 2);
t.game.set_block(1, 100, 0, "bworld:shipping_bin");
const messages = t.take(1);
const inventory = last_container(messages, "inventory");
const planks = inventory.flatMap((item: Msg, slot: number) => item?.id === "bworld:oak_planks" ? [slot] : []);
const copper = slot_of(messages, "bworld:copper_coin");
t.send(1, { type: "use_block", x: 1, y: 100, z: 0, face: "top" });
const opened = opened_menu(t.take(1));
assertEquals(opened.menu_type, "bworld:storage");
assertEquals(opened.title, "Shipping Bin");
assertEquals(opened.slots.length, 27 + 36);
move_to_menu(t, opened, planks[0], 0);
move_to_menu(t, opened, planks[1], 1);
move_to_menu(t, opened, copper, 2);
t.send(1, { type: "close_menu", menu: opened.id });
t.take(1);
t.game.set_time((t.game.world.day + 1) * CYCLE_TICKS - 1);
t.game.tick();
t.send(1, { type: "use_block", x: 1, y: 100, z: 0, face: "top" });
const sold = menu_items(t.take(1)).slice(0, 27).filter((item: Msg) => item);
assertEquals(sold, [
{ id: "bworld:brass_coin", count: 2 },
{ id: "bworld:nickel_coin", count: 2 },
{ id: "bworld:copper_coin", count: 1 },
]);
});
Deno.test("a furnace burns fuel to smelt, shows its progress, and only lets the result be taken", async () => {
const t = await setup([["bworld:iron_ore", 2], ["bworld:coal", 1]]);
t.game.set_block(1, 100, 0, "bworld:furnace");