Skip to content

Commit

Permalink
player/handler.go: Call HandleChangeWorld again.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandertv committed Dec 24, 2024
1 parent 345fa18 commit e920e59
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 0 additions & 1 deletion server/player/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ type Handler interface {
// HandleTeleport handles the teleportation of a player. ctx.Cancel() may be called to cancel it.
HandleTeleport(ctx *Context, pos mgl64.Vec3)
// HandleChangeWorld handles when the player is added to a new world. before may be nil.
// TODO: NOTE: This handler is currently not called.
HandleChangeWorld(before, after *world.World)
// HandleToggleSprint handles when the player starts or stops sprinting.
// After is true if the player is sprinting after toggling (changing their sprinting state).
Expand Down
9 changes: 8 additions & 1 deletion server/player/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ type playerData struct {
hunger *hungerManager

once sync.Once

prevWorld *world.World
}

// Player is an implementation of a player entity. It has methods that implement the behaviour that players
Expand Down Expand Up @@ -2291,7 +2293,7 @@ func (p *Player) Latency() time.Duration {
}

// Tick ticks the entity, performing actions such as checking if the player is still breaking a block.
func (p *Player) Tick(_ *world.Tx, current int64) {
func (p *Player) Tick(tx *world.Tx, current int64) {
if p.Dead() {
return
}
Expand Down Expand Up @@ -2352,6 +2354,11 @@ func (p *Player) Tick(_ *world.Tx, current int64) {
}
}

if p.prevWorld != tx.World() && p.prevWorld != nil {
p.Handler().HandleChangeWorld(p.prevWorld, tx.World())
p.prevWorld = tx.World()
}

if p.session() == session.Nop && !p.Immobile() {
m := p.mc.TickMovement(p, p.Position(), p.Velocity(), p.Rotation(), p.tx)
m.Send()
Expand Down

0 comments on commit e920e59

Please sign in to comment.