Juice sell price

This commit is contained in:
2026-10-26 19:32:46 -03:00
parent e729b92d20
commit e5221ba681
17 changed files with 182 additions and 47 deletions
+1 -1
View File
@@ -299,7 +299,7 @@ catch up. If it's further behind than that, it skips the rest and logs a warning
| Component | Params | What it does |
| ----------------------- | --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `bworld:storage` | `rows` | A chest: `rows` × 9 slots, dropped when it's broken. |
| `bworld:shipping_bin` | `rows` | Like `bworld:storage`, and every morning at 06:00 sells what's in it with a `base_sell_value` for coins. |
| `bworld:shipping_bin` | `rows` | Like `bworld:storage`, and every morning at 06:00 sells what's in it that has a sell value for coins. |
| `bworld:furnace` | none | Smelts with `furnace` and `fuel` [recipes](../resources/recipes.md). Needs `lit` and `facing` states, see `blocks/furnace.json`. |
| `bworld:smithing_table` | none | Upgrades tools with `smithing` recipes. |
| `bworld:stonecutter` | none | Cuts one item into another with `bworld:stonecutting` recipes, picked from a list. |
+4
View File
@@ -45,6 +45,10 @@ Juices from different items are different fluids, so they never share a bottle o
(`bworld:glass_bottle`, 250 mB) and buckets (`bworld:bucket`, 1000 mB) hold it, and whatever makes juice reads the
component.
Juice sells for 1.2 times the items it took to make, rounded up, so it's always worth juicing something. A bottle of
juice from an item worth 30 that makes 200 mB took 1.25 of them, and sells for 45. Juice from an item without a
`base_sell_value` can't be sold.
## Hunger and Health
Hunger and health work like Minecraft's:
+1
View File
@@ -250,6 +250,7 @@ ctx.items.max_stack(id, data); // the same for a stack with this data, fewer for
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
ctx.items.sell_value(id, data); // the same for a stack with this data, with a full fluid container's fluid on top
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
+31 -17
View File
@@ -17,17 +17,19 @@ here has no block, so it can't be placed.
"id": "copper_tools:maple_syrup",
"name": "Maple Syrup",
"color": "#a0522d",
"texture": "bworld:water_still"
"texture": "bworld:water_still",
"base_sell_value": 40
}
}
```
| Field | Required | What it does |
| --------- | -------- | ----------------------------------------------------------------------------------------------------------------------------- |
| `id` | yes | The fluid's id, in the mod's [namespace](../concepts/registries.md#identifiers). |
| `name` | no | What players see. `copper_tools:maple_syrup` is "Maple Syrup" when not set, like an item's. |
| `color` | yes | Its color, like `"#a0522d"`, for whatever shows it. |
| `texture` | no | What a [box of it](../blocks/visuals.md#fluids) is drawn with, tinted by its color, like NeoForge's still texture. See below. |
| Field | Required | What it does |
| ----------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------- |
| `id` | yes | The fluid's id, in the mod's [namespace](../concepts/registries.md#identifiers). |
| `name` | no | What players see. `copper_tools:maple_syrup` is "Maple Syrup" when not set, like an item's. |
| `color` | yes | Its color, like `"#a0522d"`, for whatever shows it. |
| `texture` | no | What a [box of it](../blocks/visuals.md#fluids) is drawn with, tinted by its color, like NeoForge's still texture. See below. |
| `base_sell_value` | no | What 1000 mB is worth sold in a [container](#containers), a whole number of 0 or more. None when not set. |
Like a fluid container's layer, the texture is multiplied by the fluid's color, so a light gray one comes out in the
fluid's own color, and its alpha is how much shows through. The base game's `bworld:water_still` is such a texture,
@@ -46,8 +48,8 @@ a tank.
## Rules
A fluid's name and color can depend on its data. The mod's [shared script](../concepts/sides.md#shared-scripts) gives
one of its fluids rules for that, like NeoForge's `FluidType.getDescription` and `FluidTintSource.colorAsStack`:
A fluid's name, color and value can depend on its data. The mod's [shared script](../concepts/sides.md#shared-scripts)
gives one of its fluids rules for that, like NeoForge's `FluidType.getDescription` and `FluidTintSource.colorAsStack`:
```ts
import type { SharedContext } from "bworld/shared";
@@ -66,22 +68,29 @@ export function setup(ctx: SharedContext) {
const { tree } = (data ?? {}) as SyrupData;
return tree === "bworld:birch_log" ? "#d9a441" : undefined;
},
// worth twice the logs it takes to make, 4 to a bucket
sell_value(data) {
const { tree } = (data ?? {}) as SyrupData;
const value = tree && ctx.items.sell_value(tree);
return value ? value * 4 * 2 : undefined;
},
});
}
```
| Rule | Returns |
| ------------- | -------------------------------------------------------- |
| `name(data)` | What players see, or `undefined` for the JSON's name. |
| `color(data)` | A color like `"#d9a441"`, or `undefined` for the JSON's. |
| Rule | Returns |
| ------------------ | ------------------------------------------------------------------------------------------------------- |
| `name(data)` | What players see, or `undefined` for the JSON's name. |
| `color(data)` | A color like `"#d9a441"`, or `undefined` for the JSON's. |
| `sell_value(data)` | What 1000 mB is worth, 0 or more and not always whole, or `undefined` for the JSON's `base_sell_value`. |
`data` is the variant's, `undefined` when it has none, and mustn't be changed. A rule that throws, or returns something
that isn't a name or a color, is logged and the JSON's is used. A fluid has one set of rules, from its own mod, and they
can only be registered during `setup`.
that isn't a name, a color or a value, is logged and the JSON's is used. A fluid has one set of rules, from its own mod,
and they can only be registered during `setup`.
The rules are in the shared script because both sides need them: the server for tooltips, and clients to draw the fluid.
Shared scripts have `ctx.items.exists(id)`, `ctx.items.name(id)` and `ctx.items.components(id)` for rules that read an
item, like syrup named after its tree.
Shared scripts have `ctx.items.exists(id)`, `ctx.items.name(id)`, `ctx.items.components(id)` and
`ctx.items.sell_value(id)` for rules that read an item, like syrup named after its tree.
## Using Fluids
@@ -127,6 +136,11 @@ What's in it is drawn with a [layer](../items/index.md#layers) tinted `"fluid"`,
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 full one sells for its own `base_sell_value` and what its fluid is worth on top: the fluid's value for 1000 mB times
how much it holds, rounded up to a whole number. A jar of maple syrup worth 40 a bucket sells for 10, and the jar's own
value when it has one. It can't be sold if neither has a value. Server scripts get this from
`ctx.items.sell_value(id, data)`, which the base game's shipping bin sells by, and tooltips show it.
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: