Worm bin working with both worms and grubs

This commit is contained in:
2026-10-12 02:22:44 -03:00
parent ff5fb971da
commit df26248f4a
13 changed files with 222 additions and 60 deletions
+3 -3
View File
@@ -3,14 +3,14 @@
"recipe": {
"type": "shaped",
"pattern": [
"CWC",
"I I",
"CDC",
"CCC"
],
"key": {
"I": "#c:ingots/iron",
"C": "#c:ingots/copper",
"D": "bworld:dirt",
"W": "bworld:worms"
"D": "bworld:dirt"
},
"result": {
"id": "bworld:worm_bin",
+8 -1
View File
@@ -10,7 +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:worm_bin", worm_bin_screen);
ctx.ui.register_menu_screen("bworld:smithing_table", smithing_screen);
ctx.ui.register_menu_screen("bworld:fishing_minigame", fishing_minigame_screen);
}
@@ -44,6 +44,13 @@ function furnace_screen(menu: ClientMenu): MenuScreen {
});
}
// its input on the left, an arrow to what it makes on the right
function worm_bin_screen(menu: ClientMenu): MenuScreen {
return container_screen(menu, HEIGHT, (g) => {
g.texture("bworld:arrow_empty", 85, 34, 18, 18);
});
}
function smithing_screen(menu: ClientMenu): MenuScreen {
return container_screen(menu, HEIGHT, (g) => {
g.texture("bworld:arrow_empty", 88, 34, 18, 18);
+37 -10
View File
@@ -39,10 +39,15 @@ function register_hoeable(ctx: ServerContext) {
// existed don't have one yet
function block_container(ctx: ServerContext, block: BlockRef, size: number): Container {
const existing = block.data?.container && ctx.containers.get(block.data.container);
if (existing) {
if (existing && existing.size >= size) {
return existing;
}
// one from before the block had more slots moves into a bigger one, keeping what's in it
const container = ctx.containers.create(size);
if (existing) {
for (let slot = 0; slot < existing.size; slot++) container.set(slot, existing.get(slot));
ctx.containers.delete(existing.id);
}
block.data = { ...block.data, container: container.id };
return container;
}
@@ -329,14 +334,29 @@ 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
// the worm bin breeds bait: one #bworld:worm_binable item in its input makes 5 more of it every morning, into its
// output, which players can only take from. they pile up to a full stack, and the input is never used up. the output
// is slot 0, where worm bins from before the input kept their worms
const WORM_BIN_OUTPUT = 0;
const WORM_BIN_INPUT = 1;
const WORM_BIN_SIZE = 2;
const WORM_BINABLE = "bworld:worm_binable";
const WORMS_A_DAY = 5;
function register_worm_bin(ctx: ServerContext) {
const binable = (id: string) => ctx.tags.has("items", WORM_BINABLE, id);
const menu_type = ctx.menus.register<BlockRef>("bworld:worm_bin", (menu, block) => {
const container = block_container(ctx, block, WORM_BIN_SIZE);
menu.title = "Worm Bin";
menu.add_slot(block_container(ctx, block, 1), 0, { x: 79, y: 34, output_only: true });
menu.add_slot(container, WORM_BIN_INPUT, {
x: 55,
y: 34,
filter: (item) => binable(item.id),
max_count: 1,
icon: "bworld:empty_slot_bait",
});
menu.add_slot(container, WORM_BIN_OUTPUT, { x: 115, y: 34, output_only: true });
menu.add_player_inventory(7, INVENTORY_Y);
menu.still_valid_near(block);
});
@@ -344,7 +364,7 @@ function register_worm_bin(ctx: ServerContext) {
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);
block_container(ctx, block, WORM_BIN_SIZE);
},
on_interact(block, _params, player) {
menu_type.open(player, block);
@@ -354,11 +374,18 @@ function register_worm_bin(ctx: ServerContext) {
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);
const container = block_container(ctx, block, WORM_BIN_SIZE);
const input = container.get(WORM_BIN_INPUT);
if (!input || !binable(input.id)) {
return;
}
// an output of something else, from before the input was swapped, has to be taken out first
const output = container.get(WORM_BIN_OUTPUT);
if (!output) {
container.set(WORM_BIN_OUTPUT, { id: input.id, count: WORMS_A_DAY });
} else if (output.id === input.id) {
output.count = Math.min(ctx.items.max_stack(input.id), output.count + WORMS_A_DAY);
}
},
});
}
@@ -0,0 +1,9 @@
{
"format_version": 1,
"tag": {
"values": [
"bworld:worms",
"bworld:grubs"
]
}
}