diff --git a/server/block/farmland.go b/server/block/farmland.go index 38afdf11a..7bc6576ab 100644 --- a/server/block/farmland.go +++ b/server/block/farmland.go @@ -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/world" "math/rand" ) @@ -72,7 +73,10 @@ func (f Farmland) hydrated(pos cube.Pos, w *world.World) bool { func (f Farmland) EntityLand(pos cube.Pos, w *world.World, e world.Entity, distance *float64) { if living, ok := e.(livingEntity); ok { if fall, ok := living.(fallDistanceEntity); ok && rand.Float64() < fall.FallDistance()-0.5 { - w.SetBlock(pos, Dirt{}, nil) + ctx := event.C() + if w.Handler().HandleCropTrample(ctx, pos); !ctx.Cancelled() { + w.SetBlock(pos, Dirt{}, nil) + } } } } diff --git a/server/world/handler.go b/server/world/handler.go index 2a598f1d0..6997575d1 100644 --- a/server/world/handler.go +++ b/server/world/handler.go @@ -35,6 +35,8 @@ type Handler interface { // wood, that can be broken by fire. HandleBlockBurn is often succeeded by HandleFireSpread, when fire spreads to // the position of the original block and the event.Context is not cancelled in HandleBlockBurn. HandleBlockBurn(ctx *event.Context, pos cube.Pos) + // HandleCropTrample handles an entity trampling a crop. + HandleCropTrample(ctx *event.Context, pos cube.Pos) // HandleEntitySpawn handles an entity being spawned into a World through a call to World.AddEntity. HandleEntitySpawn(e Entity) // HandleEntityDespawn handles an entity being despawned from a World through a call to World.RemoveEntity. @@ -59,6 +61,7 @@ func (NopHandler) HandleLiquidHarden(*event.Context, cube.Pos, Block, Block, Blo func (NopHandler) HandleSound(*event.Context, Sound, mgl64.Vec3) {} func (NopHandler) HandleFireSpread(*event.Context, cube.Pos, cube.Pos) {} func (NopHandler) HandleBlockBurn(*event.Context, cube.Pos) {} +func (NopHandler) HandleCropTrample(*event.Context, cube.Pos) {} func (NopHandler) HandleEntitySpawn(Entity) {} func (NopHandler) HandleEntityDespawn(Entity) {} func (NopHandler) HandleClose() {}