Single module modding

This commit is contained in:
2026-11-14 12:18:41 -03:00
parent 605008f584
commit 313098892e
134 changed files with 919 additions and 924 deletions
+1 -1
View File
@@ -63,7 +63,7 @@ Hunger and health work like Minecraft's:
- A full stomach heals: quickly while there's saturation, slowly with at least 18 hunger.
- At 0 hunger, players lose health every 4 seconds, down to half a heart.
Server scripts can feed players directly, and read and change their hunger. See [Players](../entities/players.md).
The server phase can feed players directly, and read and change their hunger. See [Players](../entities/players.md).
```ts
player.feed(4, 0.3); // like eating 4 nutrition with a 0.3 modifier
+5 -5
View File
@@ -12,7 +12,7 @@ Like blocks, each kind of item is defined once. What players hold are **item sta
interface ItemStack {
readonly id: string;
count: number;
data?: unknown; // any JSON value, set by server scripts
data?: unknown; // any JSON value, set by server phases
}
```
@@ -22,7 +22,7 @@ tool. It's saved, and synced to clients as part of the container the stack is in
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
Stacks handed to server phases are live: setting `count` or `data` on one changes the real stack, and a stack counted
down to 0 is gone.
## A Basic Item
@@ -97,7 +97,7 @@ they should stay inside the item's own shape, and an item drawn with a `model` c
### 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
`worn` says how an item looks on a player who wears it, like Bedrock's attachables. The server phase says what a player
wears with [`set_worn`](../entities/players.md#worn-items), and every client draws it on them. There's no third person
view, so players see what others wear, and what's on their own right arm in first person. Artifacts' power glove and
feral claws (`mods/artifacts`) and the base game's giant chestplate are examples.
@@ -154,7 +154,7 @@ load the mod.
## Item Components
Like [block components](../blocks/components.md), item components give items behavior. The server script registers them:
Like [block components](../blocks/components.md), item components give items behavior. The server phase registers them:
```ts
ctx.components.register_item<{ max_water: number }>("bworld:watering_can", {
@@ -257,6 +257,6 @@ 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
```
Client and shared scripts have `ctx.items.sell_value(id, data)` too, worked out the same way with that side's
Client and shared phases have `ctx.items.sell_value(id, data)` too, worked out the same way with that side's
[fluid rules](../resources/fluids.md#rules), so a client can show what a full bottle of juice is worth, like the base
game's [tooltip line](../gui/index.md#item-tooltips) does.
+2 -2
View File
@@ -38,7 +38,7 @@ The base game's tiers:
| `2` | iron | 7 | everything so far |
Tool types don't have to be the base game's. A mod can add a `"sickle"` type and blocks with `"tool": "sickle"`, and a
server script can check a held item's type with `ctx.items.tool(id)`, like the base game's `bworld:hoeable` does for
server phase can check a held item's type with `ctx.items.tool(id)`, like the base game's `bworld:hoeable` does for
hoes. The base game's watering cans are tools of type `"watering_can"` that no block is mined with: they come in the
same five tiers with the same durability, and each holds more water than the last (16, 24, 32, 48 and 64), set by its
`bworld:watering_can` component.
@@ -52,5 +52,5 @@ dropping.
The damage a tool has taken is kept in its stack's `data.damage`, and a worn tool shows a bar under it in its slot,
going from green to red as it wears down. Upgrading a tool at the smithing table keeps its data, damage included.
A server script wears a tool down with `ctx.items.damage(item, amount)`, which adds to the stack's `data.damage` and
The server phase wears a tool down with `ctx.items.damage(item, amount)`, which adds to the stack's `data.damage` and
returns true when that used it up. It does nothing to items that aren't tools. The base game's death drops use it.