diff --git a/server/player/handler.go b/server/player/handler.go index 5f13e4ba5..023186fb1 100644 --- a/server/player/handler.go +++ b/server/player/handler.go @@ -68,6 +68,8 @@ type Handler interface { // HandleBlockPick handles the player picking a specific block at a position in its world. ctx.Cancel() // may be called to cancel the block being picked. HandleBlockPick(ctx *event.Context, pos cube.Pos, b world.Block) + // HandleTrampleCrop handles the player trampling a crop. + HandleTrampleCrop(ctx *event.Context) // HandleItemUse handles the player using an item in the air. It is called for each item, although most // will not actually do anything. Items such as snowballs may be thrown if HandleItemUse does not cancel // the context using ctx.Cancel(). It is not called if the player is holding no item. @@ -156,6 +158,7 @@ func (NopHandler) HandleStartBreak(*event.Context, cube.Pos) func (NopHandler) HandleBlockBreak(*event.Context, cube.Pos, *[]item.Stack, *int) {} func (NopHandler) HandleBlockPlace(*event.Context, cube.Pos, world.Block) {} func (NopHandler) HandleBlockPick(*event.Context, cube.Pos, world.Block) {} +func (NopHandler) HandleTrampleCrop(*event.Context) {} func (NopHandler) HandleSignEdit(*event.Context, bool, string, string) {} func (NopHandler) HandleLecternPageTurn(*event.Context, cube.Pos, int, *int) {} func (NopHandler) HandleItemPickup(*event.Context, *item.Stack) {} diff --git a/server/player/player.go b/server/player/player.go index 4de9d0859..002d4b0ce 100644 --- a/server/player/player.go +++ b/server/player/player.go @@ -542,7 +542,14 @@ func (p *Player) fall(distance float64) { b = w.Block(pos) } if h, ok := b.(block.EntityLander); ok { - h.EntityLand(pos, w, p, &distance) + if _, ok := b.(block.Farmland); ok { + ctx := event.C() + if p.Handler().HandleTrampleCrop(ctx); !ctx.Cancelled() { + h.EntityLand(pos, w, p, &distance) + } + } else { + h.EntityLand(pos, w, p, &distance) + } } dmg := distance - 3 if boost, ok := p.Effect(effect.JumpBoost{}); ok {