Fluid containers

This commit is contained in:
2026-10-25 15:02:31 -03:00
parent fc27771a92
commit 26b59a1899
24 changed files with 486 additions and 82 deletions
+43
View File
@@ -88,3 +88,46 @@ ctx.fluids.name(birch); // "Birch Log Syrup"
ctx.fluids.color(birch); // "#d9a441"
ctx.fluids.same(birch, { id: "copper_tools:syrup" }); // false, the data is different
```
## Containers
An item with `fluid_container` holds one fluid, full or empty, like a bucket or a bottle:
```json
{
"format_version": 1,
"item": {
"id": "copper_tools:jar",
"texture": "copper_tools:jar",
"max_stack": 16,
"fluid_container": { "capacity": 250, "full_max_stack": 4 },
"layers": [{ "texture": "copper_tools:jar_fluid", "tint": "fluid" }]
}
}
```
| Field | Required | What it does |
| ---------------- | -------- | ---------------------------------------------------------------------- |
| `capacity` | yes | How much a full one holds, in mB. A bucket is 1000. |
| `full_max_stack` | no | How many full ones fit in a slot. The item's `max_stack` when not set. |
A full one's stack data is `{ "fluid": <variant> }`, like
`{ "fluid": { "id": "copper_tools:syrup", "data": { ... } } }`, and one without a `fluid` is empty. It's only ever full
or empty, so there's no amount: a full one holds `capacity`. Stacks only merge when their data is the same, so jars of
maple and birch syrup don't stack, and an empty jar doesn't stack with a full one.
What's in it is drawn with a [layer](../items/index.md#layers) tinted `"fluid"`, which is drawn in the fluid's
[color](#rules) while it's full and not at all while it's empty. Its texture is the size of the item's, opaque only
where the fluid shows, and light gray, since the color multiplies it: white comes out as the fluid's own color. Its
tooltip says what's in it and how much, like "Birch Log Syrup, 250 mB".
A server script fills one with [`player.exchange_held`](../entities/players.md#the-player-api), which turns one of the
held stack into the full one, and `ctx.items.fluid_capacity(id)` says how much it takes:
```ts
const held = player.held_item;
const capacity = held && ctx.items.fluid_capacity(held.id);
if (capacity !== undefined && !held!.data) {
player.exchange_held({ id: held!.id, count: 1, data: { fluid: { id: "copper_tools:syrup" } } });
}
```