Fix default spawn packet layout
This commit is contained in:
parent
cbd5c7b546
commit
6413216876
2 changed files with 45 additions and 1 deletions
|
|
@ -72,9 +72,13 @@ func (h *handler) sendChunkCacheCenter(cx, cz int32) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *handler) sendDefaultSpawnPosition() error {
|
func (h *handler) sendDefaultSpawnPosition() error {
|
||||||
w := protocol.NewWriter(12)
|
// 26.1.2 wraps the spawn in LevelData.RespawnData: GlobalPos followed by
|
||||||
|
// yaw and pitch. GlobalPos starts with the dimension resource key.
|
||||||
|
w := protocol.NewWriter(40)
|
||||||
|
w.String("minecraft:overworld")
|
||||||
w.Position(8, 100, 8)
|
w.Position(8, 100, 8)
|
||||||
w.Float32(0.0)
|
w.Float32(0.0)
|
||||||
|
w.Float32(0.0)
|
||||||
return h.conn.SendWriter(protocol.PlayDefaultSpawnPos, w)
|
return h.conn.SendWriter(protocol.PlayDefaultSpawnPos, w)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
40
internal/network/play_spawn_test.go
Normal file
40
internal/network/play_spawn_test.go
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
package network
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"regionio/internal/protocol"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSendDefaultSpawnPositionLayout(t *testing.T) {
|
||||||
|
recorder := &recordingConn{}
|
||||||
|
h := &handler{conn: NewConn(recorder)}
|
||||||
|
|
||||||
|
if err := h.sendDefaultSpawnPosition(); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
packets := recorder.take(t)
|
||||||
|
if len(packets) != 1 {
|
||||||
|
t.Fatalf("packet count = %d, want 1", len(packets))
|
||||||
|
}
|
||||||
|
if packets[0].ID != protocol.PlayDefaultSpawnPos {
|
||||||
|
t.Fatalf("packet ID = %#x, want %#x", packets[0].ID, protocol.PlayDefaultSpawnPos)
|
||||||
|
}
|
||||||
|
|
||||||
|
r := protocol.NewReader(packets[0].Data)
|
||||||
|
if dimension, err := r.String(); err != nil || dimension != "minecraft:overworld" {
|
||||||
|
t.Fatalf("dimension = %q, %v; want minecraft:overworld", dimension, err)
|
||||||
|
}
|
||||||
|
if x, y, z, err := r.Position(); err != nil || x != 8 || y != 100 || z != 8 {
|
||||||
|
t.Fatalf("position = (%d, %d, %d), %v; want (8, 100, 8)", x, y, z, err)
|
||||||
|
}
|
||||||
|
if yaw, err := r.Float32(); err != nil || yaw != 0 {
|
||||||
|
t.Fatalf("yaw = %v, %v; want 0", yaw, err)
|
||||||
|
}
|
||||||
|
if pitch, err := r.Float32(); err != nil || pitch != 0 {
|
||||||
|
t.Fatalf("pitch = %v, %v; want 0", pitch, err)
|
||||||
|
}
|
||||||
|
if remaining := r.Remaining(); remaining != 0 {
|
||||||
|
t.Fatalf("remaining bytes = %d, want 0", remaining)
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue