Files
bworld/docs/modding/blocks/index.md
T
2026-09-29 23:29:14 -03:00

107 lines
8.6 KiB
Markdown

# Blocks
Blocks make up the world. Each kind of block is defined once, in a JSON file in the mod's `blocks/` folder, and the
world is made of references to those definitions at different positions.
A block's definition says how it looks, how it's mined and what it drops. What it _does_ comes from
[components](components.md), which server scripts register.
## A Basic Block
`blocks/copper_block.json`:
```json
{
"format_version": 1,
"block": {
"id": "copper_tools:copper_block",
"textures": "copper_tools:copper_block",
"mining": { "toughness": 5, "tool": "pickaxe", "requires_tool": true, "tier": 1 },
"drops": "copper_tools:copper_block"
}
}
```
This registers the block and an item with the same id that places it. It's a full cube with the same texture on every
side, takes 5 seconds to break by hand, breaks faster with a pickaxe, and only drops itself when broken with a pickaxe
of tier 1 (stone or copper) or better.
## Properties
### Looks
| Field | Default | Meaning |
| ---------------- | ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `id` | required | The block's id. |
| `name` | from the id | What players see. `copper_tools:copper_block` is "Copper Block" when not set. Its item uses it too. |
| `textures` | required | One texture id for every side, `{ "top", "bottom", "side" }`, or `{ "front", "side" }` (optionally with `top` and `bottom`) for a block that faces a way. With another `model`, the model's texture variables. |
| `model` | `engine:cube` | The [block model](../resources/models.md). |
| `variants` | none | Other models, textures or rotations for some [states](states.md). |
| `render_layer` | `solid` | `solid`; `cutout` for texels that are fully opaque or fully clear, like leaves; `translucent` for blended ones, like water and glass. |
| `cull_same` | see meaning | Hide the faces between two of this block. `true` for translucent blocks, `false` otherwise. |
| `alpha` | `1` | Opacity, for translucent blocks. |
| `tint` | none | Draws its textures in a color, see [below](#tinting). |
| `light_emission` | `0` | Light it gives off, 0-15. A torch is 14. |
| `light_opacity` | see meaning | How much light passing through it loses, 0-15. `15` for solid blocks, `0` otherwise. Leaves and water use `1`. |
Only `solid` blocks hide their neighbors' faces. Blocks that aren't full cubes, like plants, should use `cutout`, or
there will be holes in the world behind them.
### Behavior
| Field | Default | Meaning |
| ---------------------- | ----------- | ----------------------------------------------------------------------------------------------------------------------------- |
| `collision` | `true` | Whether entities bump into it. Plants and water set `false`. |
| `mining.toughness` | unbreakable | Seconds to break by hand. Without `mining`, a block can't be broken. |
| `mining.tool` | none | The [tool type](../items/tools.md) that breaks it faster, like `pickaxe`, `axe` or `shovel`. |
| `mining.requires_tool` | `false` | Only drops when broken with `mining.tool`. |
| `mining.tier` | `0` | With `requires_tool`, the lowest tool tier it drops for. Iron ore is `1`, so a wood pickaxe gets nothing. |
| `drops` | nothing | The item id it drops when broken. |
| `item` | `true` | Also register an item that places it, with the same id. |
| `interactive` | `false` | Right clicking it does something, like opening a screen, so clients don't guess that it places a block. |
| `replaceable` | `false` | Placing a block into it replaces it, like water. |
| `place_in` | see meaning | Block ids it can be placed into, replacing them, like `["bworld:water"]` for rice. Air and `replaceable` blocks when not set. |
| `place_on` | anywhere | Block ids it can stand on, like `["bworld:hoed_dirt"]` for crops. See [below](#placement). |
| `states` | none | Named [state](states.md) bits, like a crop's age. |
| `components` | none | [Components](components.md) and their parameters. |
| `item_display` | none | Shows an item on top of it, see [Tile Data](tiledata.md#showing-an-item). |
A block's definition goes to every player, since clients need it to draw the block, time breaking and collide with it.
It can't hold functions.
## Mining
Breaking takes `mining.toughness` seconds by hand. A tool whose type matches `mining.tool` breaks it `tool.speed` times
faster. The client times breaking itself, and the server checks the result.
When it breaks, the block's components' `on_break` runs and it drops `drops`, unless it has `requires_tool` and the
player's tool is the wrong type or a tier below `mining.tier`.
## Placement
Players place a block by right clicking a face of another block with its item. It goes next to the face they clicked, or
into the clicked block itself when that one is `replaceable`, like water.
It's only placed when:
- the spot is one it can go into: air or a `replaceable` block, or one of `place_in`,
- the block under the spot is one of `place_on`, when the block has `place_on`,
- and, for blocks with collision, no player or mob is in the way.
A block with `place_on` also pops off (dropping what it drops) when the block under it becomes something else, like a
crop when its farmland is dug up.
Food that places a block, like potatoes, is planted when clicked somewhere it can go and eaten otherwise.
## Tinting
`tint` draws a block's textures in a color, for textures painted in greys:
```json
"tint": { "color": "grass", "textures": ["top"] }
```
`color` is `"grass"` or `"foliage"` for the biome's color, blended across biome borders like Minecraft's grass and
leaves, or a fixed color like `"#80a755"`. `textures` lists the texture variables to tint, like only the grass block's
top. Without it every texture is tinted. In inventories, where there's no biome, the block uses plains' color.