|
|
|
@@ -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);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|