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
+47 -16
View File
@@ -19,6 +19,9 @@ interface ItemStack {
`data` is how one stack differs from another of the same item, like the water left in a watering can or the damage on a
tool. It's saved, and synced to clients as part of the container the stack is in, so client code can read it.
Two stacks of one item only merge into one when their `data` is the same, whatever order its keys are in, in an
inventory or on the ground. No data is the same as `{}`.
Stacks handed to server scripts are live: setting `count` or `data` on one changes the real stack, and a stack counted
down to 0 is gone.
@@ -39,22 +42,24 @@ down to 0 is gone.
## Properties
| Field | Default | Meaning |
| ----------------- | ------------------- | ------------------------------------------------------------------------------------- |
| `id` | required | The item's id. |
| `texture` | required | The texture it's drawn with. Leave it out to [fill in a block's item](#block-items). |
| `name` | from the id | What players see. `copper_tools:copper_ingot` is "Copper Ingot" when not set. |
| `lore` | none | Tooltip text under the name. `\n` starts a new line. |
| `max_stack` | `64`, `1` for tools | How many fit in one slot. |
| `base_sell_value` | none | What one is worth when sold, a whole number of 0 or more. |
| `places` | none | A block it places when used on a block, like seeds. |
| `tool` | none | Makes it a [tool](tools.md). |
| `food` | none | Makes it [edible](food.md). |
| `data_textures` | none | Other textures, picked by the stack's `data`, see below. |
| `model` | none | A [model](../resources/models.md#item-models) it's drawn with instead of its texture. |
| `worn` | none | How it looks worn on a player, see [below](#worn-models). |
| `targets_fluids` | `false` | Players holding it aim at fluids, like buckets and fishing rods. Others aim through. |
| `components` | none | [Item components](#item-components) and their parameters. |
| Field | Default | Meaning |
| ----------------- | ------------------- | -------------------------------------------------------------------------------------- |
| `id` | required | The item's id. |
| `texture` | required | The texture it's drawn with. Leave it out to [fill in a block's item](#block-items). |
| `name` | from the id | What players see. `copper_tools:copper_ingot` is "Copper Ingot" when not set. |
| `lore` | none | Tooltip text under the name. `\n` starts a new line. |
| `max_stack` | `64`, `1` for tools | How many fit in one slot. |
| `base_sell_value` | none | What one is worth when sold, a whole number of 0 or more. |
| `places` | none | A block it places when used on a block, like seeds. |
| `tool` | none | Makes it a [tool](tools.md). |
| `food` | none | Makes it [edible](food.md). |
| `data_textures` | none | Other textures, picked by the stack's `data`, see below. |
| `model` | none | A [model](../resources/models.md#item-models) it's drawn with instead of its texture. |
| `worn` | none | How it looks worn on a player, see [below](#worn-models). |
| `targets_fluids` | `false` | Players holding it aim at fluids, like buckets and fishing rods. Others aim through. |
| `fluid_container` | none | Makes it hold a fluid, like a bucket, see [Fluids](../resources/fluids.md#containers). |
| `layers` | none | Textures drawn over its own, each in a color, see [below](#layers). |
| `components` | none | [Item components](#item-components) and their parameters. |
### Textures From Data
@@ -67,6 +72,29 @@ is out:
A stack whose `data.cast` is truthy uses `bworld:fishing_rod_cast`. When several keys are, the first listed wins.
### Layers
`layers` are textures drawn over the item's own, in order, like the fluid in a bucket or the trim on armor. Each can be
drawn in a color, with `tint`:
```json
"layers": [
{ "texture": "copper_tools:jar_fluid", "tint": "fluid" },
{ "texture": "copper_tools:jar_label", "tint": "#c42d39" }
]
```
| `tint` | The layer's drawn in |
| --------------------------------- | ---------------------------------------------------------------------------------------------------- |
| none | Its own colors. |
| a color, like `"#c42d39"` | That color. |
| `"grass"`, `"foliage"`, `"water"` | That color outside any biome, like a block's [tint](../blocks/index.md#tinting) in its item. |
| `"fluid"` | The color of the fluid a [fluid container](../resources/fluids.md#containers) holds. Not when empty. |
A tint multiplies the texture's colors, so a tinted layer is painted in light grays. A layer whose tint has no color for
a stack, like `"fluid"` on an empty container, isn't drawn. Layers are drawn on the front and back of a flat item, so
they should stay inside the item's own shape, and an item drawn with a `model` can't have them.
### Worn Models
`worn` says how an item looks on a player who wears it, like Bedrock's attachables. A server script says what a player
@@ -218,8 +246,11 @@ const { item, given } = ctx.world.use_item_on({ id: "bworld:cobblestone", count:
ctx.items.exists("bworld:carrot"); // true
ctx.items.ids(); // every item, in load order
ctx.items.max_stack("bworld:wood_pickaxe"); // 1
ctx.items.max_stack(id, data); // the same for a stack with this data, fewer for a full fluid container
ctx.items.fluid_capacity("bworld:bucket"); // how much a fluid container holds full, or undefined
ctx.items.tool("bworld:wood_pickaxe"); // "pickaxe", or undefined for items that aren't tools
ctx.items.sell_value("bworld:copper_coin"); // 1, or undefined for items without a base_sell_value
player.give_item("bworld:carrot", 3); // what doesn't fit drops at their feet
player.exchange_held({ id: "bworld:bucket", count: 1, data }); // one of the held item becomes this
```