-
-
Notifications
You must be signed in to change notification settings - Fork 89
/
ability.go
85 lines (78 loc) · 2.43 KB
/
ability.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
package protocol
const (
AbilityBuild = 1 << iota
AbilityMine
AbilityDoorsAndSwitches
AbilityOpenContainers
AbilityAttackPlayers
AbilityAttackMobs
AbilityOperatorCommands
AbilityTeleport
AbilityInvulnerable
AbilityFlying
AbilityMayFly
AbilityInstantBuild
AbilityLightning
AbilityFlySpeed
AbilityWalkSpeed
AbilityMuted
AbilityWorldBuilder
AbilityNoClip
AbilityPrivilegedBuilder
AbilityCount
)
const (
AbilityLayerTypeCustomCache = iota
AbilityLayerTypeBase
AbilityLayerTypeSpectator
AbilityLayerTypeCommands
AbilityLayerTypeEditor
)
const (
AbilityBaseFlySpeed = 0.05
AbilityBaseWalkSpeed = 0.1
)
// AbilityData represents various data about the abilities of a player, such as ability layers or permissions.
type AbilityData struct {
// EntityUniqueID is a unique identifier of the player. It appears it is not required to fill this field
// out with a correct value. Simply writing 0 seems to work.
EntityUniqueID int64
// PlayerPermissions is the permission level of the player as it shows up in the player list built up using
// the PlayerList packet.
PlayerPermissions byte
// CommandPermissions is a set of permissions that specify what commands a player is allowed to execute.
CommandPermissions byte
// Layers contains all ability layers and their potential values. This should at least have one entry, being the
// base layer.
Layers []AbilityLayer
}
// Marshal encodes/decodes an AbilityData.
func (x *AbilityData) Marshal(r IO) {
r.Int64(&x.EntityUniqueID)
r.Uint8(&x.PlayerPermissions)
r.Uint8(&x.CommandPermissions)
SliceUint8Length(r, &x.Layers)
}
// AbilityLayer represents the abilities of a specific layer, such as the base layer or the spectator layer.
type AbilityLayer struct {
// Type represents the type of the layer. This is one of the AbilityLayerType constants defined above.
Type uint16
// Abilities is a set of abilities that are enabled for the layer. This is one of the Ability constants defined
// above.
Abilities uint32
// Values is a set of values that are associated with the enabled abilities, representing the values of the
// abilities.
Values uint32
// FlySpeed is the default fly speed of the layer.
FlySpeed float32
// WalkSpeed is the default walk speed of the layer.
WalkSpeed float32
}
// Marshal encodes/decodes an AbilityLayer.
func (x *AbilityLayer) Marshal(r IO) {
r.Uint16(&x.Type)
r.Uint32(&x.Abilities)
r.Uint32(&x.Values)
r.Float32(&x.FlySpeed)
r.Float32(&x.WalkSpeed)
}