meta = $meta; } public function getName() : string{ return "Wooden Trapdoor"; } public function getHardness() : float{ return 3; } protected function recalculateBoundingBox() : ?AxisAlignedBB{ $damage = $this->getDamage(); $f = 0.1875; if(($damage & self::MASK_UPPER) > 0){ $bb = new AxisAlignedBB(0, 1 - $f, 0, 1, 1, 1); }else{ $bb = new AxisAlignedBB(0, 0, 0, 1, $f, 1); } if(($damage & self::MASK_OPENED) > 0){ $side = $damage & 0x03; if($side === self::MASK_SIDE_NORTH){ $bb->setBounds(0, 0, 1 - $f, 1, 1, 1); }elseif($side === self::MASK_SIDE_SOUTH){ $bb->setBounds(0, 0, 0, 1, 1, $f); }elseif($side === self::MASK_SIDE_WEST){ $bb->setBounds(1 - $f, 0, 0, 1, 1, 1); }elseif($side === self::MASK_SIDE_EAST){ $bb->setBounds(0, 0, 0, $f, 1, 1); } } return $bb; } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ static $directions = [ Bearing::SOUTH => 2, Bearing::WEST => 1, Bearing::NORTH => 3, Bearing::EAST => 0 ]; if($player !== null){ $this->meta = $directions[$player->getDirection()]; } if(($clickVector->y > 0.5 and $face !== Facing::UP) or $face === Facing::DOWN){ $this->meta |= self::MASK_UPPER; //top half of block } return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); } public function getVariantBitmask() : int{ return 0; } public function onActivate(Item $item, Player $player = null) : bool{ $this->meta ^= self::MASK_OPENED; $this->getLevel()->setBlock($this, $this, true); $this->level->addSound(new DoorSound($this)); return true; } public function getToolType() : int{ return BlockToolType::TYPE_AXE; } public function getFuelTime() : int{ return 300; } }