Update modding docs
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
# Food
|
||||
|
||||
An item with a `food` property can be eaten. Players eat by right clicking while holding it, when they're hungry.
|
||||
|
||||
```json
|
||||
{
|
||||
"format_version": 1,
|
||||
"item": {
|
||||
"id": "farmersdelight:cooked_rice",
|
||||
"texture": "farmersdelight:cooked_rice",
|
||||
"max_stack": 16,
|
||||
"food": { "nutrition": 6, "saturation_modifier": 0.4, "returns": "bworld:bowl" }
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Default | Meaning |
|
||||
| --------------------- | -------- | ------------------------------------------------------------------------------------------ |
|
||||
| `nutrition` | required | Hunger points it restores, out of 20. A whole number. |
|
||||
| `saturation_modifier` | required | Like Minecraft's: the saturation it gives is `nutrition × modifier × 2`. Bread's is `0.6`. |
|
||||
| `always_edible` | `false` | Can be eaten even when not hungry. |
|
||||
| `returns` | none | An item left in the hand after eating, like a bowl after soup. |
|
||||
|
||||
Food that places a block, like potatoes with `places`, is planted when clicked somewhere it can go and eaten otherwise.
|
||||
|
||||
## Hunger and Health
|
||||
|
||||
Hunger and health work like Minecraft's:
|
||||
|
||||
- Sprinting, swimming, jumping, breaking blocks, taking damage and healing add **exhaustion**. Every 4 exhaustion costs
|
||||
a point of saturation, or of hunger once saturation is gone.
|
||||
- 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).
|
||||
|
||||
```ts
|
||||
player.feed(4, 0.3); // like eating 4 nutrition with a 0.3 modifier
|
||||
player.add_exhaustion(8); // two points of saturation or hunger
|
||||
```
|
||||
@@ -0,0 +1,110 @@
|
||||
# Items
|
||||
|
||||
Items are what players carry: in their inventory, in chests, and dropped on the ground. Every block registers an item
|
||||
that places it, unless it sets `"item": false`. Everything else is defined in the mod's `items/` folder.
|
||||
|
||||
## Items and Item Stacks
|
||||
|
||||
Like blocks, each kind of item is defined once. What players hold are **item stacks**: an item id, a count, and optional
|
||||
`data`.
|
||||
|
||||
```ts
|
||||
interface ItemStack {
|
||||
readonly id: string;
|
||||
count: number;
|
||||
data?: unknown; // any JSON value, set by server scripts
|
||||
}
|
||||
```
|
||||
|
||||
`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.
|
||||
|
||||
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.
|
||||
|
||||
## A Basic Item
|
||||
|
||||
`items/copper_ingot.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"format_version": 1,
|
||||
"item": {
|
||||
"id": "copper_tools:copper_ingot",
|
||||
"texture": "copper_tools:copper_ingot",
|
||||
"lore": "Smelted from copper ore."
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Properties
|
||||
|
||||
| Field | Default | Meaning |
|
||||
| --------------- | ------------------- | ----------------------------------------------------------------------------- |
|
||||
| `id` | required | The item's id. |
|
||||
| `texture` | required | The texture it's drawn with. |
|
||||
| `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. |
|
||||
| `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. |
|
||||
| `components` | none | [Item components](#item-components) and their parameters. |
|
||||
|
||||
### Textures From Data
|
||||
|
||||
`data_textures` draws a stack with another texture when a key in its `data` is set, like the fishing rod while its line
|
||||
is out:
|
||||
|
||||
```json
|
||||
"data_textures": { "cast": "bworld:fishing_rod_cast" }
|
||||
```
|
||||
|
||||
A stack whose `data.cast` is truthy uses `bworld:fishing_rod_cast`. When several keys are, the first listed wins.
|
||||
|
||||
## Item Components
|
||||
|
||||
Like [block components](../blocks/components.md), item components give items behavior. The server script registers them:
|
||||
|
||||
```ts
|
||||
ctx.components.register_item<{ max_water: number }>("bworld:watering_can", {
|
||||
on_create(item, params) {
|
||||
item.data = { water: params.max_water };
|
||||
},
|
||||
get_lore(item, params) {
|
||||
return `Water: ${(item.data as { water: number }).water}/${params.max_water}`;
|
||||
},
|
||||
on_use(item, params, player) {
|
||||
// right clicked while holding it
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
and items list them with their parameters:
|
||||
|
||||
```json
|
||||
"components": { "bworld:watering_can": { "max_water": 32 } }
|
||||
```
|
||||
|
||||
| Handler | Called when |
|
||||
| ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `on_create(item, params)` | A stack of it is made: crafted, given, dropped by a block, and so on. |
|
||||
| `get_lore(item, params)` | The server sends the stack to a player. Returns extra tooltip text for that stack, shown under the item's own `lore`. It isn't saved. |
|
||||
| `on_use(item, params, player)` | A player right clicks while holding it, at nothing or at a block. |
|
||||
|
||||
At a block, the block's own [interaction](../blocks/components.md#interacting) comes first. An item with `on_use` is
|
||||
used instead of being placed.
|
||||
|
||||
`on_use` doesn't say which block was clicked. For that, pair it with a block component's `on_interact`, the way the
|
||||
watering can uses `bworld:water_source`, or subscribe to the `block_interact` [event](../concepts/events.md).
|
||||
|
||||
## Server Script Helpers
|
||||
|
||||
```ts
|
||||
ctx.items.exists("bworld:carrot"); // true
|
||||
ctx.items.max_stack("bworld:wood_pickaxe"); // 1
|
||||
ctx.items.tool("bworld:wood_pickaxe"); // "pickaxe", or undefined for items that aren't tools
|
||||
|
||||
player.give_item("bworld:carrot", 3); // what doesn't fit drops at their feet
|
||||
```
|
||||
@@ -0,0 +1,51 @@
|
||||
# Tools
|
||||
|
||||
A tool is an item with a `tool` property. It breaks blocks of its type faster, lets players get drops from blocks that
|
||||
require it, and wears out over time.
|
||||
|
||||
```json
|
||||
{
|
||||
"format_version": 1,
|
||||
"item": {
|
||||
"id": "copper_tools:copper_pickaxe",
|
||||
"texture": "copper_tools:copper_pickaxe",
|
||||
"tool": { "type": "pickaxe", "tier": 1, "speed": 4, "durability": 5 }
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
| Field | Default | Meaning |
|
||||
| ------------ | -------- | ------------------------------------------------------------------------------------------------------------------- |
|
||||
| `type` | required | Matched against blocks' `mining.tool`, like `"pickaxe"`, `"axe"`, `"shovel"`, `"hoe"` or `"knife"`. Any word works. |
|
||||
| `durability` | required | How many uses it has before it breaks, see below. |
|
||||
| `tier` | `0` | Compared with blocks' `mining.tier`. |
|
||||
| `speed` | `2` | How many times faster than a hand it breaks blocks of its type. |
|
||||
|
||||
Tools stack to 1 unless they set `max_stack`.
|
||||
|
||||
## Mining
|
||||
|
||||
A block breaks `speed` times faster when the held tool's `type` is the block's `mining.tool`. A block with
|
||||
`"requires_tool": true` only drops when broken with a tool of its type whose `tier` is at least the block's
|
||||
`mining.tier`. See [Mining](../blocks/index.md#mining).
|
||||
|
||||
The base game's tiers:
|
||||
|
||||
| Tier | Tools | Durability | Gets drops from |
|
||||
| ---- | ------------- | --------------------- | ----------------------------------- |
|
||||
| `0` | wood, gold | 2 (wood), 9 (gold) | stone, coal ore |
|
||||
| `1` | stone, copper | 3 (stone), 5 (copper) | also copper, tin, iron and gold ore |
|
||||
| `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
|
||||
hoes.
|
||||
|
||||
## Durability
|
||||
|
||||
Like Sunlit Valley, tools don't wear out from use. They lose durability when their owner dies: everything a player
|
||||
carries falls out where they died, and each tool loses 1 durability first. A tool that runs out breaks instead of
|
||||
dropping.
|
||||
|
||||
The damage a tool has taken is kept in its stack's `data.damage`, and its tooltip shows what's left, like
|
||||
`Durability: 4 / 5`. Upgrading a tool at the smithing table keeps its data, damage included.
|
||||
Reference in New Issue
Block a user