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;
27 public const LAYER_LOADING_SCREEN = 5;
29 public const ABILITY_BUILD = 0;
30 public const ABILITY_MINE = 1;
31 public const ABILITY_DOORS_AND_SWITCHES = 2;
32 public const ABILITY_OPEN_CONTAINERS = 3;
33 public const ABILITY_ATTACK_PLAYERS = 4;
34 public const ABILITY_ATTACK_MOBS = 5;
35 public const ABILITY_OPERATOR = 6;
36 public const ABILITY_TELEPORT = 7;
37 public const ABILITY_INVULNERABLE = 8;
38 public const ABILITY_FLYING = 9;
39 public const ABILITY_ALLOW_FLIGHT = 10;
40 public const ABILITY_INFINITE_RESOURCES = 11;
41 public const ABILITY_LIGHTNING = 12;
42 private const ABILITY_FLY_SPEED = 13;
43 private const ABILITY_WALK_SPEED = 14;
44 public const ABILITY_MUTED = 15;
45 public const ABILITY_WORLD_BUILDER = 16;
46 public const ABILITY_NO_CLIP = 17;
47 public const ABILITY_PRIVILEGED_BUILDER = 18;
49 public const NUMBER_OF_ABILITIES = 19;
57 private array $boolAbilities,
58 private ?
float $flySpeed,
59 private ?
float $walkSpeed
62 public function getLayerId() : int{ return $this->layerId; }
71 public function getFlySpeed() : ?float{ return $this->flySpeed; }
73 public function getWalkSpeed() : ?float{ return $this->walkSpeed; }
76 $layerId = $in->getLShort();
78 $setAbilityValues = $in->
getLInt();
83 for($i = 0; $i < self::NUMBER_OF_ABILITIES; $i++){
84 if($i === self::ABILITY_FLY_SPEED || $i === self::ABILITY_WALK_SPEED){
87 if(($setAbilities & (1 << $i)) !== 0){
88 $boolAbilities[$i] = ($setAbilityValues & (1 << $i)) !== 0;
91 if(($setAbilities & (1 << self::ABILITY_FLY_SPEED)) === 0){
92 if($flySpeed !== 0.0){
93 throw new PacketDecodeException(
"Fly speed should be zero if the layer does not set it");
97 if(($setAbilities & (1 << self::ABILITY_WALK_SPEED)) === 0){
98 if($walkSpeed !== 0.0){
99 throw new PacketDecodeException(
"Walk speed should be zero if the layer does not set it");
104 return new self($layerId, $boolAbilities, $flySpeed, $walkSpeed);
107 public function encode(PacketSerializer $out) : void{
108 $out->putLShort($this->layerId);
111 $setAbilityValues = 0;
112 foreach($this->boolAbilities as $ability => $value){
113 $setAbilities |= (1 << $ability);
114 $setAbilityValues |= ($value ? 1 << $ability : 0);
116 if($this->flySpeed !==
null){
117 $setAbilities |= (1 << self::ABILITY_FLY_SPEED);
119 if($this->walkSpeed !==
null){
120 $setAbilities |= (1 << self::ABILITY_WALK_SPEED);
123 $out->putLInt($setAbilities);
124 $out->putLInt($setAbilityValues);
125 $out->putLFloat($this->flySpeed ?? 0);
126 $out->putLFloat($this->walkSpeed ?? 0);