22declare(strict_types=1);
27use pocketmine\block\utils\HorizontalFacingOption;
28use pocketmine\block\utils\HorizontalFacingTrait;
29use pocketmine\block\utils\SupportType;
40 use HorizontalFacingTrait;
42 protected bool $top =
false;
43 protected bool $hingeRight =
false;
44 protected bool $open =
false;
47 $w->enum($this->facing);
49 $w->bool($this->hingeRight);
50 $w->bool($this->open);
54 parent::readStateFromWorld();
56 $this->collisionBoxes =
null;
59 $other = $this->getSide($this->top ? Facing::DOWN : Facing::UP);
62 $this->facing = $other->facing;
63 $this->open = $other->open;
65 $this->hingeRight = $other->hingeRight;
72 public function isTop() : bool{ return $this->top; }
75 public function setTop(
bool $top) : self{
80 public function isHingeRight() : bool{ return $this->hingeRight; }
84 $this->hingeRight = $hingeRight;
88 public function isOpen() : bool{ return $this->open; }
91 public function setOpen(
bool $open) : self{
102 return [
AxisAlignedBB::one()->trimmedCopy($this->open ?
Facing::rotateY($this->facing->toFacing(), !$this->hingeRight) : $this->facing->toFacing(), 327 / 400)];
106 return SupportType::NONE;
110 if(!$this->canBeSupportedAt($this) && !$this->getSide(
Facing::DOWN) instanceof
Door){
111 $this->position->getWorld()->useBreakOn($this->position);
117 $blockUp = $this->getSide(Facing::UP);
118 if(!$blockUp->canBeReplaced() || !$this->canBeSupportedAt($blockReplace)){
122 if($player !==
null){
124 $this->facing = HorizontalFacingOption::fromFacing($player->getHorizontalFacing());
127 $realFacing = $this->facing->toFacing();
128 $next = $this->getSide(Facing::rotateY($realFacing,
false));
129 $next2 = $this->getSide(Facing::rotateY($realFacing,
true));
131 if($next->hasSameTypeId($this) || (!$next2->isTransparent() && $next->isTransparent())){
132 $this->hingeRight =
true;
135 $topHalf = clone $this;
136 $topHalf->top =
true;
138 $tx->
addBlock($blockReplace->position, $this)->addBlock($blockUp->position, $topHalf);
146 $this->open = !$this->open;
148 $other = $this->getSide($this->top ? Facing::DOWN : Facing::UP);
149 $world = $this->position->getWorld();
151 $other->open = $this->open;
152 $world->setBlock($other->position, $other);
155 $world->setBlock($this->position, $this);
156 $world->addSound($this->position,
new DoorSound());
163 return parent::getDrops($item);
170 $other = $this->getSide($this->top ?
Facing::DOWN :
Facing::UP);
171 if($other->hasSameTypeId($this)){
172 return [$this, $other];
174 return parent::getAffectedBlocks();
177 private function canBeSupportedAt(
Block $block) : bool{
178 return $block->getAdjacentSupportType(
Facing::DOWN)->hasEdgeSupport();
hasSameTypeId(Block $other)
setHingeRight(bool $hingeRight)
place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player=null)
onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player=null, array &$returnedItems=[])
getSupportType(Facing $facing)
recalculateCollisionBoxes()
describeBlockOnlyState(RuntimeDataDescriber $w)
addBlock(Vector3 $pos, Block $state)