From fe3a4baddb9a9aa8fbb11adc421eee444333a931 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 8 Jul 2019 18:08:52 +0100 Subject: [PATCH] added StairShape enum this has no practical value to plugins yet, but it will in the future. --- src/pocketmine/block/Stair.php | 30 ++++++------- src/pocketmine/block/utils/StairShape.php | 51 +++++++++++++++++++++++ 2 files changed, 67 insertions(+), 14 deletions(-) create mode 100644 src/pocketmine/block/utils/StairShape.php diff --git a/src/pocketmine/block/Stair.php b/src/pocketmine/block/Stair.php index 892c73045..7b84afbc6 100644 --- a/src/pocketmine/block/Stair.php +++ b/src/pocketmine/block/Stair.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\block\utils\BlockDataValidator; +use pocketmine\block\utils\StairShape; use pocketmine\item\Item; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Facing; @@ -32,18 +33,19 @@ use pocketmine\player\Player; use pocketmine\world\BlockTransaction; class Stair extends Transparent{ - private const SHAPE_STRAIGHT = "straight"; - private const SHAPE_INNER_LEFT = "inner_left"; - private const SHAPE_INNER_RIGHT = "inner_right"; - private const SHAPE_OUTER_LEFT = "outer_left"; - private const SHAPE_OUTER_RIGHT = "outer_right"; /** @var int */ protected $facing = Facing::NORTH; /** @var bool */ protected $upsideDown = false; - /** @var string */ - protected $shape = self::SHAPE_STRAIGHT; + + /** @var StairShape */ + protected $shape; + + public function __construct(BlockIdentifier $idInfo, string $name, BlockBreakInfo $breakInfo){ + $this->shape = StairShape::STRAIGHT(); + parent::__construct($idInfo, $name, $breakInfo); + } protected function writeStateToMeta() : int{ return (5 - $this->facing) | ($this->upsideDown ? BlockLegacyMetadata::STAIR_FLAG_UPSIDE_DOWN : 0); @@ -63,11 +65,11 @@ class Stair extends Transparent{ $clockwise = Facing::rotateY($this->facing, true); if(($backFacing = $this->getPossibleCornerFacing(false)) !== null){ - $this->shape = $backFacing === $clockwise ? self::SHAPE_OUTER_RIGHT : self::SHAPE_OUTER_LEFT; + $this->shape = $backFacing === $clockwise ? StairShape::OUTER_RIGHT() : StairShape::OUTER_LEFT(); }elseif(($frontFacing = $this->getPossibleCornerFacing(true)) !== null){ - $this->shape = $frontFacing === $clockwise ? self::SHAPE_INNER_RIGHT : self::SHAPE_INNER_LEFT; + $this->shape = $frontFacing === $clockwise ? StairShape::INNER_RIGHT() : StairShape::INNER_LEFT(); }else{ - $this->shape = self::SHAPE_STRAIGHT; + $this->shape = StairShape::STRAIGHT(); } } @@ -81,14 +83,14 @@ class Stair extends Transparent{ ->trim(Facing::opposite($topStepFace), 0.5) ->trim(Facing::opposite($this->facing), 0.5); - if($this->shape === self::SHAPE_OUTER_LEFT or $this->shape === self::SHAPE_OUTER_RIGHT){ - $topStep->trim(Facing::rotateY($this->facing, $this->shape === self::SHAPE_OUTER_LEFT), 0.5); - }elseif($this->shape === self::SHAPE_INNER_LEFT or $this->shape === self::SHAPE_INNER_RIGHT){ + if($this->shape->equals(StairShape::OUTER_LEFT()) or $this->shape->equals(StairShape::OUTER_RIGHT())){ + $topStep->trim(Facing::rotateY($this->facing, $this->shape->equals(StairShape::OUTER_LEFT())), 0.5); + }elseif($this->shape->equals(StairShape::INNER_LEFT()) or $this->shape->equals(StairShape::INNER_RIGHT())){ //add an extra cube $bbs[] = AxisAlignedBB::one() ->trim(Facing::opposite($topStepFace), 0.5) ->trim($this->facing, 0.5) //avoid overlapping with main step - ->trim(Facing::rotateY($this->facing, $this->shape === self::SHAPE_INNER_LEFT), 0.5); + ->trim(Facing::rotateY($this->facing, $this->shape->equals(StairShape::INNER_LEFT())), 0.5); } $bbs[] = $topStep; diff --git a/src/pocketmine/block/utils/StairShape.php b/src/pocketmine/block/utils/StairShape.php new file mode 100644 index 000000000..89f4c544a --- /dev/null +++ b/src/pocketmine/block/utils/StairShape.php @@ -0,0 +1,51 @@ +