13declare(strict_types=1);
15namespace pocketmine\network\mcpe\protocol;
20 public const NETWORK_ID = ProtocolInfo::PLAYER_ARMOR_DAMAGE_PACKET;
22 private const FLAG_HEAD = 0;
23 private const FLAG_CHEST = 1;
24 private const FLAG_LEGS = 2;
25 private const FLAG_FEET = 3;
26 private const FLAG_BODY = 4;
28 private ?
int $headSlotDamage;
29 private ?
int $chestSlotDamage;
30 private ?
int $legsSlotDamage;
31 private ?
int $feetSlotDamage;
32 private ?
int $bodySlotDamage;
37 public static function create(?
int $headSlotDamage, ?
int $chestSlotDamage, ?
int $legsSlotDamage, ?
int $feetSlotDamage, ?
int $bodySlotDamage) : self{
39 $result->headSlotDamage = $headSlotDamage;
40 $result->chestSlotDamage = $chestSlotDamage;
41 $result->legsSlotDamage = $legsSlotDamage;
42 $result->feetSlotDamage = $feetSlotDamage;
43 $result->bodySlotDamage = $bodySlotDamage;
47 public function getHeadSlotDamage() : ?int{ return $this->headSlotDamage; }
49 public function getChestSlotDamage() : ?int{ return $this->chestSlotDamage; }
51 public function getLegsSlotDamage() : ?int{ return $this->legsSlotDamage; }
53 public function getFeetSlotDamage() : ?int{ return $this->feetSlotDamage; }
55 public function getBodySlotDamage() : ?int{ return $this->bodySlotDamage; }
57 private function maybeReadDamage(
int $flags,
int $flag, PacketSerializer $in) : ?int{
58 if(($flags & (1 << $flag)) !== 0){
59 return $in->getVarInt();
65 $flags = $in->getByte();
67 $this->headSlotDamage = $this->maybeReadDamage($flags, self::FLAG_HEAD, $in);
68 $this->chestSlotDamage = $this->maybeReadDamage($flags, self::FLAG_CHEST, $in);
69 $this->legsSlotDamage = $this->maybeReadDamage($flags, self::FLAG_LEGS, $in);
70 $this->feetSlotDamage = $this->maybeReadDamage($flags, self::FLAG_FEET, $in);
71 $this->bodySlotDamage = $this->maybeReadDamage($flags, self::FLAG_BODY, $in);
74 private function composeFlag(?
int $field,
int $flag) : int{
75 return $field !== null ? (1 << $flag) : 0;
78 private function maybeWriteDamage(?
int $field,
PacketSerializer $out) : void{
86 $this->composeFlag($this->headSlotDamage, self::FLAG_HEAD) |
87 $this->composeFlag($this->chestSlotDamage, self::FLAG_CHEST) |
88 $this->composeFlag($this->legsSlotDamage, self::FLAG_LEGS) |
89 $this->composeFlag($this->feetSlotDamage, self::FLAG_FEET) |
90 $this->composeFlag($this->bodySlotDamage, self::FLAG_BODY)
93 $this->maybeWriteDamage($this->headSlotDamage, $out);
94 $this->maybeWriteDamage($this->chestSlotDamage, $out);
95 $this->maybeWriteDamage($this->legsSlotDamage, $out);
96 $this->maybeWriteDamage($this->feetSlotDamage, $out);
97 $this->maybeWriteDamage($this->bodySlotDamage, $out);
101 return $handler->handlePlayerArmorDamage($this);
handle(PacketHandlerInterface $handler)
decodePayload(PacketSerializer $in)
encodePayload(PacketSerializer $out)
static create(?int $headSlotDamage, ?int $chestSlotDamage, ?int $legsSlotDamage, ?int $feetSlotDamage, ?int $bodySlotDamage)