Added getShape() and setShape() APIs to StraightOnlyRail and Rail

This commit is contained in:
Dylan K. Taylor 2021-07-22 18:37:30 +01:00
parent e97234d420
commit 5c609cc1c1
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
2 changed files with 27 additions and 0 deletions

View File

@ -26,6 +26,8 @@ namespace pocketmine\block;
use pocketmine\block\utils\InvalidBlockStateException;
use pocketmine\block\utils\RailConnectionInfo;
use pocketmine\math\Facing;
use function array_keys;
use function implode;
class Rail extends BaseRail{
@ -77,4 +79,15 @@ class Rail extends BaseRail{
return $possible;
}
public function getShape() : int{ return $this->railShape; }
/** @return $this */
public function setShape(int $shape) : self{
if(!isset(RailConnectionInfo::CONNECTIONS[$shape]) && !isset(RailConnectionInfo::CURVE_CONNECTIONS[$shape])){
throw new \InvalidArgumentException("Invalid shape, must be one of " . implode(", ", [...array_keys(RailConnectionInfo::CONNECTIONS), ...array_keys(RailConnectionInfo::CURVE_CONNECTIONS)]));
}
$this->railShape = $shape;
return $this;
}
}

View File

@ -25,6 +25,8 @@ namespace pocketmine\block;
use pocketmine\block\utils\InvalidBlockStateException;
use pocketmine\block\utils\RailConnectionInfo;
use function array_keys;
use function implode;
/**
* Simple non-curvable rail.
@ -61,4 +63,16 @@ class StraightOnlyRail extends BaseRail{
protected function getCurrentShapeConnections() : array{
return RailConnectionInfo::CONNECTIONS[$this->railShape];
}
public function getShape() : int{ return $this->railShape; }
/** @return $this */
public function setShape(int $shape) : self{
if(!isset(RailConnectionInfo::CONNECTIONS[$shape])){
throw new \InvalidArgumentException("Invalid rail shape, must be one of " . implode(", ", array_keys(RailConnectionInfo::CONNECTIONS)));
}
$this->railShape = $shape;
return $this;
}
}