mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-04 09:10:00 +00:00
drop a few more useless static variables
phpstan is better able to understand constant literals, since it knows their types will never change.
This commit is contained in:
parent
b96565faa4
commit
6054104ecb
@ -36,33 +36,33 @@ final class BlockDataSerializer{
|
|||||||
* @throws InvalidBlockStateException
|
* @throws InvalidBlockStateException
|
||||||
*/
|
*/
|
||||||
public static function readFacing(int $raw) : int{
|
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,
|
0 => Facing::DOWN,
|
||||||
1 => Facing::UP,
|
1 => Facing::UP,
|
||||||
2 => Facing::NORTH,
|
2 => Facing::NORTH,
|
||||||
3 => Facing::SOUTH,
|
3 => Facing::SOUTH,
|
||||||
4 => Facing::WEST,
|
4 => Facing::WEST,
|
||||||
5 => Facing::EAST
|
5 => Facing::EAST
|
||||||
];
|
][$raw] ?? null;
|
||||||
if(!isset($map[$raw])){
|
if($result === null){
|
||||||
throw new InvalidBlockStateException("Invalid facing $raw");
|
throw new InvalidBlockStateException("Invalid facing $raw");
|
||||||
}
|
}
|
||||||
return $map[$raw];
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function writeFacing(int $facing) : int{
|
public static function writeFacing(int $facing) : int{
|
||||||
static $map = [ //again, for redundancy
|
$result = [ //again, for redundancy
|
||||||
Facing::DOWN => 0,
|
Facing::DOWN => 0,
|
||||||
Facing::UP => 1,
|
Facing::UP => 1,
|
||||||
Facing::NORTH => 2,
|
Facing::NORTH => 2,
|
||||||
Facing::SOUTH => 3,
|
Facing::SOUTH => 3,
|
||||||
Facing::WEST => 4,
|
Facing::WEST => 4,
|
||||||
Facing::EAST => 5
|
Facing::EAST => 5
|
||||||
];
|
][$facing] ?? null;
|
||||||
if(!isset($map[$facing])){
|
if($result === null){
|
||||||
throw new \InvalidArgumentException("Invalid facing $facing");
|
throw new \InvalidArgumentException("Invalid facing $facing");
|
||||||
}
|
}
|
||||||
return $map[$facing];
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -87,29 +87,29 @@ final class BlockDataSerializer{
|
|||||||
* @throws InvalidBlockStateException
|
* @throws InvalidBlockStateException
|
||||||
*/
|
*/
|
||||||
public static function readLegacyHorizontalFacing(int $raw) : int{
|
public static function readLegacyHorizontalFacing(int $raw) : int{
|
||||||
static $map = [ //again, for redundancy
|
$result = [ //again, for redundancy
|
||||||
0 => Facing::SOUTH,
|
0 => Facing::SOUTH,
|
||||||
1 => Facing::WEST,
|
1 => Facing::WEST,
|
||||||
2 => Facing::NORTH,
|
2 => Facing::NORTH,
|
||||||
3 => Facing::EAST
|
3 => Facing::EAST
|
||||||
];
|
][$raw] ?? null;
|
||||||
if(!isset($map[$raw])){
|
if($result === null){
|
||||||
throw new InvalidBlockStateException("Invalid legacy facing $raw");
|
throw new InvalidBlockStateException("Invalid legacy facing $raw");
|
||||||
}
|
}
|
||||||
return $map[$raw];
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function writeLegacyHorizontalFacing(int $facing) : int{
|
public static function writeLegacyHorizontalFacing(int $facing) : int{
|
||||||
static $map = [
|
$result = [
|
||||||
Facing::SOUTH => 0,
|
Facing::SOUTH => 0,
|
||||||
Facing::WEST => 1,
|
Facing::WEST => 1,
|
||||||
Facing::NORTH => 2,
|
Facing::NORTH => 2,
|
||||||
Facing::EAST => 3
|
Facing::EAST => 3
|
||||||
];
|
][$facing] ?? null;
|
||||||
if(!isset($map[$facing])){
|
if($result === null){
|
||||||
throw new \InvalidArgumentException("Invalid Y-axis facing");
|
throw new \InvalidArgumentException("Invalid Y-axis facing");
|
||||||
}
|
}
|
||||||
return $map[$facing];
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -62,25 +62,24 @@ trait PillarRotationTrait{
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected function readAxisFromMeta(int $meta) : void{
|
protected function readAxisFromMeta(int $meta) : void{
|
||||||
static $map = [
|
$axis = $meta >> $this->getAxisMetaShift();
|
||||||
|
$mapped = [
|
||||||
0 => Axis::Y,
|
0 => Axis::Y,
|
||||||
1 => Axis::X,
|
1 => Axis::X,
|
||||||
2 => Axis::Z
|
2 => Axis::Z
|
||||||
];
|
][$axis] ?? null;
|
||||||
$axis = $meta >> $this->getAxisMetaShift();
|
if($mapped === null){
|
||||||
if(!isset($map[$axis])){
|
|
||||||
throw new InvalidBlockStateException("Invalid axis meta $axis");
|
throw new InvalidBlockStateException("Invalid axis meta $axis");
|
||||||
}
|
}
|
||||||
$this->axis = $map[$axis];
|
$this->axis = $mapped;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function writeAxisToMeta() : int{
|
protected function writeAxisToMeta() : int{
|
||||||
static $bits = [
|
return [
|
||||||
Axis::Y => 0,
|
Axis::Y => 0,
|
||||||
Axis::Z => 2,
|
Axis::Z => 2,
|
||||||
Axis::X => 1
|
Axis::X => 1
|
||||||
];
|
][$this->axis] << $this->getAxisMetaShift();
|
||||||
return $bits[$this->axis] << $this->getAxisMetaShift();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user