22declare(strict_types=1);
26use pocketmine\block\utils\HorizontalFacingTrait;
27use pocketmine\block\utils\StairShape;
28use pocketmine\block\utils\SupportType;
39 use HorizontalFacingTrait;
41 protected bool $upsideDown =
false;
42 protected StairShape $shape = StairShape::STRAIGHT;
45 $w->horizontalFacing($this->facing);
46 $w->bool($this->upsideDown);
50 parent::readStateFromWorld();
52 $this->collisionBoxes =
null;
55 if(($backFacing = $this->getPossibleCornerFacing(
false)) !==
null){
56 $this->shape = $backFacing === $clockwise ? StairShape::OUTER_RIGHT : StairShape::OUTER_LEFT;
57 }elseif(($frontFacing = $this->getPossibleCornerFacing(
true)) !==
null){
58 $this->shape = $frontFacing === $clockwise ? StairShape::INNER_RIGHT : StairShape::INNER_LEFT;
60 $this->shape = StairShape::STRAIGHT;
66 public function isUpsideDown() : bool{ return $this->upsideDown; }
70 $this->upsideDown = $upsideDown;
74 public function getShape() : StairShape{ return $this->shape; }
77 public function setShape(StairShape $shape) : self{
78 $this->shape = $shape;
83 $topStepFace = $this->upsideDown ?
Facing::DOWN :
Facing::UP;
85 AxisAlignedBB::one()->trim($topStepFace, 0.5)
88 $topStep = AxisAlignedBB::one()
89 ->trim(Facing::opposite($topStepFace), 0.5)
90 ->trim(Facing::opposite($this->facing), 0.5);
92 if($this->shape === StairShape::OUTER_LEFT || $this->shape === StairShape::OUTER_RIGHT){
93 $topStep->trim(Facing::rotateY($this->facing, $this->shape === StairShape::OUTER_LEFT), 0.5);
94 }elseif($this->shape === StairShape::INNER_LEFT || $this->shape === StairShape::INNER_RIGHT){
96 $bbs[] = AxisAlignedBB::one()
97 ->trim(Facing::opposite($topStepFace), 0.5)
98 ->trim($this->facing, 0.5)
99 ->trim(Facing::rotateY($this->facing, $this->shape === StairShape::INNER_LEFT), 0.5);
109 $facing ===
Facing::UP && $this->upsideDown ||
110 $facing ===
Facing::DOWN && !$this->upsideDown ||
111 ($facing === $this->facing && $this->shape !== StairShape::OUTER_LEFT && $this->shape !== StairShape::OUTER_RIGHT) ||
112 ($facing ===
Facing::rotate($this->facing,
Axis::Y, false) && $this->shape === StairShape::INNER_LEFT) ||
113 ($facing ===
Facing::rotate($this->facing,
Axis::Y, true) && $this->shape === StairShape::INNER_RIGHT)
115 return SupportType::FULL;
117 return SupportType::NONE;
120 private function getPossibleCornerFacing(
bool $oppositeFacing) : ?int{
121 $side = $this->getSide($oppositeFacing ? Facing::opposite($this->facing) : $this->facing);
123 $side instanceof Stair &&
124 $side->upsideDown === $this->upsideDown &&
125 Facing::axis($side->facing) !== Facing::axis($this->facing)
126 ) ? $side->facing :
null;
130 if($player !== null){
131 $this->facing = $player->getHorizontalFacing();
133 $this->upsideDown = (($clickVector->y > 0.5 && $face !== Facing::UP) || $face === Facing::DOWN);
135 return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
describeBlockOnlyState(RuntimeDataDescriber $w)
getSupportType(int $facing)
setShape(StairShape $shape)
place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player=null)
setUpsideDown(bool $upsideDown)
recalculateCollisionBoxes()
static rotateY(int $direction, bool $clockwise)