13declare(strict_types=1);
15namespace pocketmine\network\mcpe\protocol;
27 public const NETWORK_ID = ProtocolInfo::REQUEST_ABILITY_PACKET;
29 private const VALUE_TYPE_BOOL = 1;
30 private const VALUE_TYPE_FLOAT = 2;
32 public const ABILITY_FLYING = 9;
33 public const ABILITY_NOCLIP = 17;
35 private int $abilityId;
36 private float|
bool $abilityValue;
41 public static function create(
int $abilityId,
float|
bool $abilityValue) : self{
43 $result->abilityId = $abilityId;
44 $result->abilityValue = $abilityValue;
48 public function getAbilityId() : int{ return $this->abilityId; }
50 public function getAbilityValue() : float|bool{ return $this->abilityValue; }
53 $this->abilityId = $in->getVarInt();
62 $this->abilityValue = match($valueType){
63 self::VALUE_TYPE_BOOL => $boolValue,
64 self::VALUE_TYPE_FLOAT => $floatValue,
70 $out->putVarInt($this->abilityId);
72 [$valueType, $boolValue, $floatValue] = match(
true){
73 is_bool($this->abilityValue) => [self::VALUE_TYPE_BOOL, $this->abilityValue, 0.0],
74 is_float($this->abilityValue) => [self::VALUE_TYPE_FLOAT,
false, $this->abilityValue],
75 default =>
throw new \LogicException(
"Unreachable")
77 $out->putByte($valueType);
78 $out->putBool($boolValue);
79 $out->putLFloat($floatValue);
83 return $handler->handleRequestAbility($this);
decodePayload(PacketSerializer $in)
handle(PacketHandlerInterface $handler)
static create(int $abilityId, float|bool $abilityValue)
encodePayload(PacketSerializer $out)