Juice sell price

This commit is contained in:
2026-10-26 19:32:46 -03:00
parent e729b92d20
commit e5221ba681
17 changed files with 182 additions and 47 deletions
+27
View File
@@ -4,6 +4,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 { sell_value } from "$/common/inventory.ts";
import { CYCLE_TICKS } from "$/common/time.ts";
import { display_name, get_state_value } from "$/common/utils.ts";
import { container_items, menu_data, menu_items, opened_menu, stone_floor, test_game } from "./helpers.ts";
@@ -131,6 +132,32 @@ Deno.test("a shipping bin sells what's in it every morning for as few coins as i
]);
});
Deno.test("a shipping bin sells a stack for what its data makes it worth, like a bottle by its juice", async () => {
const t = await setup();
const [fruit] = EverythingRegistry.entries<ItemRegistry>("items")
.find(([, item]) => item.components?.["bworld:juiceable"] && item.base_sell_value !== undefined)!;
const full = { fluid: { id: "bworld:juice", data: { item: fruit } } };
t.send(1, { type: "chat", text: `/give bworld:glass_bottle 3 ${JSON.stringify(full)}` });
t.game.set_block(1, 100, 0, "bworld:shipping_bin");
const bottles = slot_of(t.take(1), "bworld:glass_bottle");
t.send(1, { type: "use_block", x: 1, y: 100, z: 0, face: "top" });
const opened = opened_menu(t.take(1));
move_to_menu(t, opened, bottles, 0);
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);
const coin_value = (id: string) => EverythingRegistry.get<ItemRegistry>("items", id)!.base_sell_value!;
const paid = sold.reduce((total: number, coin: Msg) => total + coin.count * coin_value(coin.id), 0);
const value = sell_value("bworld:glass_bottle", full, t.game.mods.fluid_rules)!;
assert(value > 0);
assertEquals(paid, 3 * value);
});
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");