diff options
| author | raven <citrons@mondecitronne.com> | 2026-03-24 18:35:05 -0500 |
|---|---|---|
| committer | raven <citrons@mondecitronne.com> | 2026-03-24 18:35:05 -0500 |
| commit | 80c73873aa09f7f4cc825aa65269b7650993574c (patch) | |
| tree | 3dfb8e9baec843e0d5902bc7d8b1f1045a128f2a /server | |
| parent | b10ba4c11247a09364daf1ad25a17ac7beb7e54d (diff) | |
send movement updates less frequently
Diffstat (limited to 'server')
| -rw-r--r-- | server/player.go | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/server/player.go b/server/player.go index c4fac5c..358381d 100644 --- a/server/player.go +++ b/server/player.go @@ -4,6 +4,7 @@ import ( "io" "os" "fmt" + "time" "regexp" "slices" "strings" @@ -20,6 +21,7 @@ type player struct { extensions map[string]bool level *level levelLoaded bool + lastMovementUpdate time.Time currentMessage string } @@ -116,10 +118,18 @@ func (p *player) handlePacket(packet classic.Packet) { } switch pck := packet.(type) { case *classic.SetPosFacingExt: - p.state.Pos = entityPos { + newPos := entityPos { entityCoord(pck.X), entityCoord(pck.Y), entityCoord(pck.Z), } - p.state.Facing = entityFacing {pck.Yaw, pck.Pitch} + newFacing := entityFacing {pck.Yaw, pck.Pitch} + if newPos == p.state.Pos && newFacing == p.state.Facing { + if time.Since(p.lastMovementUpdate) < time.Second { + break + } + } + p.lastMovementUpdate = time.Now() + p.state.Pos = newPos + p.state.Facing = newFacing p.level.OnMovePlayer(p, p.state.Pos, p.state.Facing) case *classic.ClientSetBlock: block := blockType(pck.Block) |
