Skip to content

Commit

Permalink
block/leaves.go: fixed import cycle
Browse files Browse the repository at this point in the history
  • Loading branch information
aabstractt committed Jul 24, 2024
1 parent 07bbb48 commit 20f731c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
12 changes: 7 additions & 5 deletions server/block/leaves.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package block

import (
"github.com/df-mc/dragonfly/server/block/cube"
"github.com/df-mc/dragonfly/server/event"
"github.com/df-mc/dragonfly/server/item"
"github.com/df-mc/dragonfly/server/world"
"github.com/go-gl/mathgl/mgl64"
Expand Down Expand Up @@ -66,11 +67,12 @@ func (l Leaves) RandomTick(pos cube.Pos, w *world.World, _ *rand.Rand) {
l.ShouldUpdate = false
w.SetBlock(pos, l, nil)
} else {
drops := l.BreakInfo().Drops(nil, nil)
w.Handler().HandleLeavesDecay(pos, &drops)

for _, drop := range drops {
dropItem(w, drop, pos.Vec3Centre())
ctx := event.C()
if w.Handler().HandleLeavesDecay(ctx, pos); !ctx.Cancelled() {
drops := l.BreakInfo().Drops(nil, nil)
for _, drop := range drops {
dropItem(w, drop, pos.Vec3Centre())
}
}

w.SetBlock(pos, nil, nil)
Expand Down
6 changes: 3 additions & 3 deletions server/world/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package world
import (
"github.com/df-mc/dragonfly/server/block/cube"
"github.com/df-mc/dragonfly/server/event"
"github.com/df-mc/dragonfly/server/item"
"github.com/go-gl/mathgl/mgl64"
)

Expand All @@ -12,7 +11,8 @@ import (
type Handler interface {
// HandleLeavesDecay handles the decaying of a Leaves block at a position. Leaves decaying happens when
// there is no wood block neighbouring it. The position of the Leaves block is passed to the handler.
HandleLeavesDecay(pos cube.Pos, drops *[]item.Stack)
// if ctx.Cancel() is called, the leaves don't drop any items.
HandleLeavesDecay(ctx *event.Context, pos cube.Pos)
// HandleLiquidFlow handles the flowing of a liquid from one block position from into another block
// position into. The liquid that will replace the block is also passed. This replaced block might
// also be a Liquid. The Liquid's depth and falling state can be checked to see if the resulting
Expand Down Expand Up @@ -57,7 +57,7 @@ var _ Handler = (*NopHandler)(nil)
// Users may embed NopHandler to avoid having to implement each method.
type NopHandler struct{}

func (NopHandler) HandleLeavesDecay(cube.Pos, *[]item.Stack) {}
func (NopHandler) HandleLeavesDecay(*event.Context, cube.Pos) {}
func (NopHandler) HandleLiquidFlow(*event.Context, cube.Pos, cube.Pos, Liquid, Block) {}
func (NopHandler) HandleLiquidDecay(*event.Context, cube.Pos, Liquid, Liquid) {}
func (NopHandler) HandleLiquidHarden(*event.Context, cube.Pos, Block, Block, Block) {}
Expand Down

0 comments on commit 20f731c

Please sign in to comment.