Fluid slots and kegs !

This commit is contained in:
2026-10-31 17:35:27 -03:00
parent 65934d34a1
commit 658a6453b7
19 changed files with 494 additions and 34 deletions
+1
View File
@@ -25,6 +25,7 @@
"drops": "bworld:keg",
"interactive": true,
"components": {
"bworld:keg": {}
}
}
}
+4 -3
View File
@@ -29,7 +29,8 @@ 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", worm_bin_screen);
ctx.ui.register_menu_screen("bworld:worm_bin", input_output_screen);
ctx.ui.register_menu_screen("bworld:keg", input_output_screen);
ctx.ui.register_menu_screen("bworld:smithing_table", smithing_screen);
ctx.ui.register_menu_screen("bworld:stonecutter", (menu) => stonecutter_screen(ctx, menu));
ctx.ui.register_menu_screen("bworld:fishing_minigame", fishing_minigame_screen);
@@ -130,8 +131,8 @@ 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 {
// its input on the left, an arrow to what it makes on the right, like the worm bin's slots and the keg's tanks
function input_output_screen(menu: ClientMenu): MenuScreen {
return container_screen(menu, HEIGHT, (g) => {
g.texture("bworld:arrow_empty", 85, 34, 18, 18);
});
+51
View File
@@ -27,6 +27,7 @@ export function setup(ctx: ServerContext) {
register_trapdoor(ctx);
register_buckets(ctx);
register_juicer(ctx);
register_keg(ctx);
register_curios(ctx);
register_effects(ctx);
register_growable_block(ctx);
@@ -925,6 +926,56 @@ function register_juicer(ctx: ServerContext) {
});
}
// the keg holds an input tank and an output tank of KEG_CAPACITY mB each, in its tile data. its screen shows both, and
// its fluid handler, from every side, only fills the input and only drains the output
const KEG_CAPACITY = 4000;
interface KegData {
input?: FluidStack;
output?: FluidStack;
}
function register_keg(ctx: ServerContext) {
const tank = (block: BlockRef, which: keyof KegData) =>
ctx.fluids.tank_handler({
tanks: 1,
capacity: KEG_CAPACITY,
get: () => {
const fluid = (block.data as KegData | undefined)?.[which];
return fluid ? [fluid] : [];
},
set: ([fluid]) => {
block.data = { ...block.data, [which]: fluid } satisfies KegData;
},
});
const menu_type = ctx.menus.register<BlockRef>("bworld:keg", (menu, block) => {
menu.title = "Keg";
menu.add_fluid_slot(tank(block, "input"), 0, { x: 55, y: 34 });
menu.add_fluid_slot(tank(block, "output"), 0, { x: 115, y: 34, output_only: true });
menu.add_player_inventory(7, INVENTORY_Y);
menu.still_valid_near(block);
});
ctx.components.register_block("bworld:keg", {
on_interact(block, _params, player) {
menu_type.open(player, block);
return true;
},
fluid_handler(block) {
const input = tank(block, "input");
const output = tank(block, "output");
return {
tanks: () => 2,
fluid_in_tank: (index) => (index === 0 ? input : output).fluid_in_tank(0),
tank_capacity: () => KEG_CAPACITY,
is_fluid_valid: (index) => index === 0,
fill: (stack, action) => input.fill(stack, action),
drain: (what, action) => output.drain(what, action),
};
},
});
}
interface GrowableBlockParams {
// what grows on top of it
block_id: string;