PocketMine-MP
5.23.3 git-f7687af337d001ddbcc47b8e773f014a33faa662
Loading...
Searching...
No Matches
DoublePlant.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\data\runtime\RuntimeDataDescriber
;
27
use
pocketmine\item\Item
;
28
use
pocketmine\math\Facing
;
29
use
pocketmine\math\Vector3
;
30
use
pocketmine\player\Player
;
31
use
pocketmine\world\BlockTransaction
;
32
33
class
DoublePlant
extends
Flowable
{
34
protected
bool
$top =
false
;
35
36
protected
function
describeBlockOnlyState
(
RuntimeDataDescriber
$w) : void{
37
$w->bool($this->top);
38
}
39
40
public
function
isTop() : bool{ return $this->top; }
41
43
public
function
setTop
(
bool
$top) : self{
44
$this->top = $top;
45
return
$this;
46
}
47
48
public
function
place
(
BlockTransaction
$tx,
Item
$item,
Block
$blockReplace,
Block
$blockClicked,
int
$face,
Vector3
$clickVector, ?
Player
$player =
null
) : bool{
49
$down = $blockReplace->getSide(
Facing
::DOWN);
50
if
($down->hasTypeTag(BlockTypeTags::DIRT) && $blockReplace->
getSide
(Facing::UP)->canBeReplaced()){
51
$top = clone $this;
52
$top->top = true;
53
$tx->addBlock($blockReplace->position, $this)->addBlock($blockReplace->position->getSide(Facing::UP), $top);
54
return true;
55
}
56
57
return
false
;
58
}
59
63
public
function
isValidHalfPlant
() : bool{
64
$other = $this->getSide($this->top ?
Facing
::DOWN :
Facing
::UP);
65
66
return
(
67
$other instanceof
DoublePlant
&&
68
$other->
hasSameTypeId
($this) &&
69
$other->top !== $this->top
70
);
71
}
72
73
public
function
onNearbyBlockChange
() : void{
74
$down = $this->getSide(
Facing
::DOWN);
75
if
(!$this->isValidHalfPlant() || (!$this->top && !$down->hasTypeTag(BlockTypeTags::DIRT) && !$down->hasTypeTag(BlockTypeTags::MUD))){
76
$this->position->getWorld()->useBreakOn($this->position);
77
}
78
}
79
80
public
function
getDrops
(
Item
$item) : array{
81
return $this->top ? parent::getDrops($item) : [];
82
}
83
84
public
function
getAffectedBlocks
() : array{
85
if($this->isValidHalfPlant()){
86
return
[$this, $this->getSide($this->top ? Facing::DOWN : Facing::UP)];
87
}
88
89
return
parent::getAffectedBlocks();
90
}
91
92
public
function
getFlameEncouragement
() : int{
93
return 60;
94
}
95
96
public
function
getFlammability
() : int{
97
return 100;
98
}
99
}
pocketmine\block\Block
Definition
Block.php:62
pocketmine\block\Block\getSide
getSide(int $side, int $step=1)
Definition
Block.php:770
pocketmine\block\Block\hasSameTypeId
hasSameTypeId(Block $other)
Definition
Block.php:184
pocketmine\block\DoublePlant
Definition
DoublePlant.php:33
pocketmine\block\DoublePlant\describeBlockOnlyState
describeBlockOnlyState(RuntimeDataDescriber $w)
Definition
DoublePlant.php:36
pocketmine\block\DoublePlant\setTop
setTop(bool $top)
Definition
DoublePlant.php:43
pocketmine\block\DoublePlant\getFlameEncouragement
getFlameEncouragement()
Definition
DoublePlant.php:92
pocketmine\block\DoublePlant\place
place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player=null)
Definition
DoublePlant.php:48
pocketmine\block\DoublePlant\isValidHalfPlant
isValidHalfPlant()
Definition
DoublePlant.php:63
pocketmine\block\DoublePlant\getFlammability
getFlammability()
Definition
DoublePlant.php:96
pocketmine\block\DoublePlant\getDrops
getDrops(Item $item)
Definition
DoublePlant.php:80
pocketmine\block\DoublePlant\getAffectedBlocks
getAffectedBlocks()
Definition
DoublePlant.php:84
pocketmine\block\DoublePlant\onNearbyBlockChange
onNearbyBlockChange()
Definition
DoublePlant.php:73
pocketmine\block\Flowable
Definition
Flowable.php:34
pocketmine\item\Item
Definition
Item.php:60
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\data\runtime\RuntimeDataDescriber
Definition
RuntimeDataDescriber.php:38
pocketmine\block
Definition
ActivatorRail.php:24
src
block
DoublePlant.php
Generated by
1.12.0