Fences
This commit is contained in:
@@ -59,19 +59,30 @@ component.
|
||||
|
||||
## Handlers
|
||||
|
||||
| Handler | Called when | Returns |
|
||||
| ------------------------------------ | ----------------------------------------------------------------- | -------------------------- |
|
||||
| `on_create(block, params)` | The block is placed or set, by a player or a script. | |
|
||||
| `on_break(block, params, player?)` | The block is broken or replaced. `player` when a player broke it. | |
|
||||
| `on_click(block, params, player)` | A player starts hitting it. | |
|
||||
| `on_interact(block, params, player)` | A player right clicks it. | `true` if it did something |
|
||||
| `on_tick(block, params, dt)` | Every tick, 20 times a second, near a player. | |
|
||||
| `on_second(block, params, dt)` | Every second, near a player. | |
|
||||
| `on_new_day(block, params, day)` | Every morning at 06:00, anywhere in the world. | |
|
||||
| Handler | Called when | Returns |
|
||||
| --------------------------------------------- | ---------------------------------------------------------------------- | -------------------------- |
|
||||
| `on_create(block, params)` | The block is placed or set, by a player or a script. | |
|
||||
| `on_break(block, params, player?)` | The block is broken or replaced. `player` when a player broke it. | |
|
||||
| `on_click(block, params, player)` | A player starts hitting it. | |
|
||||
| `on_interact(block, params, player)` | A player right clicks it. | `true` if it did something |
|
||||
| `on_tick(block, params, dt)` | Every tick, 20 times a second, near a player. | |
|
||||
| `on_second(block, params, dt)` | Every second, near a player. | |
|
||||
| `on_new_day(block, params, day)` | Every morning at 06:00, anywhere in the world. | |
|
||||
| `on_neighbor_change(block, params, neighbor)` | A block on one of its 6 sides is placed, broken or changes its states. | |
|
||||
|
||||
`block` is `{ id, x, y, z, data }`, where `data` is the block's [tile data](tiledata.md). `params` is what the block's
|
||||
JSON lists for this component, and `dt` is in seconds.
|
||||
|
||||
### Neighbors
|
||||
|
||||
`on_neighbor_change` is how a block keeps up with what's around it, like Minecraft's `updateShape`: `neighbor` is
|
||||
`{ x, y, z, id }` of the block that changed. A fence sets its `north`, `east`, `south` and `west` states from it.
|
||||
Setting a state to what it already is changes nothing and tells no one, so blocks answering each other this way settle.
|
||||
|
||||
`ctx.world.is_face_sturdy(x, y, z, face)` says whether a block's side is something to attach to, like Minecraft's
|
||||
`isFaceSturdy`: its [collision shape](../resources/models.md#collision-shapes) covers the whole side. Stone's sides are,
|
||||
a slab's sides and plants aren't.
|
||||
|
||||
### Interacting
|
||||
|
||||
When a player right clicks a block, every component's `on_interact` runs. If any of them returns `true`, the click was
|
||||
@@ -96,16 +107,17 @@ catch up. If it's further behind than that, it skips the rest and logs a warning
|
||||
|
||||
`mods/bworld/scripts/server.ts` registers these, and any mod that depends on `bworld` can use them:
|
||||
|
||||
| Component | Params | What it does |
|
||||
| ----------------------- | --------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `bworld:storage` | `rows` | A chest: `rows` × 9 slots, dropped when it's broken. |
|
||||
| `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:hoeable` | `tool`, `into` | Right clicking with a tool of type `tool` turns it into `into`, like a hoe on grass. |
|
||||
| `bworld:farmland` | none | Watered with the watering can, dries out every morning. |
|
||||
| `bworld:crop` | see [Crops](crops.md) | Grows a stage every morning its farmland was watered. |
|
||||
| `bworld:crop_top` | see [Crops](crops.md) | The top half of a two block crop, like rice. |
|
||||
| `bworld:water_source` | none | Refills the watering can. |
|
||||
| `bworld:fishable` | none | Can be fished in with the fishing rod. |
|
||||
| Component | Params | What it does |
|
||||
| ----------------------- | --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
|
||||
| `bworld:storage` | `rows` | A chest: `rows` × 9 slots, dropped when it's broken. |
|
||||
| `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:hoeable` | `tool`, `into` | Right clicking with a tool of type `tool` turns it into `into`, like a hoe on grass. |
|
||||
| `bworld:farmland` | none | Watered with the watering can, dries out every morning. |
|
||||
| `bworld:crop` | see [Crops](crops.md) | Grows a stage every morning its farmland was watered. |
|
||||
| `bworld:crop_top` | see [Crops](crops.md) | The top half of a two block crop, like rice. |
|
||||
| `bworld:water_source` | none | Refills the watering can. |
|
||||
| `bworld:fishable` | none | Can be fished in with the fishing rod. |
|
||||
| `bworld:fence` | `connects_to` | Joins the blocks in the tag `connects_to` and sturdy sides of other blocks, except leaves. Needs the `north`, `east`, `south` and `west` states. |
|
||||
|
||||
Item components work the same way, see [Items](../items/index.md#item-components).
|
||||
|
||||
@@ -37,6 +37,8 @@ of tier 1 (stone or copper) or better.
|
||||
| `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). |
|
||||
| `parts` | none | Models drawn together depending on [states](states.md), like a fence's post and bars. See [Parts](../resources/models.md#parts). |
|
||||
| `item_model` | none | The model its item is drawn with. See [Item Models](../resources/models.md#item-models). |
|
||||
| `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. |
|
||||
@@ -53,6 +55,7 @@ there will be holes in the world behind them.
|
||||
| ---------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `collision` | `true` | Whether entities bump into it. Plants and water set `false`. |
|
||||
| `shape` | its model | The boxes players point at and entities bump into, in pixels. See [Shapes](../resources/models.md#shapes). |
|
||||
| `collision_shape` | `shape` | What entities bump into when it's different, up to 24 pixels high. See [Collision Shapes](../resources/models.md#collision-shapes). |
|
||||
| `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`. |
|
||||
|
||||
@@ -15,7 +15,7 @@ Blocks that aren't full cubes should use the `cutout` or `translucent` [render l
|
||||
`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.
|
||||
like Minecraft's plants, unless it sets an [`item_model`](#item-models).
|
||||
|
||||
## Texture Variables
|
||||
|
||||
@@ -109,7 +109,47 @@ their own, like a crop that's taller the older it is:
|
||||
}
|
||||
```
|
||||
|
||||
Boxes stay inside the block, from 0 to 16, so a shape can't be taller than a block like Minecraft's fences.
|
||||
Boxes stay inside the block, from 0 to 16.
|
||||
|
||||
### Collision Shapes
|
||||
|
||||
What entities bump into is the shape, unless the block sets `collision_shape`, like Minecraft's `getCollisionShape`.
|
||||
It's in pixels like `shape`, and is the only shape that can go higher than the block: up to 24 pixels, so a fence is too
|
||||
tall to jump over while players still point at a block-high post. Variants and [parts](#parts) can set their own.
|
||||
|
||||
## Parts
|
||||
|
||||
A block can be made of pieces instead of one model, like Minecraft's multipart blockstates. Each of `parts` is a model
|
||||
that's drawn when its `when` matches the block's [states](../blocks/states.md) (always, without one), turned by its `y`.
|
||||
Its `shape` and `collision_shape` are added to the block's when it's drawn. A fence is a post, and a bar for each side
|
||||
it joins, `blocks/oak_fence.json`:
|
||||
|
||||
```json
|
||||
"states": [
|
||||
{ "name": "north", "bits": 1, "default": 0 },
|
||||
{ "name": "east", "bits": 1, "default": 0 },
|
||||
{ "name": "south", "bits": 1, "default": 0 },
|
||||
{ "name": "west", "bits": 1, "default": 0 }
|
||||
],
|
||||
"parts": [
|
||||
{ "model": "bworld:fence_post", "shape": [[6, 0, 6, 10, 16, 10]], "collision_shape": [[6, 0, 6, 10, 24, 10]] },
|
||||
{ "when": "north=1", "model": "bworld:fence_side", "shape": [[7, 0, 0, 9, 16, 9]], "collision_shape": [[7, 0, 0, 9, 24, 9]] },
|
||||
{ "when": "east=1", "model": "bworld:fence_side", "y": 90, "shape": [[7, 0, 0, 9, 16, 9]], "collision_shape": [[7, 0, 0, 9, 24, 9]] },
|
||||
...
|
||||
]
|
||||
```
|
||||
|
||||
The side model is the bars on the north side, and `y` turns it to the others. Parts use the block's `textures` unless
|
||||
they set their own, so one pair of models serves every kind of wood. Parts replace `model` and `variants`' models.
|
||||
|
||||
What sets the states is up to the block's [components](../blocks/components.md): the fences' `bworld:fence` sets them
|
||||
from what's beside it, every time something next to it changes.
|
||||
|
||||
## Item Models
|
||||
|
||||
`item_model` draws a block's item with another model, filled in with the block's textures, like Minecraft's
|
||||
`fence_inventory`. Fences use `bworld:fence_inventory`, two posts and the bars between them, since a single post
|
||||
wouldn't look like a fence. It's drawn in slots, in hands and on the ground.
|
||||
|
||||
## Lighting
|
||||
|
||||
|
||||
Reference in New Issue
Block a user