22declare(strict_types=1);
26use pocketmine\block\utils\HorizontalFacingTrait;
27use pocketmine\block\utils\SupportType;
38 use HorizontalFacingTrait;
40 protected bool $top =
false;
41 protected bool $hingeRight =
false;
42 protected bool $open =
false;
45 $w->horizontalFacing($this->facing);
47 $w->bool($this->hingeRight);
48 $w->bool($this->open);
52 parent::readStateFromWorld();
54 $this->collisionBoxes =
null;
57 $other = $this->getSide($this->top ? Facing::DOWN : Facing::UP);
60 $this->facing = $other->facing;
61 $this->open = $other->open;
63 $this->hingeRight = $other->hingeRight;
70 public function isTop() : bool{ return $this->top; }
73 public function setTop(
bool $top) : self{
78 public function isHingeRight() : bool{ return $this->hingeRight; }
82 $this->hingeRight = $hingeRight;
86 public function isOpen() : bool{ return $this->open; }
89 public function setOpen(
bool $open) : self{
103 return [
AxisAlignedBB::one()->trim($this->open ?
Facing::rotateY($this->facing, !$this->hingeRight) : $this->facing, 327 / 400)];
107 return SupportType::NONE;
111 if(!$this->canBeSupportedAt($this) && !$this->getSide(
Facing::DOWN) instanceof
Door){
112 $this->position->getWorld()->useBreakOn($this->position);
118 $blockUp = $this->getSide(Facing::UP);
119 if(!$blockUp->canBeReplaced() || !$this->canBeSupportedAt($blockReplace)){
123 if($player !==
null){
124 $this->facing = $player->getHorizontalFacing();
127 $next = $this->getSide(Facing::rotateY($this->facing,
false));
128 $next2 = $this->getSide(Facing::rotateY($this->facing,
true));
130 if($next->hasSameTypeId($this) || (!$next2->isTransparent() && $next->isTransparent())){
131 $this->hingeRight =
true;
134 $topHalf = clone $this;
135 $topHalf->top =
true;
137 $tx->
addBlock($blockReplace->position, $this)->addBlock($blockUp->position, $topHalf);
145 $this->open = !$this->open;
147 $other = $this->getSide($this->top ? Facing::DOWN : Facing::UP);
148 $world = $this->position->getWorld();
150 $other->open = $this->open;
151 $world->setBlock($other->position, $other);
154 $world->setBlock($this->position, $this);
155 $world->addSound($this->position,
new DoorSound());
162 return parent::getDrops($item);
169 $other = $this->getSide($this->top ?
Facing::DOWN :
Facing::UP);
170 if($other->hasSameTypeId($this)){
171 return [$this, $other];
173 return parent::getAffectedBlocks();
176 private function canBeSupportedAt(
Block $block) : bool{
177 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)