13declare(strict_types=1);
15namespace pocketmine\network\mcpe\protocol\types;
22 public const LAYER_CACHE = 0;
23 public const LAYER_BASE = 1;
24 public const LAYER_SPECTATOR = 2;
25 public const LAYER_COMMANDS = 3;
26 public const LAYER_EDITOR = 4;
28 public const ABILITY_BUILD = 0;
29 public const ABILITY_MINE = 1;
30 public const ABILITY_DOORS_AND_SWITCHES = 2;
31 public const ABILITY_OPEN_CONTAINERS = 3;
32 public const ABILITY_ATTACK_PLAYERS = 4;
33 public const ABILITY_ATTACK_MOBS = 5;
34 public const ABILITY_OPERATOR = 6;
35 public const ABILITY_TELEPORT = 7;
36 public const ABILITY_INVULNERABLE = 8;
37 public const ABILITY_FLYING = 9;
38 public const ABILITY_ALLOW_FLIGHT = 10;
39 public const ABILITY_INFINITE_RESOURCES = 11;
40 public const ABILITY_LIGHTNING = 12;
41 private const ABILITY_FLY_SPEED = 13;
42 private const ABILITY_WALK_SPEED = 14;
43 public const ABILITY_MUTED = 15;
44 public const ABILITY_WORLD_BUILDER = 16;
45 public const ABILITY_NO_CLIP = 17;
46 public const ABILITY_PRIVILEGED_BUILDER = 18;
48 public const NUMBER_OF_ABILITIES = 19;
56 private array $boolAbilities,
57 private ?
float $flySpeed,
58 private ?
float $walkSpeed
61 public function getLayerId() : int{ return $this->layerId; }
70 public function getFlySpeed() : ?float{ return $this->flySpeed; }
72 public function getWalkSpeed() : ?float{ return $this->walkSpeed; }
75 $layerId = $in->getLShort();
77 $setAbilityValues = $in->
getLInt();
82 for($i = 0; $i < self::NUMBER_OF_ABILITIES; $i++){
83 if($i === self::ABILITY_FLY_SPEED || $i === self::ABILITY_WALK_SPEED){
86 if(($setAbilities & (1 << $i)) !== 0){
87 $boolAbilities[$i] = ($setAbilityValues & (1 << $i)) !== 0;
90 if(($setAbilities & (1 << self::ABILITY_FLY_SPEED)) === 0){
91 if($flySpeed !== 0.0){
92 throw new PacketDecodeException(
"Fly speed should be zero if the layer does not set it");
96 if(($setAbilities & (1 << self::ABILITY_WALK_SPEED)) === 0){
97 if($walkSpeed !== 0.0){
98 throw new PacketDecodeException(
"Walk speed should be zero if the layer does not set it");
103 return new self($layerId, $boolAbilities, $flySpeed, $walkSpeed);
106 public function encode(PacketSerializer $out) : void{
107 $out->putLShort($this->layerId);
110 $setAbilityValues = 0;
111 foreach($this->boolAbilities as $ability => $value){
112 $setAbilities |= (1 << $ability);
113 $setAbilityValues |= ($value ? 1 << $ability : 0);
115 if($this->flySpeed !==
null){
116 $setAbilities |= (1 << self::ABILITY_FLY_SPEED);
118 if($this->walkSpeed !==
null){
119 $setAbilities |= (1 << self::ABILITY_WALK_SPEED);
122 $out->putLInt($setAbilities);
123 $out->putLInt($setAbilityValues);
124 $out->putLFloat($this->flySpeed ?? 0);
125 $out->putLFloat($this->walkSpeed ?? 0);
__construct(private int $layerId, private array $boolAbilities, private ?float $flySpeed, private ?float $walkSpeed)