diff --git a/src/block/utils/BlockDataSerializer.php b/src/block/utils/BlockDataSerializer.php index 1459e74f2..5a9eaadff 100644 --- a/src/block/utils/BlockDataSerializer.php +++ b/src/block/utils/BlockDataSerializer.php @@ -36,33 +36,33 @@ final class BlockDataSerializer{ * @throws InvalidBlockStateException */ public static function readFacing(int $raw) : int{ - static $map = [ //this is for redundancy, for when/if the FACING constant values change + $result = [ //this is for redundancy, for when/if the FACING constant values change 0 => Facing::DOWN, 1 => Facing::UP, 2 => Facing::NORTH, 3 => Facing::SOUTH, 4 => Facing::WEST, 5 => Facing::EAST - ]; - if(!isset($map[$raw])){ + ][$raw] ?? null; + if($result === null){ throw new InvalidBlockStateException("Invalid facing $raw"); } - return $map[$raw]; + return $result; } public static function writeFacing(int $facing) : int{ - static $map = [ //again, for redundancy + $result = [ //again, for redundancy Facing::DOWN => 0, Facing::UP => 1, Facing::NORTH => 2, Facing::SOUTH => 3, Facing::WEST => 4, Facing::EAST => 5 - ]; - if(!isset($map[$facing])){ + ][$facing] ?? null; + if($result === null){ throw new \InvalidArgumentException("Invalid facing $facing"); } - return $map[$facing]; + return $result; } /** @@ -87,29 +87,29 @@ final class BlockDataSerializer{ * @throws InvalidBlockStateException */ public static function readLegacyHorizontalFacing(int $raw) : int{ - static $map = [ //again, for redundancy + $result = [ //again, for redundancy 0 => Facing::SOUTH, 1 => Facing::WEST, 2 => Facing::NORTH, 3 => Facing::EAST - ]; - if(!isset($map[$raw])){ + ][$raw] ?? null; + if($result === null){ throw new InvalidBlockStateException("Invalid legacy facing $raw"); } - return $map[$raw]; + return $result; } public static function writeLegacyHorizontalFacing(int $facing) : int{ - static $map = [ + $result = [ Facing::SOUTH => 0, Facing::WEST => 1, Facing::NORTH => 2, Facing::EAST => 3 - ]; - if(!isset($map[$facing])){ + ][$facing] ?? null; + if($result === null){ throw new \InvalidArgumentException("Invalid Y-axis facing"); } - return $map[$facing]; + return $result; } /** diff --git a/src/block/utils/PillarRotationTrait.php b/src/block/utils/PillarRotationTrait.php index 8685ddb57..7ae8f8cc6 100644 --- a/src/block/utils/PillarRotationTrait.php +++ b/src/block/utils/PillarRotationTrait.php @@ -62,25 +62,24 @@ trait PillarRotationTrait{ } protected function readAxisFromMeta(int $meta) : void{ - static $map = [ + $axis = $meta >> $this->getAxisMetaShift(); + $mapped = [ 0 => Axis::Y, 1 => Axis::X, 2 => Axis::Z - ]; - $axis = $meta >> $this->getAxisMetaShift(); - if(!isset($map[$axis])){ + ][$axis] ?? null; + if($mapped === null){ throw new InvalidBlockStateException("Invalid axis meta $axis"); } - $this->axis = $map[$axis]; + $this->axis = $mapped; } protected function writeAxisToMeta() : int{ - static $bits = [ + return [ Axis::Y => 0, Axis::Z => 2, Axis::X => 1 - ]; - return $bits[$this->axis] << $this->getAxisMetaShift(); + ][$this->axis] << $this->getAxisMetaShift(); } /**