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
+35 -8
View File
@@ -71,6 +71,31 @@ inventory slot `i` is the returned index plus `i`.
editing their client. `on_take` is the place to use up a recipe's inputs, so taking the result and spending the inputs
happen in the same step, like the smithing table does.
### Fluid Slots
`add_fluid_slot(handler, tank, options)` shows a tank of a [fluid handler](../resources/fluids.md#fluid-handlers), like
Modern Industrialization's fluid slots. It returns the slot's index among the menu's fluid slots, which are numbered
apart from its item slots.
```ts
menu.add_fluid_slot(input_tank, 0, { x: 55, y: 34 });
menu.add_fluid_slot(output_tank, 0, { x: 115, y: 34, output_only: true });
```
| Option | Meaning |
| ------------- | ------------------------------------------------------------------------ |
| `x`, `y` | Where its 18 pixel frame goes, in GUI pixels from the screen's top left. |
| `output_only` | Fluid containers only fill from it, they can't be emptied into it. |
The engine draws it, so the screen needs no code for it: a droplet while the tank is empty, and the whole slot in its
fluid while there's any. Its tooltip says what the fluid is, how much of the tank it fills, and what clicking it does.
Clicking it with a fluid container on the cursor fills the container from the tank, or else empties it into the handler,
all on the server. It goes through the handler's `fill` and `drain`, so a handler with more than one tank fills
whichever its own rules say. Give each slot a handler of its own tank when that matters, like the keg's input and
output. One container of a stack on the cursor is used, and what it turns into goes into the inventory while there are
more.
### Shift Clicking
Shift clicking a slot moves its stack to the other part of the menu, like NeoForge's `quickMoveStack`:
@@ -216,13 +241,15 @@ for each player like Minecraft's. Menu 0 is the player's own inventory (slots 0
grid (36 to 45), always there and never opened. The slots mods added to it come after, from 46: `join` lists their
positions, and the `container` message with `"extra"` syncs what's in them, like the inventory's.
| Message | Way | What |
| -------------------- | ------ | ------------------------------------------------------------------------------- |
| `open_menu` | server | The id, type, title, open data, each slot's position, and the data. |
| `menu_content` | server | Every slot's item, by menu slot index, when any changed. |
| `menu_data` | server | All the data, when any changed. |
| `close_menu` | both | The server closed it, or the player did. 0 is their inventory screen. |
| `click`, `drop_item` | client | A menu slot index of the open menu (or menu 0). Ones for other ids are ignored. |
| `menu_button` | client | A button of the open menu. |
| Message | Way | What |
| -------------------- | ------ | -------------------------------------------------------------------------------- |
| `open_menu` | server | The id, type, title, open data, each slot's and fluid slot's position, the data. |
| `menu_content` | server | Every slot's item, by menu slot index, when any changed. |
| `menu_tanks` | server | Every fluid slot's fluid, amount and capacity, when any changed. |
| `menu_data` | server | All the data, when any changed. |
| `close_menu` | both | The server closed it, or the player did. 0 is their inventory screen. |
| `click`, `drop_item` | client | A menu slot index of the open menu (or menu 0). Ones for other ids are ignored. |
| `click_fluid` | client | A fluid slot of the open menu, by its index among the fluid slots. |
| `menu_button` | client | A button of the open menu. |
The code is in `server/game/menu.ts` and `client/menu.ts`.
+3
View File
@@ -229,3 +229,6 @@ on_interact(block, _params, player) {
return tanks !== undefined && ctx.fluids.interact(player, tanks);
},
```
A [menu](../inventories/menus.md#fluid-slots) shows a handler's tanks with `add_fluid_slot`, which players fill and
empty fluid containers on from the cursor.