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
+26 -3
View File
@@ -4,7 +4,14 @@
// the client's copy of a menu, like neoforge's client menu: built from what the server sent when it opened, kept up
// to date with what it syncs. clicks go to the server, which decides what they do
import { Container } from "$/common/inventory.ts";
import { CRAFTING_RESULT_SLOT, type MenuSlotInfo, PLAYER_MENU, PLAYER_MENU_EXTRA } from "$/common/protocol.ts";
import {
CRAFTING_RESULT_SLOT,
type MenuFluidSlotInfo,
type MenuSlotInfo,
type MenuTank,
PLAYER_MENU,
PLAYER_MENU_EXTRA,
} from "$/common/protocol.ts";
import type { ClientInventories } from "./inventory.ts";
import type { ItemStack as ApiItemStack } from "$/common/mod_api/client.ts";
@@ -23,6 +30,12 @@ export interface ClientSlot {
max_count?: number;
}
// a tank the server's menu shows, which clicks with a fluid container on the cursor fill it from or empty it into
export interface ClientFluidSlot extends MenuFluidSlotInfo {
// what the server last said is in it
tank: MenuTank;
}
export class ClientMenu {
readonly id: number;
readonly type: string;
@@ -30,6 +43,7 @@ export class ClientMenu {
readonly open_data: unknown;
data: Record<string, number>;
slots: ClientSlot[];
fluid_slots: ClientFluidSlot[] = [];
constructor(
id: number,
@@ -55,9 +69,16 @@ export class ClientMenu {
}
// one the server opened: its slots' items come in menu_content, into a container of its own
static opened(id: number, type: string, title: string, open_data: unknown, slots: MenuSlotInfo[]) {
static opened(
id: number,
type: string,
title: string,
open_data: unknown,
slots: MenuSlotInfo[],
fluid_slots: MenuFluidSlotInfo[] = [],
) {
const items = new Container(slots.length);
return new ClientMenu(
const menu = new ClientMenu(
id,
type,
title,
@@ -72,6 +93,8 @@ export class ClientMenu {
max_count: slot.max_count,
})),
);
menu.fluid_slots = fluid_slots.map((slot) => ({ ...slot, tank: { amount: 0, capacity: 0 } }));
return menu;
}
}