/
player_armour_damage.go
77 lines (72 loc) · 1.99 KB
/
player_armour_damage.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
package packet
import (
"github.com/sandertv/gophertunnel/minecraft/protocol"
)
// PlayerArmourDamage is sent by the server to damage the armour of a player. It is a very efficient packet,
// but generally it's much easier to just send a slot update for the damaged armour.
type PlayerArmourDamage struct {
// Bitset holds a bitset of 4 bits that indicate which pieces of armour need to have damage dealt to them.
// The first bit, when toggled, is for a helmet, the second for the chestplate, the third for the leggings
// and the fourth for boots.
Bitset uint8
// HelmetDamage is the amount of damage that should be dealt to the helmet.
HelmetDamage int32
// ChestplateDamage is the amount of damage that should be dealt to the chestplate.
ChestplateDamage int32
// LeggingsDamage is the amount of damage that should be dealt to the leggings.
LeggingsDamage int32
// BootsDamage is the amount of damage that should be dealt to the boots.
BootsDamage int32
}
// ID ...
func (pk *PlayerArmourDamage) ID() uint32 {
return IDPlayerArmourDamage
}
// Marshal ...
func (pk *PlayerArmourDamage) Marshal(w *protocol.Writer) {
w.Uint8(&pk.Bitset)
if pk.Bitset&0b0001 != 0 {
w.Varint32(&pk.HelmetDamage)
} else {
pk.HelmetDamage = 0
}
if pk.Bitset&0b0010 != 0 {
w.Varint32(&pk.ChestplateDamage)
} else {
pk.ChestplateDamage = 0
}
if pk.Bitset&0b0100 != 0 {
w.Varint32(&pk.LeggingsDamage)
} else {
pk.LeggingsDamage = 0
}
if pk.Bitset&0b1000 != 0 {
w.Varint32(&pk.BootsDamage)
} else {
pk.BootsDamage = 0
}
}
// Unmarshal ...
func (pk *PlayerArmourDamage) Unmarshal(r *protocol.Reader) {
r.Uint8(&pk.Bitset)
if pk.Bitset&0b0001 != 0 {
r.Varint32(&pk.HelmetDamage)
} else {
pk.HelmetDamage = 0
}
if pk.Bitset&0b0010 != 0 {
r.Varint32(&pk.ChestplateDamage)
} else {
pk.ChestplateDamage = 0
}
if pk.Bitset&0b0100 != 0 {
r.Varint32(&pk.LeggingsDamage)
} else {
pk.LeggingsDamage = 0
}
if pk.Bitset&0b1000 != 0 {
r.Varint32(&pk.BootsDamage)
} else {
pk.BootsDamage = 0
}
}