PocketMine-MP 5.16.1 git-585aee9386a787c95e73dd0a05ffca8329606b68
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
22declare(strict_types=1);
23
24namespace pocketmine\block;
25
28use pocketmine\block\utils\StaticSupportTrait;
36
37final 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, int $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}
describeBlockOnlyState(RuntimeDataDescriber $w)
onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player=null, array &$returnedItems=[])
pop(int $count=1)
Definition: Item.php:430