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;
27 private ?
int $headSlotDamage;
28 private ?
int $chestSlotDamage;
29 private ?
int $legsSlotDamage;
30 private ?
int $feetSlotDamage;
35 public static function create(?
int $headSlotDamage, ?
int $chestSlotDamage, ?
int $legsSlotDamage, ?
int $feetSlotDamage) : self{
37 $result->headSlotDamage = $headSlotDamage;
38 $result->chestSlotDamage = $chestSlotDamage;
39 $result->legsSlotDamage = $legsSlotDamage;
40 $result->feetSlotDamage = $feetSlotDamage;
44 public function getHeadSlotDamage() : ?int{ return $this->headSlotDamage; }
46 public function getChestSlotDamage() : ?int{ return $this->chestSlotDamage; }
48 public function getLegsSlotDamage() : ?int{ return $this->legsSlotDamage; }
50 public function getFeetSlotDamage() : ?int{ return $this->feetSlotDamage; }
52 private function maybeReadDamage(
int $flags,
int $flag, PacketSerializer $in) : ?int{
53 if(($flags & (1 << $flag)) !== 0){
54 return $in->getVarInt();
60 $flags = $in->getByte();
62 $this->headSlotDamage = $this->maybeReadDamage($flags, self::FLAG_HEAD, $in);
63 $this->chestSlotDamage = $this->maybeReadDamage($flags, self::FLAG_CHEST, $in);
64 $this->legsSlotDamage = $this->maybeReadDamage($flags, self::FLAG_LEGS, $in);
65 $this->feetSlotDamage = $this->maybeReadDamage($flags, self::FLAG_FEET, $in);
68 private function composeFlag(?
int $field,
int $flag) : int{
69 return $field !== null ? (1 << $flag) : 0;
72 private function maybeWriteDamage(?
int $field,
PacketSerializer $out) : void{
80 $this->composeFlag($this->headSlotDamage, self::FLAG_HEAD) |
81 $this->composeFlag($this->chestSlotDamage, self::FLAG_CHEST) |
82 $this->composeFlag($this->legsSlotDamage, self::FLAG_LEGS) |
83 $this->composeFlag($this->feetSlotDamage, self::FLAG_FEET)
86 $this->maybeWriteDamage($this->headSlotDamage, $out);
87 $this->maybeWriteDamage($this->chestSlotDamage, $out);
88 $this->maybeWriteDamage($this->legsSlotDamage, $out);
89 $this->maybeWriteDamage($this->feetSlotDamage, $out);
93 return $handler->handlePlayerArmorDamage($this);
handle(PacketHandlerInterface $handler)
static create(?int $headSlotDamage, ?int $chestSlotDamage, ?int $legsSlotDamage, ?int $feetSlotDamage)
decodePayload(PacketSerializer $in)
encodePayload(PacketSerializer $out)