Update modding docs
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
# Block Models
|
||||
|
||||
A block's model is its shape: the boxes it's made of and which texture goes on each face. Blocks use `engine:cube`
|
||||
unless they set `model`. For entity models, see [Entities](../entities/index.md#entity-models).
|
||||
|
||||
## Built-In Models
|
||||
|
||||
| Model | Texture variables | Shape |
|
||||
| -------------- | --------------------------------------------------------- | ---------------------------------------------- |
|
||||
| `engine:cube` | one texture, `{ top, bottom, side }` or `{ front, side }` | A full block. |
|
||||
| `engine:cross` | `cross` | Two crossed planes, like flowers and saplings. |
|
||||
| `engine:crop` | `crop` | Four planes in a # shape, like wheat. |
|
||||
|
||||
Blocks that aren't full cubes should use the `cutout` or `translucent` [render layer](../blocks/index.md#looks), since
|
||||
`solid` blocks hide their neighbors' faces. They usually want `"collision": false` too.
|
||||
|
||||
In inventories, a block with a full cube model is drawn as a cube. Any other block is drawn flat, as its first texture,
|
||||
like Minecraft's plants.
|
||||
|
||||
## Texture Variables
|
||||
|
||||
Models name their textures with variables, like `#side`, and blocks fill them in with `textures`:
|
||||
|
||||
```json
|
||||
{
|
||||
"id": "bworld:sapling",
|
||||
"model": "engine:cross",
|
||||
"textures": { "cross": "bworld:sapling" }
|
||||
}
|
||||
```
|
||||
|
||||
For `engine:cube`, one texture id fills every face. `{ "front", "side" }` puts `front` on the north face and `side` on
|
||||
the rest. It's for blocks that [face a way](../blocks/states.md#facing), and can also set `top` and `bottom`.
|
||||
|
||||
## Custom Models
|
||||
|
||||
Mods add models in `models/`, in Minecraft's block model format: boxes measured in pixels, where 0 to 16 is the block,
|
||||
with a texture per face. `models/slab.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"format_version": 1,
|
||||
"model": {
|
||||
"id": "copper_tools:slab",
|
||||
"textures": { "top": "#side", "bottom": "#side" },
|
||||
"elements": [{
|
||||
"from": [0, 0, 0],
|
||||
"to": [16, 8, 16],
|
||||
"faces": {
|
||||
"top": { "texture": "#top" },
|
||||
"bottom": { "texture": "#bottom", "cullface": "bottom" },
|
||||
"north": { "texture": "#side", "cullface": "north" },
|
||||
"south": { "texture": "#side", "cullface": "south" },
|
||||
"west": { "texture": "#side", "cullface": "west" },
|
||||
"east": { "texture": "#side", "cullface": "east" }
|
||||
}
|
||||
}]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
A block using it sets `"model": "copper_tools:slab"` and `"textures": { "side": "bworld:planks" }`, and gets planks on
|
||||
every face, since `top` and `bottom` default to `#side`.
|
||||
|
||||
| Field | Meaning |
|
||||
| ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `id` | The model's id, in the mod's namespace. |
|
||||
| `textures` | Defaults for texture variables. Values are texture ids or other variables, like `"#side"`. |
|
||||
| `elements[].from`, `to` | Opposite corners of the box, `[x, y, z]` in pixels. |
|
||||
| `elements[].rotation` | `{ origin, axis, angle, rescale }`: turns the box around `origin` on `x`, `y` or `z` by -45, -22.5, 0, 22.5 or 45 degrees. `rescale` stretches it back to the block's width. |
|
||||
| `elements[].shade` | Darker faces on the sides and bottom. `true` by default, plants turn it off. |
|
||||
| `elements[].faces` | Any of `top`, `bottom`, `north`, `south`, `west` and `east`. |
|
||||
| `faces.*.texture` | A variable like `"#side"`, filled in by the block's `textures`, or a texture id. |
|
||||
| `faces.*.uv` | `[u1, v1, u2, v2]`, the part of the texture in pixels. Defaults to the part the face covers. |
|
||||
| `faces.*.rotation` | Turns the texture on the face clockwise by 0, 90, 180 or 270 degrees. |
|
||||
| `faces.*.cullface` | Hides the face when the neighbor on that side is a solid block. Only for faces on the block's edge. |
|
||||
|
||||
Faces are only drawn from the front, so a flat plane that should be seen from both sides needs a face each way.
|
||||
|
||||
## Lighting
|
||||
|
||||
Faces flat against the block's edge get smooth lighting and ambient occlusion like a full block's. Anything inside the
|
||||
block is lit evenly with the light of the block's own space.
|
||||
@@ -0,0 +1,126 @@
|
||||
# Recipes
|
||||
|
||||
Recipes are data in a mod's `recipes/` folder, one per file. The base game has four types, for its crafting grid,
|
||||
furnace and smithing table. Mods can make up types of their own for their machines.
|
||||
|
||||
## Crafting: `shaped`
|
||||
|
||||
For the crafting grid in the player's inventory screen:
|
||||
|
||||
```json
|
||||
{
|
||||
"format_version": 1,
|
||||
"recipe": {
|
||||
"type": "shaped",
|
||||
"pattern": ["PPP", "P P", "PPP"],
|
||||
"key": { "P": "bworld:planks" },
|
||||
"result": { "id": "bworld:chest", "count": 1 }
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
`pattern` is 1 to 3 rows of 1 to 3 characters, where a space is an empty slot. `key` maps each letter to an item. The
|
||||
pattern fits anywhere in the grid.
|
||||
|
||||
## Smelting: `furnace` and `fuel`
|
||||
|
||||
```json
|
||||
{
|
||||
"format_version": 1,
|
||||
"recipe": {
|
||||
"type": "furnace",
|
||||
"input": "bworld:iron_ore",
|
||||
"output": { "id": "bworld:iron_ingot", "count": 1 },
|
||||
"cook_time": 200
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
```json
|
||||
{
|
||||
"format_version": 1,
|
||||
"recipe": { "type": "fuel", "item": "bworld:coal", "burn_time": 1000 }
|
||||
}
|
||||
```
|
||||
|
||||
`cook_time` and `burn_time` are in ticks, 20 to a second. Two furnace recipes for the same input are an error. For fuel,
|
||||
a later recipe for the same item replaces an earlier one.
|
||||
|
||||
## Smithing: `smithing`
|
||||
|
||||
For the smithing table, which upgrades a tool:
|
||||
|
||||
```json
|
||||
{
|
||||
"format_version": 1,
|
||||
"recipe": {
|
||||
"type": "smithing",
|
||||
"tool": "bworld:wood_pickaxe",
|
||||
"material": { "id": "bworld:stone", "count": 5 },
|
||||
"result": "bworld:stone_pickaxe"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
An optional `addition` is a third item it also takes. Upgrading uses up the tool, `count` of the material and the
|
||||
addition, and the result keeps the tool's `data`, like its [durability](../items/tools.md#durability). Two smithing
|
||||
recipes with the same tool, material and addition are an error.
|
||||
|
||||
## Choices
|
||||
|
||||
Anywhere a recipe takes an item (`key` values, `input`, `item`), a list of ids means any of them fits:
|
||||
|
||||
```json
|
||||
"key": { "P": ["bworld:planks", "bworld:birch_planks", "bworld:spruce_planks"] }
|
||||
```
|
||||
|
||||
In the crafting grid, each slot can hold a different one of them, so a stick can be made from oak and birch planks
|
||||
together. The recipe viewer takes turns showing them.
|
||||
|
||||
## Custom Recipe Types
|
||||
|
||||
Any `type` with a namespace is a mod's own, like `farmersdelight:cooking` for the cooking pot. The engine only stores
|
||||
these recipes. Everything else about them is up to the mod:
|
||||
|
||||
```json
|
||||
{
|
||||
"format_version": 1,
|
||||
"recipe": {
|
||||
"type": "farmersdelight:cooking",
|
||||
"ingredients": ["farmersdelight:cabbage", ["bworld:carrot", "bworld:potato", "farmersdelight:onion"]],
|
||||
"result": { "id": "farmersdelight:cabbage_rolls", "count": 1 },
|
||||
"cook_time": 100
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The mod's server script reads them in `setup` and checks their fields itself:
|
||||
|
||||
```ts
|
||||
const recipes = ctx.recipes.list("farmersdelight:cooking").map((json, i) => {
|
||||
if (!Array.isArray(json.ingredients) || json.ingredients.length > 6) {
|
||||
throw new Error(`cooking recipe ${i + 1}: ingredients must be 1 to 6 items`);
|
||||
}
|
||||
// ...check the rest, and turn it into whatever the machine needs
|
||||
return json;
|
||||
});
|
||||
```
|
||||
|
||||
Throwing in `setup` stops the server from starting with the error, so a broken recipe is caught when the server starts
|
||||
rather than when someone uses the machine. Other mods can add recipes of your type too, as long as they depend on your
|
||||
mod.
|
||||
|
||||
`list` returns copies, in load order. Client scripts can read every recipe with `ctx.recipes.list(type?)`, which is how
|
||||
the recipe viewer shows mods' own types.
|
||||
|
||||
## Looking Up Recipes
|
||||
|
||||
Server scripts can ask about the base game's types:
|
||||
|
||||
```ts
|
||||
ctx.recipes.furnace_result("bworld:iron_ore"); // { output, cook_time }, or undefined
|
||||
ctx.recipes.is_smeltable("bworld:iron_ore");
|
||||
ctx.recipes.is_fuel("bworld:coal");
|
||||
ctx.recipes.fuel_value("bworld:coal"); // burn time in ticks, 0 when it isn't fuel
|
||||
ctx.recipes.smithing("bworld:wood_pickaxe", "bworld:stone"); // { result, material_count }, or undefined
|
||||
```
|
||||
@@ -0,0 +1,36 @@
|
||||
# Textures
|
||||
|
||||
Every `.png` in a mod's `textures/` folder becomes a texture that blocks, items, entities and screens can use.
|
||||
|
||||
## Texture Ids
|
||||
|
||||
A texture's id is `<mod id>:<file name without .png>`. Subfolders are joined with `_`, so in the mod `copper_tools`:
|
||||
|
||||
| File | Texture id |
|
||||
| --------------------------- | --------------------------- |
|
||||
| `textures/copper_block.png` | `copper_tools:copper_block` |
|
||||
| `textures/ores/tin.png` | `copper_tools:ores_tin` |
|
||||
|
||||
Any mod can use any texture by its id, including the base game's, like `bworld:stone`.
|
||||
|
||||
## Sizes
|
||||
|
||||
Textures can be any size up to 256×256. Blocks and items are made for 16×16 and stretch a texture of another size over
|
||||
the same face, so a 32×32 block texture is just a sharper one. Larger ones are for things like entity skins.
|
||||
|
||||
## Missing Textures
|
||||
|
||||
A texture id that doesn't exist shows the magenta and black checker, `engine:missing`, and `check-mods` warns about it.
|
||||
It isn't an error, so a mod still loads while its art is unfinished.
|
||||
|
||||
## Engine Textures
|
||||
|
||||
The engine's own textures use the `engine` namespace and come from `assets/`, not from a mod:
|
||||
|
||||
- `engine:missing`, the missing texture,
|
||||
- `engine:break_0` to `engine:break_8`, the cracks drawn on a block being broken.
|
||||
|
||||
## How Players Get Them
|
||||
|
||||
Textures go in the mod's `.bmod`. When a player joins, their client puts every mod's textures into one atlas. The server
|
||||
never decodes images.
|
||||
Reference in New Issue
Block a user