This commit is contained in:
2026-10-22 19:55:59 -03:00
parent 1b30d71a47
commit 4cd29a17b3
37 changed files with 427 additions and 155 deletions
+19
View File
@@ -65,6 +65,7 @@ component.
| `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_scroll(block, params, player, scroll)` | A player turns the mouse wheel looking at it. See [Scrolling](#scrolling). | |
| `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. See [Ticking](#ticking) for where. | |
@@ -214,6 +215,24 @@ on_interact(block) {
Give a block `"interactive": true` when right clicking it always does something, like opening a screen. Otherwise
clients guess that the click places the held block and show it for a moment before the server corrects them.
### Scrolling
A block whose JSON has `"scrollable": true` takes the mouse wheel: a player turning it while looking at the block, in
reach, runs its components' `on_scroll` on the server, and their hotbar slot stays where it is. It's for a setting that
goes up and down, like how long the pulse repeater waits. `scroll` is `{ amount, face, hit }`: how many notches, more
than 0 for up, and the face and point they look at, like `on_interact`'s. Clients don't guess what it does, so keep what
it changes in states or [client data](tiledata.md#client-data) for them to see, and show the new value with
`player.send_message(text, { overlay: true })`, which puts it above their hotbar for a moment. The pulse repeater's is
in `mods/bworld/scripts/verdigris/devices.ts`:
```ts
on_scroll(block, _params, player, scroll) {
const delay = Math.max(0, Math.min(PULSE_DELAYS.length - 1, state(block, "delay") + scroll.amount));
set(block, "delay", delay);
player.send_message(`Delay: ${delay_text(PULSE_DELAYS[delay])}`, { overlay: true });
},
```
### Ticking
`on_tick` and `on_second` only run for blocks that **have tile data**, within 6 chunks of a player. So a component that
+1
View File
@@ -64,6 +64,7 @@ there will be holes in the world behind them.
| `loot_table` | none | A [loot table](../resources/loot_tables.md) it drops from when broken instead, with its states and the tool. Not with `drops`. |
| `item` | `true` | Also register an item that places it, with the same id. To give that item more, see [Block Items](../items/index.md#block-items). |
| `interactive` | `false` | Right clicking it does something, like opening a screen, so clients don't guess that it places a block. |
| `scrollable` | `false` | The mouse wheel turned while looking at it goes to its components' `on_scroll` instead of the hotbar, see [Scrolling](components.md#scrolling). |
| `replaceable` | `false` | Placing a block into it replaces it, like water. Liquids default to `true`. |
| `place_in` | see meaning | Block ids or [tags](../resources/tags.md) it can be placed into, replacing them, like `["bworld:water"]` for rice. Air and `replaceable` blocks when not set. |
| `place_on` | anywhere | Block ids or [tags](../resources/tags.md) it can stand on, like `["bworld:hoed_dirt"]` for crops or `["#bworld:logs"]`. See [below](#placement). |