22declare(strict_types=1);
27use pocketmine\block\utils\HorizontalFacingTrait;
28use pocketmine\block\utils\SupportType;
39 use HorizontalFacingTrait;
41 protected bool $top =
false;
42 protected bool $hingeRight =
false;
43 protected bool $open =
false;
46 $w->horizontalFacing($this->facing);
48 $w->bool($this->hingeRight);
49 $w->bool($this->open);
53 parent::readStateFromWorld();
55 $this->collisionBoxes =
null;
58 $other = $this->getSide($this->top ? Facing::DOWN : Facing::UP);
61 $this->facing = $other->facing;
62 $this->open = $other->open;
64 $this->hingeRight = $other->hingeRight;
71 public function isTop() : bool{ return $this->top; }
74 public function setTop(
bool $top) : self{
79 public function isHingeRight() : bool{ return $this->hingeRight; }
83 $this->hingeRight = $hingeRight;
87 public function isOpen() : bool{ return $this->open; }
90 public function setOpen(
bool $open) : self{
101 return [
AxisAlignedBB::one()->trim($this->open ?
Facing::rotateY($this->facing, !$this->hingeRight) : $this->facing, 327 / 400)];
105 return SupportType::NONE;
109 if(!$this->canBeSupportedAt($this) && !$this->getSide(
Facing::DOWN) instanceof
Door){
110 $this->position->getWorld()->useBreakOn($this->position);
116 $blockUp = $this->getSide(Facing::UP);
117 if(!$blockUp->canBeReplaced() || !$this->canBeSupportedAt($blockReplace)){
121 if($player !==
null){
122 $this->facing = $player->getHorizontalFacing();
125 $next = $this->getSide(Facing::rotateY($this->facing,
false));
126 $next2 = $this->getSide(Facing::rotateY($this->facing,
true));
128 if($next->hasSameTypeId($this) || (!$next2->isTransparent() && $next->isTransparent())){
129 $this->hingeRight =
true;
132 $topHalf = clone $this;
133 $topHalf->top =
true;
135 $tx->
addBlock($blockReplace->position, $this)->addBlock($blockUp->position, $topHalf);
143 $this->open = !$this->open;
145 $other = $this->getSide($this->top ? Facing::DOWN : Facing::UP);
146 $world = $this->position->getWorld();
148 $other->open = $this->open;
149 $world->setBlock($other->position, $other);
152 $world->setBlock($this->position, $this);
153 $world->addSound($this->position,
new DoorSound());
160 return parent::getDrops($item);
167 $other = $this->getSide($this->top ?
Facing::DOWN :
Facing::UP);
168 if($other->hasSameTypeId($this)){
169 return [$this, $other];
171 return parent::getAffectedBlocks();
174 private function canBeSupportedAt(
Block $block) : bool{
175 return $block->getAdjacentSupportType(
Facing::DOWN)->hasEdgeSupport();
hasSameTypeId(Block $other)
setHingeRight(bool $hingeRight)
place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player=null)
onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player=null, array &$returnedItems=[])
getSupportType(int $facing)
recalculateCollisionBoxes()
describeBlockOnlyState(RuntimeDataDescriber $w)
addBlock(Vector3 $pos, Block $state)