Neighbor Updates as a Queue
This commit is contained in:
@@ -99,6 +99,23 @@ ctx.components.register_block("copper_tools:bell", {
|
||||
});
|
||||
```
|
||||
|
||||
The blocks beside one that changed don't hear of it while the change is going on. They wait in a queue and hear in the
|
||||
order they were told, once the change is done, along with the ones they set off. The world is settled again by the time
|
||||
the outermost change returns, so a script that places a fence in `on_tick` sees it joined right after. One that places
|
||||
it in `on_neighbor_change`, which runs while another change is settling, sees it joined once that's done. Blocks a
|
||||
handler tells while its block is being broken, in `on_break`, hear once it's gone. A change can tell blocks 65,536 times
|
||||
before it's stopped and the server logs where, so blocks that keep setting each other off can't hang the server.
|
||||
|
||||
Two more things in `ctx.world` are for blocks that tell others themselves:
|
||||
|
||||
- `ctx.world.neighbor_changed(x, y, z, from)` tells the block at `x y z` that the one at `from` changed, running its
|
||||
rules' and components' `on_neighbor_change`, like NeoForge's `neighborChanged`. It's for a block whose effect on
|
||||
others changed without it changing, or for blocks it reaches that aren't beside it, like the far end of something it's
|
||||
joined to.
|
||||
- `ctx.world.set_state(x, y, z, name, value, { update_neighbors: false })` changes a state without telling the blocks
|
||||
around it, for a script that tells them itself, so a long line of blocks changing together tells each block beside it
|
||||
once instead of once per block. `on_state_change` still runs.
|
||||
|
||||
## Rules
|
||||
|
||||
A component's rules decide a block's states from where it's placed, what's around it and being right clicked. They're
|
||||
@@ -135,6 +152,8 @@ the axle of the block it's placed against.
|
||||
`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.
|
||||
The blocks a change tells hear of it one after another, in the same order on the server and on clients, once the change
|
||||
is done (see [Changes](#changes)).
|
||||
|
||||
`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,
|
||||
|
||||
@@ -31,7 +31,8 @@ ctx.world.set_state(x, y, z, "age", age + 1);
|
||||
`get_state` is `undefined` where there's no block, and `set_state` does nothing there and returns `false`. Both throw
|
||||
for a state the block doesn't have, and `set_state` for a value that doesn't fit its bits. Changes are synced to
|
||||
everyone who can see the block. Unlike `set_block`, it doesn't run `on_break` or `on_create`, and the block keeps its
|
||||
tile data. It runs the block's [`on_state_change`](components.md#changes) instead.
|
||||
tile data. It runs the block's [`on_state_change`](components.md#changes) instead, and tells the blocks beside it,
|
||||
unless it's given `{ update_neighbors: false }`.
|
||||
|
||||
## Variants
|
||||
|
||||
|
||||
Reference in New Issue
Block a user