-
-
Notifications
You must be signed in to change notification settings - Fork 89
/
player_auth_input.go
174 lines (161 loc) · 5.3 KB
/
player_auth_input.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
package packet
import (
"github.com/go-gl/mathgl/mgl32"
"github.com/sandertv/gophertunnel/minecraft/protocol"
)
const (
InputFlagAscend = 1 << iota
InputFlagDescend
InputFlagNorthJump
InputFlagJumpDown
InputFlagSprintDown
InputFlagChangeHeight
InputFlagJumping
InputFlagAutoJumpingInWater
InputFlagSneaking
InputFlagSneakDown
InputFlagUp
InputFlagDown
InputFlagLeft
InputFlagRight
InputFlagUpLeft
InputFlagUpRight
InputFlagWantUp
InputFlagWantDown
InputFlagWantDownSlow
InputFlagWantUpSlow
InputFlagSprinting
InputFlagAscendBlock
InputFlagDescendBlock
InputFlagSneakToggleDown
InputFlagPersistSneak
InputFlagStartSprinting
InputFlagStopSprinting
InputFlagStartSneaking
InputFlagStopSneaking
InputFlagStartSwimming
InputFlagStopSwimming
InputFlagStartJumping
InputFlagStartGliding
InputFlagStopGliding
InputFlagPerformItemInteraction
InputFlagPerformBlockActions
InputFlagPerformItemStackRequest
InputFlagHandledTeleport
InputFlagEmoting
InputFlagMissedSwing
InputFlagStartCrawling
InputFlagStopCrawling
InputFlagStartFlying
InputFlagStopFlying
InputFlagClientAckServerData
InputFlagClientPredictedVehicle
InputFlagPaddlingLeft
InputFlagPaddlingRight
)
const (
InputModeMouse = iota + 1
InputModeTouch
InputModeGamePad
InputModeMotionController
)
const (
PlayModeNormal = iota
PlayModeTeaser
PlayModeScreen
PlayModeViewer
PlayModeReality
PlayModePlacement
PlayModeLivingRoom
PlayModeExitLevel
PlayModeExitLevelLivingRoom
PlayModeNumModes
)
const (
InteractionModelTouch = iota
InteractionModelCrosshair
InteractionModelClassic
)
// PlayerAuthInput is sent by the client to allow for server authoritative movement. It is used to synchronise
// the player input with the position server-side.
// The client sends this packet when the ServerAuthoritativeMovementMode field in the StartGame packet is set
// to true, instead of the MovePlayer packet. The client will send this packet once every tick.
type PlayerAuthInput struct {
// Pitch and Yaw hold the rotation that the player reports it has.
Pitch, Yaw float32
// Position holds the position that the player reports it has.
Position mgl32.Vec3
// MoveVector is a Vec2 that specifies the direction in which the player moved, as a combination of X/Z
// values which are created using the WASD/controller stick state.
MoveVector mgl32.Vec2
// HeadYaw is the horizontal rotation of the head that the player reports it has.
HeadYaw float32
// InputData is a combination of bit flags that together specify the way the player moved last tick. It
// is a combination of the flags above.
InputData uint64
// InputMode specifies the way that the client inputs data to the screen. It is one of the constants that
// may be found above.
InputMode uint32
// PlayMode specifies the way that the player is playing. The values it holds, which are rather random,
// may be found above.
PlayMode uint32
// InteractionModel is a constant representing the interaction model the player is using. It is one of the
// constants that may be found above.
InteractionModel uint32
// GazeDirection is the direction in which the player is gazing, when the PlayMode is PlayModeReality: In
// other words, when the player is playing in virtual reality.
GazeDirection mgl32.Vec3
// Tick is the server tick at which the packet was sent. It is used in relation to
// CorrectPlayerMovePrediction.
Tick uint64
// Delta was the delta between the old and the new position. There isn't any practical use for this field
// as it can be calculated by the server itself.
Delta mgl32.Vec3
// ItemInteractionData is the transaction data if the InputData includes an item interaction.
ItemInteractionData protocol.UseItemTransactionData
// ItemStackRequest is sent by the client to change an item in their inventory.
ItemStackRequest protocol.ItemStackRequest
// BlockActions is a slice of block actions that the client has interacted with.
BlockActions []protocol.PlayerBlockAction
// VehicleRotation is the rotation of the vehicle that the player is in, if any.
VehicleRotation mgl32.Vec2
// ClientPredictedVehicle is the unique ID of the vehicle that the client predicts the player to be in.
ClientPredictedVehicle int64
// AnalogueMoveVector is a Vec2 that specifies the direction in which the player moved, as a combination
// of X/Z values which are created using an analogue input.
AnalogueMoveVector mgl32.Vec2
}
// ID ...
func (pk *PlayerAuthInput) ID() uint32 {
return IDPlayerAuthInput
}
func (pk *PlayerAuthInput) Marshal(io protocol.IO) {
io.Float32(&pk.Pitch)
io.Float32(&pk.Yaw)
io.Vec3(&pk.Position)
io.Vec2(&pk.MoveVector)
io.Float32(&pk.HeadYaw)
io.Varuint64(&pk.InputData)
io.Varuint32(&pk.InputMode)
io.Varuint32(&pk.PlayMode)
io.Varuint32(&pk.InteractionModel)
if pk.PlayMode == PlayModeReality {
io.Vec3(&pk.GazeDirection)
}
io.Varuint64(&pk.Tick)
io.Vec3(&pk.Delta)
if pk.InputData&InputFlagPerformItemInteraction != 0 {
io.PlayerInventoryAction(&pk.ItemInteractionData)
}
if pk.InputData&InputFlagPerformItemStackRequest != 0 {
protocol.Single(io, &pk.ItemStackRequest)
}
if pk.InputData&InputFlagClientPredictedVehicle != 0 {
io.Vec2(&pk.VehicleRotation)
io.Varint64(&pk.ClientPredictedVehicle)
}
if pk.InputData&InputFlagPerformBlockActions != 0 {
protocol.SliceVarint32Length(io, &pk.BlockActions)
}
io.Vec2(&pk.AnalogueMoveVector)
}