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
+23
View File
@@ -16,7 +16,9 @@ import {
} from "$/common/inventory.ts";
import {
CRAFTING_RESULT_SLOT,
type MenuFluidSlotInfo,
type MenuSlotInfo,
type MenuTank,
PLAYER_MENU,
PLAYER_MENU_CRAFTING,
PLAYER_MENU_EXTRA,
@@ -44,6 +46,18 @@ export interface MenuSlot {
inventory?: number;
}
// a tank the menu shows, see MenuBuilder.add_fluid_slot
export interface MenuFluidSlot {
x: number;
y: number;
// a fluid container on the cursor only fills from it, it can't be emptied into it
output?: boolean;
// what's in it now
tank(): MenuTank;
// the player clicked it, with whatever their cursor holds
click(): void;
}
export class Menu {
readonly id: number;
readonly type: string;
@@ -51,6 +65,7 @@ export class Menu {
// sent once when it opens
open_data: unknown = null;
slots: MenuSlot[] = [];
fluid_slots: MenuFluidSlot[] = [];
// numbers the screen shows, read every tick and sent when they change, like DataSlot
data = new Map<string, () => number>();
// checked every tick, any false closes it, like stillValid
@@ -152,6 +167,14 @@ export class Menu {
}));
}
fluid_slot_info(): MenuFluidSlotInfo[] {
return this.fluid_slots.map(({ x, y, output }) => ({ x, y, ...(output ? { output: true } : {}) }));
}
tanks(): MenuTank[] {
return this.fluid_slots.map((slot) => slot.tank());
}
// what players are sent, with lore
content(): (ItemData | null)[] {
return this.slots.map((slot) => slot.container.get_item(slot.index)?.to_synced_data() ?? null);