Trapdoors

This commit is contained in:
2026-10-03 17:52:58 -03:00
parent 91655c28c5
commit 63e6248f9f
35 changed files with 927 additions and 23 deletions
+33 -12
View File
@@ -69,6 +69,7 @@ component.
| `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. | |
| `state_for_placement(placement, params)` | A player is about to place it. | States to place it with |
`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.
@@ -83,6 +84,25 @@ Setting a state to what it already is changes nothing and tells no one, so block
`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.
### Placing
`state_for_placement` picks the states a block is placed with, like Minecraft's `getStateForPlacement`. `placement` is
`{ x, y, z, player, face, hit }`: where it's going, the face of the block that was clicked, and where on that block the
click was, from 0 to 1 on each axis. It returns states by name, and the rest keep their defaults, except that a 2 bit
`facing` already faces the player. It runs before the server checks that no one is in the way, so that's checked against
the shape the block will really have. A trapdoor clicked onto the upper half of a block's side hangs in the top half:
```ts
state_for_placement(placement): Record<string, number> {
if (placement.face !== "top" && placement.face !== "bottom") {
return { facing: ["north", "east", "south", "west"].indexOf(placement.face), half: placement.hit[1] > 0.5 ? 1 : 0 };
}
return { half: placement.face === "top" ? 0 : 1 };
},
```
Clients guess blocks are placed with their defaults, and the server corrects them right after.
### Interacting
When a player right clicks a block, every component's `on_interact` runs. If any of them returns `true`, the click was
@@ -107,17 +127,18 @@ 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. |
| `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. |
| 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:trapdoor` | none | Opens and closes when right clicked, and is placed like Minecraft's. Needs `facing` (2 bits), `half` and `open` states, see `blocks/oak_trapdoor.json`. |
| `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).
+1 -1
View File
@@ -45,7 +45,7 @@ showed. These events fire for **every** player's actions, since they all go thro
| Event | Before | After | Fields |
| ---------------- | ------ | ----- | ------------------------------------------------------------------------------------------------------------------------------------- |
| `block_break` | ✓ | ✓ | `player`, `block` (with its tile `data`), `item` held |
| `block_place` | ✓ | ✓ | `player`, `block` (`{ id, x, y, z }`), `face` clicked, `item` held |
| `block_place` | ✓ | ✓ | `player`, `block` (`{ id, x, y, z }`), `face` clicked, `hit` where on it (0-1 each axis), `item` held |
| `block_interact` | ✓ | ✓ | `player`, `block`, `item` held. Before fires for every right click on a block, after only when a component's `on_interact` handled it |
| `chat_send` | ✓ | ✓ | `player`, `message`. Before handlers can change `message` |
| `player_damage` | ✓ | ✓ | `player`, `amount`, `cause`. Before handlers can change `amount`, after fires only when they were hurt, with what they took |