Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions server/player/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ type Handler interface {
// the original cause of the immunity frame. In this case, the damage is
// reduced but the player is still knocked back.
HandleHurt(ctx *Context, damage *float64, immune bool, attackImmunity *time.Duration, src world.DamageSource)
// HandleKnockBack handles the player being knocked back. ctx.Cancel() may be called to cancel knockback.
HandleKnockBack(ctx *Context, src *mgl64.Vec3, force, height *float64)
// HandleDeath handles the player dying to a particular damage cause.
HandleDeath(p *Player, src world.DamageSource, keepInv *bool)
// HandleRespawn handles the respawning of the player in the world. The spawn position passed may be
Expand Down Expand Up @@ -192,6 +194,7 @@ func (NopHandler) HandleAttackEntity(*Context, world.Entity, *float64, *float64,
func (NopHandler) HandleExperienceGain(*Context, *int) {}
func (NopHandler) HandlePunchAir(*Context) {}
func (NopHandler) HandleHurt(*Context, *float64, bool, *time.Duration, world.DamageSource) {}
func (NopHandler) HandleKnockBack(*Context, *mgl64.Vec3, *float64, *float64) {}
func (NopHandler) HandleHeal(*Context, *float64, world.HealingSource) {}
func (NopHandler) HandleFoodLoss(*Context, int, *int) {}
func (NopHandler) HandleDeath(*Player, world.DamageSource, *bool) {}
Expand Down
5 changes: 5 additions & 0 deletions server/player/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,11 @@ func (p *Player) KnockBack(src mgl64.Vec3, force, height float64) {
// knockBack is an unexported function that is used to knock the player back. This function does not check if the player
// can take damage or not.
func (p *Player) knockBack(src mgl64.Vec3, force, height float64) {
ctx := event.C(p)
if p.Handler().HandleKnockBack(ctx, &src, &force, &height); ctx.Cancelled() {
return
}

velocity := p.Position().Sub(src)
velocity[1] = 0

Expand Down