/
player_action.go
43 lines (38 loc) · 1.45 KB
/
player_action.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
package packet
import (
"github.com/sandertv/gophertunnel/minecraft/protocol"
)
// PlayerAction is sent by the client when it executes any action, for example starting to sprint, swim,
// starting the breaking of a block, dropping an item, etc.
type PlayerAction struct {
// EntityRuntimeID is the runtime ID of the player. The runtime ID is unique for each world session, and
// entities are generally identified in packets using this runtime ID.
EntityRuntimeID uint64
// ActionType is the ID of the action that was executed by the player. It is one of the constants that may
// be found in protocol/player.go.
ActionType int32
// BlockPosition is the position of the target block, if the action with the ActionType set concerned a
// block. If that is not the case, the block position will be zero.
BlockPosition protocol.BlockPos
// BlockFace is the face of the target block that was touched. If the action with the ActionType set
// concerned a block. If not, the face is always 0.
BlockFace int32
}
// ID ...
func (*PlayerAction) ID() uint32 {
return IDPlayerAction
}
// Marshal ...
func (pk *PlayerAction) Marshal(w *protocol.Writer) {
w.Varuint64(&pk.EntityRuntimeID)
w.Varint32(&pk.ActionType)
w.UBlockPos(&pk.BlockPosition)
w.Varint32(&pk.BlockFace)
}
// Unmarshal ...
func (pk *PlayerAction) Unmarshal(r *protocol.Reader) {
r.Varuint64(&pk.EntityRuntimeID)
r.Varint32(&pk.ActionType)
r.UBlockPos(&pk.BlockPosition)
r.Varint32(&pk.BlockFace)
}