From fbef1d96d29a84509702c643a46abbe4b85adc8a Mon Sep 17 00:00:00 2001 From: Paula Date: Sun, 11 Oct 2026 23:10:28 -0300 Subject: [PATCH] Worm bin --- mods/bworld/blocks/worm_bin.json | 32 +++++++++++++ mods/bworld/recipes/crafting_worm_bin.json | 20 ++++++++ mods/bworld/scripts/client.ts | 1 + mods/bworld/scripts/server.ts | 35 ++++++++++++++ mods/bworld/textures/worm_bin_front.png | Bin 0 -> 300 bytes mods/bworld/textures/worm_bin_side.png | Bin 0 -> 268 bytes mods/bworld/textures/worm_bin_top.png | Bin 0 -> 347 bytes tests/worm_bin_test.ts | 51 +++++++++++++++++++++ 8 files changed, 139 insertions(+) create mode 100644 mods/bworld/blocks/worm_bin.json create mode 100644 mods/bworld/recipes/crafting_worm_bin.json create mode 100644 mods/bworld/textures/worm_bin_front.png create mode 100644 mods/bworld/textures/worm_bin_side.png create mode 100644 mods/bworld/textures/worm_bin_top.png create mode 100644 tests/worm_bin_test.ts diff --git a/mods/bworld/blocks/worm_bin.json b/mods/bworld/blocks/worm_bin.json new file mode 100644 index 0000000..ae1cd05 --- /dev/null +++ b/mods/bworld/blocks/worm_bin.json @@ -0,0 +1,32 @@ +{ + "format_version": 1, + "block": { + "id": "bworld:worm_bin", + "name": "Worm Bin", + "textures": { + "front": "bworld:worm_bin_front", + "side": "bworld:worm_bin_side", + "top": "bworld:worm_bin_top" + }, + "states": [ + { + "name": "facing", + "bits": 2, + "default": 0 + } + ], + "variants": { + "facing=1": { "y": 90 }, + "facing=2": { "y": 180 }, + "facing=3": { "y": 270 } + }, + "mining": { + "toughness": 2 + }, + "drops": "bworld:worm_bin", + "interactive": true, + "components": { + "bworld:worm_bin": {} + } + } +} diff --git a/mods/bworld/recipes/crafting_worm_bin.json b/mods/bworld/recipes/crafting_worm_bin.json new file mode 100644 index 0000000..dee6509 --- /dev/null +++ b/mods/bworld/recipes/crafting_worm_bin.json @@ -0,0 +1,20 @@ +{ + "format_version": 1, + "recipe": { + "type": "shaped", + "pattern": [ + "CWC", + "CDC", + "CCC" + ], + "key": { + "C": "#c:ingots/copper", + "D": "bworld:dirt", + "W": "bworld:worms" + }, + "result": { + "id": "bworld:worm_bin", + "count": 1 + } + } +} diff --git a/mods/bworld/scripts/client.ts b/mods/bworld/scripts/client.ts index 47bedcd..e0c0f70 100644 --- a/mods/bworld/scripts/client.ts +++ b/mods/bworld/scripts/client.ts @@ -10,6 +10,7 @@ export function setup(ctx: ClientContext) { ctx.ui.register_menu_screen("bworld:storage", chest_screen); ctx.ui.register_menu_screen("bworld:furnace", furnace_screen); ctx.ui.register_menu_screen("bworld:crabpot", (menu) => container_screen(menu, HEIGHT)); + ctx.ui.register_menu_screen("bworld:worm_bin", (menu) => container_screen(menu, HEIGHT)); ctx.ui.register_menu_screen("bworld:smithing_table", smithing_screen); ctx.ui.register_menu_screen("bworld:fishing_minigame", fishing_minigame_screen); } diff --git a/mods/bworld/scripts/server.ts b/mods/bworld/scripts/server.ts index 75d0320..640cc3d 100644 --- a/mods/bworld/scripts/server.ts +++ b/mods/bworld/scripts/server.ts @@ -10,6 +10,7 @@ export function setup(ctx: ServerContext) { register_shipping_bin(ctx, storage_menu); register_furnace(ctx); register_crabpot(ctx); + register_worm_bin(ctx); register_smithing_table(ctx); register_farming(ctx); register_fishing(ctx); @@ -328,6 +329,40 @@ function register_crabpot(ctx: ServerContext) { }); } +// the worm bin makes worms every morning, for the crab pot's bait, into its one slot, which players can only take from. +// they pile up to a full stack +const WORMS_A_DAY = 5; + +function register_worm_bin(ctx: ServerContext) { + const menu_type = ctx.menus.register("bworld:worm_bin", (menu, block) => { + menu.title = "Worm Bin"; + menu.add_slot(block_container(ctx, block, 1), 0, { x: 79, y: 34, output_only: true }); + menu.add_player_inventory(7, INVENTORY_Y); + menu.still_valid_near(block); + }); + + ctx.components.register_block("bworld:worm_bin", { + // its container is its tile data, so its mornings come anywhere in the world, like a crop's + on_create(block) { + block_container(ctx, block, 1); + }, + on_interact(block, _params, player) { + menu_type.open(player, block); + return true; + }, + on_break(block) { + drop_contents(ctx, block); + }, + on_new_day(block) { + const container = block_container(ctx, block, 1); + const worms = container.get(0); + const max = ctx.items.max_stack(CRABPOT_WORMS); + if (!worms) container.set(0, { id: CRABPOT_WORMS, count: WORMS_A_DAY }); + else if (worms.id === CRABPOT_WORMS) worms.count = Math.min(max, worms.count + WORMS_A_DAY); + }, + }); +} + function register_smithing_table(ctx: ServerContext) { const menu_type = ctx.menus.register("bworld:smithing_table", (menu, block, player) => { const container = ctx.containers.create(4); diff --git a/mods/bworld/textures/worm_bin_front.png b/mods/bworld/textures/worm_bin_front.png new file mode 100644 index 0000000000000000000000000000000000000000..ab5a1c77675c64c223c1944821417841d71bb6c7 GIT binary patch literal 300 zcmV+{0n`48P) zJqp4=6ofxR%2kLKf*8;!+gMl$fz%$rQ+Os16cB6`Az&4-Q_)foE#k&xcjMncn%Ots zBg3nWXY$Td-LTKM>P?3LxB&IGz>nnDVSwZ2Ky%c>(H}1RQ~uec`vw4@(eY?>yvpqg za@-tDz`J1aT|u0BTUZCf?Ts`}NaKWXd#haH0!D#poIoV;$^7NhE6yp1^K1LM@(zma zUe{-1(B_o@|EM`?WgX}m%qQ#?E5p;nKpAk^pYn3_fK4J0IBA>!pN~f^uwJ5qdupzwH}gEM#oD;onQB*ub>_FCxTFydp4U&lQD`G?)@ z%@)apJA-i_fXO^TvRiGMc$CHzSq?yy#u(XXsmrSMJ)Dl3_aeMf>SPzKO_)jZn z7w?YpNx)ttiM9GksL1li3fe_oRxP1d4vkDm5&3|0v%~=CHT3nC;#MF^V*svY8B2E{ S9Mii100001w5fXj(ui=;?VEKaE)WK!rYbjd|XugQyW$>v_nBsl0$#Ly-LO3+}MwbUV= zn0S)fzSH4+&-;Eqt>M^Svq4w4H^uw;?op}hbzoVaFCPH32c3c`2epP{do2qR-lX=R zQ@llApzUIooahSxviB@sVOw)qGDNR4m&g3u9boRx05~0;{T@*&jS^n(p8zn-yvuTt z0nocX=iub1VCU{k4G2A70cCLL`B+Z%UkNZwLF~Q}9`9BD_v01D<)N~c60lrk^hOtr z6DR>`lvH5Lv43vhD>twl`~L}=z&fQ-g7)RdTft4z0D{SMXJas#5_&$G+)svdAA&}c ttd$$;kRQn~1! { + 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"); +});