Improve crops system

This commit is contained in:
2026-09-26 18:32:38 -03:00
parent e22f12c0b6
commit 0fa6ec4ed3
15 changed files with 394 additions and 31 deletions
+8 -2
View File
@@ -250,6 +250,7 @@ program**, so the server and each client can number blocks differently. Saves an
| `item` | `true` | `register_block_item` | Also register an item that places this block, with the same id. |
| `interactive` | `false` | `interactive` | Right clicking it does something (opens a screen), so clients don't guess it places a block. |
| `replaceable` | `false` | new | Placing a block into it replaces it, like water. |
| `place_on` | anywhere | `place_on` | Block ids it can stand on, like `["bworld:hoed_dirt"]` for crops. Players can't place it anywhere else, and it breaks (with its drops) when the block under it becomes something else, like Minecraft's `canSurvive`. |
| `states` | none | `states` | Up to 16 bits of named state, like `hoed_dirt` has now. |
| `components` | none | `components` | Custom components with parameters, handled by server scripts. |
@@ -607,11 +608,14 @@ ctx.components.register_block("copper_tools:oxidizes", {
| `on_interact(block, params, player)` | A player right clicks it. | `true` if handled, so no block gets placed |
| `on_tick(block, params, dt)` | Every tick (20 per second) near a player. | ignored |
| `on_second(block, params, dt)` | Every second near a player. | ignored |
| `on_new_day(block, params, day)` | Every morning at 06:00, anywhere in the world. | ignored |
`block` is `{ id, x, y, z, data }`. `data` is tile data: any JSON value, `undefined` until a handler sets it, saved with
the world and **never sent to clients**. To show tile data to a player, open a screen with it (see [GUIs](#guis)).
`on_tick` and `on_second` only run for blocks that have tile data, so a component that ticks from the start sets
`block.data` in `on_create`. They run within 6 chunks of a player. `dt` is in seconds: 0.05 for `on_tick`, 1 for
`on_tick`, `on_second` and `on_new_day` only run for blocks that have tile data, so a component that ticks from the
start sets `block.data` in `on_create`. `on_new_day` runs for every such block in the world, near a player or not, so
things like crops keep growing while nobody's around (see the base game's farming in `mods/bworld/scripts/server.ts`).
When time jumps forward past several mornings (`/time add`), each one runs, up to 64. They run within 6 chunks of a player. `dt` is in seconds: 0.05 for `on_tick`, 1 for
`on_second`.
The server runs a fixed 20 ticks per second. When a tick takes too long, the next ones run back to back until it has
@@ -645,6 +649,7 @@ events** fire once it has happened.
| `player_leave` | | ✓ | `player` |
| `server_start` | | ✓ | none |
| `tick` | | ✓ | `dt` in seconds, 20 times per second |
| `new_day` | | ✓ | `day`, at 06:00 after every block's `on_new_day` |
These fire for **every** player's actions, because they all go through the server. When a before event cancels a break
or place, the server tells that player's client to undo what it already showed.
@@ -662,6 +667,7 @@ interface ServerWorld {
is_loaded(x: number, z: number): boolean;
readonly seed: string;
readonly time: number; // world time, see below
readonly day: number; // days since the world started, going up at 06:00, 0 on the first day
set_time(time: number): void; // synced to every player
}