PocketMine-MP
5.33.2 git-1133d49c924b4358c79d44eeb97dcbf56cb4d1eb
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
22
declare(strict_types=1);
23
24
namespace
pocketmine\block
;
25
26
use
pocketmine\block\utils\HorizontalFacing
;
27
use pocketmine\block\utils\HorizontalFacingOption;
28
use pocketmine\block\utils\HorizontalFacingTrait;
29
use pocketmine\block\utils\SupportType;
30
use
pocketmine\data\runtime\RuntimeDataDescriber
;
31
use
pocketmine\item\Item
;
32
use
pocketmine\math\AxisAlignedBB
;
33
use
pocketmine\math\Facing
;
34
use
pocketmine\math\Vector3
;
35
use
pocketmine\player\Player
;
36
use
pocketmine\world\BlockTransaction
;
37
use
pocketmine\world\sound\DoorSound
;
38
39
class
Trapdoor
extends
Transparent
implements
HorizontalFacing
{
40
use HorizontalFacingTrait;
41
42
protected
bool
$open =
false
;
43
protected
bool
$top =
false
;
44
45
protected
function
describeBlockOnlyState
(
RuntimeDataDescriber
$w) : void{
46
$w->enum($this->facing);
47
$w->bool($this->top);
48
$w->bool($this->open);
49
}
50
51
public
function
isOpen() : bool{ return $this->open; }
52
54
public
function
setOpen
(
bool
$open) : self{
55
$this->open = $open;
56
return
$this;
57
}
58
59
public
function
isTop() : bool{ return $this->top; }
60
62
public
function
setTop
(
bool
$top) : self{
63
$this->top = $top;
64
return
$this;
65
}
66
67
protected
function
recalculateCollisionBoxes
() : array{
68
return [
AxisAlignedBB
::one()->trimmedCopy($this->open ? $this->facing->toFacing() : ($this->top ?
Facing
::DOWN :
Facing
::UP), 13 / 16)];
69
}
70
71
public
function
getSupportType
(
Facing
$facing) : SupportType{
72
return SupportType::NONE;
73
}
74
75
public
function
place
(
BlockTransaction
$tx,
Item
$item,
Block
$blockReplace,
Block
$blockClicked,
Facing
$face,
Vector3
$clickVector, ?
Player
$player =
null
) : bool{
76
if($player !== null){
77
$this->facing = HorizontalFacingOption::fromFacing(Facing::opposite($player->getHorizontalFacing()));
78
}
79
if
(($clickVector->y > 0.5 && $face !== Facing::UP) || $face === Facing::DOWN){
80
$this->top =
true
;
81
}
82
83
return
parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
84
}
85
86
public
function
onInteract
(
Item
$item,
Facing
$face,
Vector3
$clickVector, ?
Player
$player =
null
, array &$returnedItems = []) : bool{
87
$this->open = !$this->open;
88
$world = $this->position->getWorld();
89
$world->setBlock($this->position, $this);
90
$world->addSound($this->position,
new
DoorSound
());
91
return
true
;
92
}
93
}
pocketmine\block\Block
Definition
Block.php:62
pocketmine\block\Transparent
Definition
Transparent.php:32
pocketmine\block\Trapdoor
Definition
Trapdoor.php:39
pocketmine\block\Trapdoor\getSupportType
getSupportType(Facing $facing)
Definition
Trapdoor.php:71
pocketmine\block\Trapdoor\setTop
setTop(bool $top)
Definition
Trapdoor.php:62
pocketmine\block\Trapdoor\describeBlockOnlyState
describeBlockOnlyState(RuntimeDataDescriber $w)
Definition
Trapdoor.php:45
pocketmine\block\Trapdoor\place
place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player=null)
Definition
Trapdoor.php:75
pocketmine\block\Trapdoor\recalculateCollisionBoxes
recalculateCollisionBoxes()
Definition
Trapdoor.php:67
pocketmine\block\Trapdoor\setOpen
setOpen(bool $open)
Definition
Trapdoor.php:54
pocketmine\block\Trapdoor\onInteract
onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player=null, array &$returnedItems=[])
Definition
Trapdoor.php:86
pocketmine\item\Item
Definition
Item.php:62
pocketmine\math\AxisAlignedBB
Definition
AxisAlignedBB.php:29
pocketmine\math\Vector3
Definition
Vector3.php:37
pocketmine\player\Player
Definition
Player.php:173
pocketmine\world\BlockTransaction
Definition
BlockTransaction.php:30
pocketmine\world\sound\DoorSound
Definition
DoorSound.php:30
pocketmine\block\utils\HorizontalFacing
Definition
HorizontalFacing.php:26
pocketmine\data\runtime\RuntimeDataDescriber
Definition
RuntimeDataDescriber.php:38
pocketmine\block
Definition
ActivatorRail.php:24
pocketmine\math\Facing
Facing
Definition
Facing.php:28
src
block
Trapdoor.php
Generated by
1.12.0