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;
48 public const ABILITY_VERTICAL_FLY_SPEED = 19;
50 public const NUMBER_OF_ABILITIES = 20;
58 private array $boolAbilities,
59 private ?
float $flySpeed,
60 private ?
float $verticalFlySpeed,
61 private ?
float $walkSpeed
64 public function getLayerId() : int{ return $this->layerId; }
73 public function getFlySpeed() : ?float{ return $this->flySpeed; }
75 public function getVerticalFlySpeed() : ?float{ return $this->verticalFlySpeed; }
77 public function getWalkSpeed() : ?float{ return $this->walkSpeed; }
79 public static function decode(PacketSerializer $in) : self{
80 $layerId = $in->getLShort();
81 $setAbilities = $in->getLInt();
82 $setAbilityValues = $in->getLInt();
83 $flySpeed = $in->getLFloat();
84 $verticalFlySpeed = $in->getLFloat();
85 $walkSpeed = $in->getLFloat();
88 for($i = 0; $i < self::NUMBER_OF_ABILITIES; $i++){
89 if($i === self::ABILITY_FLY_SPEED || $i === self::ABILITY_WALK_SPEED){
92 if(($setAbilities & (1 << $i)) !== 0){
93 $boolAbilities[$i] = ($setAbilityValues & (1 << $i)) !== 0;
96 if(($setAbilities & (1 << self::ABILITY_FLY_SPEED)) === 0){
97 if($flySpeed !== 0.0){
98 throw new PacketDecodeException(
"Fly speed should be zero if the layer does not set it");
102 if(($setAbilities & (1 << self::ABILITY_VERTICAL_FLY_SPEED)) === 0){
103 if($verticalFlySpeed !== 0.0){
104 throw new PacketDecodeException(
"Vertical fly speed should be zero if the layer does not set it");
106 $verticalFlySpeed =
null;
108 if(($setAbilities & (1 << self::ABILITY_WALK_SPEED)) === 0){
109 if($walkSpeed !== 0.0){
110 throw new PacketDecodeException(
"Walk speed should be zero if the layer does not set it");
115 return new self($layerId, $boolAbilities, $flySpeed, $verticalFlySpeed, $walkSpeed);
118 public function encode(PacketSerializer $out) : void{
119 $out->putLShort($this->layerId);
122 $setAbilityValues = 0;
123 foreach($this->boolAbilities as $ability => $value){
124 $setAbilities |= (1 << $ability);
125 $setAbilityValues |= ($value ? 1 << $ability : 0);
127 if($this->flySpeed !==
null){
128 $setAbilities |= (1 << self::ABILITY_FLY_SPEED);
130 if($this->verticalFlySpeed !==
null){
131 $setAbilities |= (1 << self::ABILITY_VERTICAL_FLY_SPEED);
133 if($this->walkSpeed !==
null){
134 $setAbilities |= (1 << self::ABILITY_WALK_SPEED);
137 $out->putLInt($setAbilities);
138 $out->putLInt($setAbilityValues);
139 $out->putLFloat($this->flySpeed ?? 0);
140 $out->putLFloat($this->verticalFlySpeed ?? 0);
141 $out->putLFloat($this->walkSpeed ?? 0);