Skip to content

server/world: Add a cancellable neighbour update event#1287

Open
root-nat wants to merge 1 commit into
df-mc:masterfrom
root-nat:feature/neighbour-update-event
Open

server/world: Add a cancellable neighbour update event#1287
root-nat wants to merge 1 commit into
df-mc:masterfrom
root-nat:feature/neighbour-update-event

Conversation

@root-nat

Copy link
Copy Markdown

Adds a cancellable event for neighbour-triggered block updates — the equivalent of PocketMine's BlockUpdateEvent (#1002) — mirroring the existing HandleRedstoneUpdate.

What

world.Handler.HandleNeighbourUpdate(ctx *Context, pos, changedNeighbour cube.Pos) (plus the NopHandler stub) is fired from performNeighbourUpdates before a queued neighbour update is dispatched. ctx.Cancel() skips the update for both the block and any liquid at the position.

Design note

The event is fired only for positions whose block or liquid implements NeighbourUpdateTicker — it gates updates that would actually run, rather than firing for every queued position. This keeps the veto use case precise and avoids an allocation per inert neighbour (a block change queues the position plus its six neighbours, most of which do not react).

This differs from PocketMine's BlockUpdateEvent, which fires regardless. If you would prefer observe-everything semantics, the event call can be hoisted above the ticker-existence check with only the dispatch gated on cancellation — happy to change it.

Closes #1002.

🤖 Generated with Claude Code

Blocks react to a neighbouring block changing through NeighbourUpdateTick,
but a Handler had no way to observe or veto this, unlike the redstone update
event. Add HandleNeighbourUpdate, fired before a queued neighbour update is
dispatched to the block (and any liquid) at the position; cancelling it skips
the update, mirroring HandleRedstoneUpdate.

The event is only fired for positions whose block or liquid actually handles
neighbour updates, so inert blocks add no overhead.

Closes df-mc#1002.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a way to cancel block update caused by neighbour changes.

1 participant