PocketMine-MP 5.32.2 git-237b304ef9858756b018e44e8f298093f66f823b
Loading...
Searching...
No Matches
Trapdoor.php
1<?php
2
3/*
4 *
5 * ____ _ _ __ __ _ __ __ ____
6 * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7 * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8 * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9 * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * @author PocketMine Team
17 * @link http://www.pocketmine.net/
18 *
19 *
20 */
21
22declare(strict_types=1);
23
24namespace pocketmine\block;
25
27use pocketmine\block\utils\HorizontalFacingTrait;
28use pocketmine\block\utils\SupportType;
37
38class Trapdoor extends Transparent implements HorizontalFacing{
39 use HorizontalFacingTrait;
40
41 protected bool $open = false;
42 protected bool $top = false;
43
44 protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{
45 $w->horizontalFacing($this->facing);
46 $w->bool($this->top);
47 $w->bool($this->open);
48 }
49
50 public function isOpen() : bool{ return $this->open; }
51
53 public function setOpen(bool $open) : self{
54 $this->open = $open;
55 return $this;
56 }
57
58 public function isTop() : bool{ return $this->top; }
59
61 public function setTop(bool $top) : self{
62 $this->top = $top;
63 return $this;
64 }
65
66 protected function recalculateCollisionBoxes() : array{
67 return [AxisAlignedBB::one()->trim($this->open ? $this->facing : ($this->top ? Facing::DOWN : Facing::UP), 13 / 16)];
68 }
69
70 public function getSupportType(int $facing) : SupportType{
71 return SupportType::NONE;
72 }
73
74 public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
75 if($player !== null){
76 $this->facing = Facing::opposite($player->getHorizontalFacing());
77 }
78 if(($clickVector->y > 0.5 && $face !== Facing::UP) || $face === Facing::DOWN){
79 $this->top = true;
80 }
81
82 return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
83 }
84
85 public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
86 $this->open = !$this->open;
87 $world = $this->position->getWorld();
88 $world->setBlock($this->position, $this);
89 $world->addSound($this->position, new DoorSound());
90 return true;
91 }
92}
onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player=null, array &$returnedItems=[])
Definition Trapdoor.php:85
getSupportType(int $facing)
Definition Trapdoor.php:70
describeBlockOnlyState(RuntimeDataDescriber $w)
Definition Trapdoor.php:44
place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player=null)
Definition Trapdoor.php:74