This commit is contained in:
2026-10-11 23:10:28 -03:00
parent 935c0df7af
commit fbef1d96d2
8 changed files with 139 additions and 0 deletions
+32
View File
@@ -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": {}
}
}
}
@@ -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
}
}
}
+1
View File
@@ -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);
}
+35
View File
@@ -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<BlockRef>("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<BlockRef>("bworld:smithing_table", (menu, block, player) => {
const container = ctx.containers.create(4);
Binary file not shown.

After

Width:  |  Height:  |  Size: 300 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 268 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 347 B

+51
View File
@@ -0,0 +1,51 @@
// 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");
});