Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TrampleCrop Handler #868

Merged
merged 10 commits into from
Aug 31, 2024
3 changes: 3 additions & 0 deletions server/player/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
xNatsuri marked this conversation as resolved.
Show resolved Hide resolved
// 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.
Expand Down Expand Up @@ -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) {}
Expand Down
9 changes: 8 additions & 1 deletion server/player/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading