Skip to content

Commit

Permalink
implement TrampleCrop player handler
Browse files Browse the repository at this point in the history
  • Loading branch information
xNatsuri committed May 2, 2024
1 parent 97fdfe2 commit 5dc83b0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
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)
// 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

0 comments on commit 5dc83b0

Please sign in to comment.