1.21.111 support
This commit is contained in:
@@ -9,20 +9,8 @@ import (
|
||||
// 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
|
||||
// BodyDamage is the amount of damage that should be dealt to the body.
|
||||
BodyDamage int32
|
||||
// List ...
|
||||
List []protocol.PlayerArmourDamageEntry
|
||||
}
|
||||
|
||||
// ID ...
|
||||
@@ -31,33 +19,49 @@ func (pk *PlayerArmourDamage) ID() uint32 {
|
||||
}
|
||||
|
||||
func (pk *PlayerArmourDamage) Marshal(io protocol.IO) {
|
||||
io.Uint8(&pk.Bitset)
|
||||
if pk.Bitset&packet.PlayerArmourDamageFlagHelmet != 0 {
|
||||
io.Varint32(&pk.HelmetDamage)
|
||||
} else {
|
||||
pk.HelmetDamage = 0
|
||||
}
|
||||
if pk.Bitset&packet.PlayerArmourDamageFlagChestplate != 0 {
|
||||
io.Varint32(&pk.ChestplateDamage)
|
||||
} else {
|
||||
pk.ChestplateDamage = 0
|
||||
}
|
||||
if pk.Bitset&packet.PlayerArmourDamageFlagLeggings != 0 {
|
||||
io.Varint32(&pk.LeggingsDamage)
|
||||
} else {
|
||||
pk.LeggingsDamage = 0
|
||||
}
|
||||
if pk.Bitset&packet.PlayerArmourDamageFlagBoots != 0 {
|
||||
io.Varint32(&pk.BootsDamage)
|
||||
} else {
|
||||
pk.BootsDamage = 0
|
||||
}
|
||||
|
||||
if proto.IsProtoGTE(io, proto.ID712) {
|
||||
if pk.Bitset&packet.PlayerArmourDamageFlagBody != 0 {
|
||||
io.Varint32(&pk.BodyDamage)
|
||||
} else {
|
||||
pk.BodyDamage = 0
|
||||
if proto.IsProtoLT(io, proto.ID844) {
|
||||
var bitset uint8
|
||||
flags := []uint8{packet.PlayerArmourDamageFlagHelmet, packet.PlayerArmourDamageFlagChestplate, packet.PlayerArmourDamageFlagLeggings, packet.PlayerArmourDamageFlagBoots}
|
||||
if proto.IsProtoGTE(io, proto.ID712) {
|
||||
flags = append(flags, packet.PlayerArmourDamageFlagBody)
|
||||
}
|
||||
if proto.IsReader(io) {
|
||||
io.Uint8(&bitset)
|
||||
pk.List = make([]protocol.PlayerArmourDamageEntry, 0, len(flags))
|
||||
for _, flag := range flags {
|
||||
if bitset&flag != 0 {
|
||||
v := protocol.PlayerArmourDamageEntry{
|
||||
ArmourSlot: flag,
|
||||
}
|
||||
v2 := int32(0)
|
||||
io.Varint32(&v2)
|
||||
v.Damage = int16(v2)
|
||||
pk.List = append(pk.List, v)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
for _, entry := range pk.List {
|
||||
if entry.ArmourSlot == packet.PlayerArmourDamageFlagBody && !proto.IsProtoGTE(io, proto.ID712) {
|
||||
continue
|
||||
}
|
||||
bitset |= 1 << entry.ArmourSlot
|
||||
}
|
||||
io.Uint8(&bitset)
|
||||
for _, flag := range flags {
|
||||
if bitset&flag != 0 {
|
||||
damage := int32(0)
|
||||
for _, entry := range pk.List {
|
||||
if entry.ArmourSlot == flag {
|
||||
damage = int32(entry.Damage)
|
||||
break
|
||||
}
|
||||
}
|
||||
io.Varint32(&damage)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
protocol.SliceVarint32Length(io, &pk.List)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user