PocketMine-MP
5.33.2 git-1133d49c924b4358c79d44eeb97dcbf56cb4d1eb
Loading...
Searching...
No Matches
TorchflowerCrop.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\BlockEventHelper
;
27
use
pocketmine\block\utils\CropGrowthHelper
;
28
use pocketmine\block\utils\StaticSupportTrait;
29
use
pocketmine\data\runtime\RuntimeDataDescriber
;
30
use
pocketmine\item\Fertilizer
;
31
use
pocketmine\item\Item
;
32
use
pocketmine\item\VanillaItems
;
33
use
pocketmine\math\Facing
;
34
use
pocketmine\math\Vector3
;
35
use
pocketmine\player\Player
;
36
37
final
class
TorchflowerCrop
extends
Flowable
{
38
use StaticSupportTrait;
39
40
private
bool
$ready =
false
;
41
42
public
function
describeBlockOnlyState
(
RuntimeDataDescriber
$w) : void{
43
$w->bool($this->ready);
44
}
45
46
public
function
isReady() : bool{ return $this->ready; }
47
48
public
function
setReady(
bool
$ready) : self{
49
$this->ready = $ready;
50
return
$this;
51
}
52
53
private
function
canBeSupportedAt(Block $block) : bool{
54
return $block->getSide(Facing::DOWN)->getTypeId() === BlockTypeIds::FARMLAND;
55
}
56
57
private
function
getNextState() : Block{
58
if($this->ready){
59
return
VanillaBlocks::TORCHFLOWER();
60
}
else
{
61
return
VanillaBlocks::TORCHFLOWER_CROP()->setReady(
true
);
62
}
63
}
64
65
public
function
onInteract
(
Item
$item,
Facing
$face,
Vector3
$clickVector, ?
Player
$player =
null
, array &$returnedItems = []) : bool{
66
if($item instanceof
Fertilizer
){
67
if
(BlockEventHelper::grow($this, $this->getNextState(), $player)){
68
$item->
pop
();
69
}
70
71
return
true
;
72
}
73
74
return
false
;
75
}
76
77
public
function
ticksRandomly
() : bool{
78
return true;
79
}
80
81
public
function
onRandomTick
() : void{
82
if(
CropGrowthHelper
::canGrow($this)){
83
BlockEventHelper::grow($this, $this->getNextState(),
null
);
84
}
85
}
86
87
public
function
asItem
() :
Item
{
88
return
VanillaItems
::TORCHFLOWER_SEEDS();
89
}
90
}
pocketmine\block\Flowable
Definition
Flowable.php:34
pocketmine\block\TorchflowerCrop
Definition
TorchflowerCrop.php:37
pocketmine\block\TorchflowerCrop\ticksRandomly
ticksRandomly()
Definition
TorchflowerCrop.php:77
pocketmine\block\TorchflowerCrop\onInteract
onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player=null, array &$returnedItems=[])
Definition
TorchflowerCrop.php:65
pocketmine\block\TorchflowerCrop\asItem
asItem()
Definition
TorchflowerCrop.php:87
pocketmine\block\TorchflowerCrop\onRandomTick
onRandomTick()
Definition
TorchflowerCrop.php:81
pocketmine\block\TorchflowerCrop\describeBlockOnlyState
describeBlockOnlyState(RuntimeDataDescriber $w)
Definition
TorchflowerCrop.php:42
pocketmine\block\utils\BlockEventHelper
Definition
BlockEventHelper.php:39
pocketmine\block\utils\CropGrowthHelper
Definition
CropGrowthHelper.php:30
pocketmine\item\Fertilizer
Definition
Fertilizer.php:26
pocketmine\item\Item
Definition
Item.php:62
pocketmine\item\Item\pop
pop(int $count=1)
Definition
Item.php:435
pocketmine\item\VanillaItems
Definition
VanillaItems.php:358
pocketmine\math\Vector3
Definition
Vector3.php:37
pocketmine\player\Player
Definition
Player.php:173
pocketmine\data\runtime\RuntimeDataDescriber
Definition
RuntimeDataDescriber.php:38
pocketmine\block
Definition
ActivatorRail.php:24
pocketmine\math\Facing
Facing
Definition
Facing.php:28
src
block
TorchflowerCrop.php
Generated by
1.12.0