/
respawn.go
50 lines (43 loc) · 1.6 KB
/
respawn.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package packet
import (
"github.com/go-gl/mathgl/mgl32"
"github.com/sandertv/gophertunnel/minecraft/protocol"
)
const (
// Respawn packets with these states are sent by the server.
RespawnStateSearchingForSpawn = iota
RespawnStateReadyToSpawn
// A Respawn packet with this state is sent by the client.
RespawnStateClientReadyToSpawn
)
// Respawn is sent by the server to make a player respawn client-side. It is sent in response to a
// PlayerAction packet with ActionType PlayerActionRespawn.
// As of 1.13, the server sends two of these packets with different states, and the client sends one of these
// back in order to complete the respawn.
type Respawn struct {
// Position is the position on which the player should be respawned. The position might be in a different
// dimension, in which case the client should first be sent a ChangeDimension packet.
Position mgl32.Vec3
// State is the 'state' of the respawn. It is one of the constants that may be found above, and the value
// the packet contains depends on whether the server or client sends it.
State byte
// EntityRuntimeID is the entity runtime ID of the player that the respawn packet concerns. This is
// apparently for the server to recognise which player sends this packet.
EntityRuntimeID uint64
}
// ID ...
func (*Respawn) ID() uint32 {
return IDRespawn
}
// Marshal ...
func (pk *Respawn) Marshal(w *protocol.Writer) {
w.Vec3(&pk.Position)
w.Uint8(&pk.State)
w.Varuint64(&pk.EntityRuntimeID)
}
// Unmarshal ...
func (pk *Respawn) Unmarshal(r *protocol.Reader) {
r.Vec3(&pk.Position)
r.Uint8(&pk.State)
r.Varuint64(&pk.EntityRuntimeID)
}