-
Notifications
You must be signed in to change notification settings - Fork 6
/
interact.go
56 lines (49 loc) · 1.63 KB
/
interact.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
51
52
53
54
55
56
package packet
import (
"dotcs/minecraft/protocol"
"github.com/go-gl/mathgl/mgl32"
)
const (
_ = iota + 1
_
InteractActionLeaveVehicle
InteractActionMouseOverEntity
InteractActionNPCOpen
InteractActionOpenInventory
)
// Interact is sent by the client when it interacts with another entity in some way. It used to be used for
// normal entity and block interaction, but this is no longer the case now.
type Interact struct {
// Action type is the ID of the action that was executed by the player. It is one of the constants that
// may be found above.
ActionType byte
// TargetEntityRuntimeID is the runtime ID of the entity that the player interacted with. This is empty
// for the InteractActionOpenInventory action type.
TargetEntityRuntimeID uint64
// Position associated with the ActionType above. For the InteractActionMouseOverEntity, this is the
// position relative to the entity moused over over which the player hovered with its mouse/touch. For the
// InteractActionLeaveVehicle, this is the position that the player spawns at after leaving the vehicle.
Position mgl32.Vec3
}
// ID ...
func (*Interact) ID() uint32 {
return IDInteract
}
// Marshal ...
func (pk *Interact) Marshal(w *protocol.Writer) {
w.Uint8(&pk.ActionType)
w.Varuint64(&pk.TargetEntityRuntimeID)
switch pk.ActionType {
case InteractActionMouseOverEntity, InteractActionLeaveVehicle:
w.Vec3(&pk.Position)
}
}
// Unmarshal ...
func (pk *Interact) Unmarshal(r *protocol.Reader) {
r.Uint8(&pk.ActionType)
r.Varuint64(&pk.TargetEntityRuntimeID)
switch pk.ActionType {
case InteractActionMouseOverEntity, InteractActionLeaveVehicle:
r.Vec3(&pk.Position)
}
}