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