Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions server/world/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ type Handler interface {
// HandleRedstoneUpdate handles a redstone update at a position. ctx.Cancel() may be called
// to cancel the redstone update.
HandleRedstoneUpdate(ctx *Context, pos cube.Pos)
// HandleNeighbourUpdate handles a block at pos being updated because of a change to a
// neighbouring block at changedNeighbour. It is only called for a block or liquid that
// reacts to the change, that is, one implementing NeighbourUpdateTicker. ctx.Cancel() may
// be called to prevent both the block and any liquid at the position from being updated.
HandleNeighbourUpdate(ctx *Context, pos, changedNeighbour cube.Pos)
// HandleClose handles the World being closed. HandleClose may be used as a
// moment to finish code running on other goroutines that operates on the
// World specifically. HandleClose is called directly before the World stops
Expand Down Expand Up @@ -93,4 +98,5 @@ func (NopHandler) HandleEntitySpawn(*Tx, Entity)
func (NopHandler) HandleEntityDespawn(*Tx, Entity) {}
func (NopHandler) HandleExplosion(*Context, mgl64.Vec3, *[]Entity, *[]cube.Pos, *float64, *bool) {}
func (NopHandler) HandleRedstoneUpdate(*Context, cube.Pos) {}
func (NopHandler) HandleNeighbourUpdate(*Context, cube.Pos, cube.Pos) {}
func (NopHandler) HandleClose(*Tx) {}
21 changes: 15 additions & 6 deletions server/world/tick.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/df-mc/dragonfly/server/block/cube"
"github.com/df-mc/dragonfly/server/event"
"github.com/df-mc/dragonfly/server/internal/sliceutil"
)

Expand Down Expand Up @@ -102,13 +103,21 @@ func (t ticker) performNeighbourUpdates(tx *Tx) {

for _, update := range updates {
pos, changedNeighbour := update.pos, update.neighbour
if ticker, ok := tx.Block(pos).(NeighbourUpdateTicker); ok {
ticker.NeighbourUpdateTick(pos, changedNeighbour, tx)
blockTicker, blockOk := tx.Block(pos).(NeighbourUpdateTicker)
liquid, _ := tx.World().additionalLiquid(pos)
liquidTicker, liquidOk := liquid.(NeighbourUpdateTicker)
if !blockOk && !liquidOk {
continue
}
if liquid, ok := tx.World().additionalLiquid(pos); ok {
if ticker, ok := liquid.(NeighbourUpdateTicker); ok {
ticker.NeighbourUpdateTick(pos, changedNeighbour, tx)
}
ctx := event.C(tx)
if tx.World().Handler().HandleNeighbourUpdate(ctx, pos, changedNeighbour); ctx.Cancelled() {
continue
}
if blockOk {
blockTicker.NeighbourUpdateTick(pos, changedNeighbour, tx)
}
if liquidOk {
liquidTicker.NeighbourUpdateTick(pos, changedNeighbour, tx)
}
}
}
Expand Down