mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-07 18:32:55 +00:00
closes #6070 there are some unresolved questions about the growth speed of beetroots, pitcher plants and torchflower crops, but that's a topic for another commit. this change also doesn't account for the light levels.
91 lines
2.3 KiB
PHP
91 lines
2.3 KiB
PHP
<?php
|
|
|
|
/*
|
|
*
|
|
* ____ _ _ __ __ _ __ __ ____
|
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* @author PocketMine Team
|
|
* @link http://www.pocketmine.net/
|
|
*
|
|
*
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace pocketmine\block;
|
|
|
|
use pocketmine\block\utils\BlockEventHelper;
|
|
use pocketmine\block\utils\CropGrowthHelper;
|
|
use pocketmine\block\utils\StaticSupportTrait;
|
|
use pocketmine\data\runtime\RuntimeDataDescriber;
|
|
use pocketmine\item\Fertilizer;
|
|
use pocketmine\item\Item;
|
|
use pocketmine\item\VanillaItems;
|
|
use pocketmine\math\Facing;
|
|
use pocketmine\math\Vector3;
|
|
use pocketmine\player\Player;
|
|
|
|
final class TorchflowerCrop extends Flowable{
|
|
use StaticSupportTrait;
|
|
|
|
private bool $ready = false;
|
|
|
|
public function describeBlockOnlyState(RuntimeDataDescriber $w) : void{
|
|
$w->bool($this->ready);
|
|
}
|
|
|
|
public function isReady() : bool{ return $this->ready; }
|
|
|
|
public function setReady(bool $ready) : self{
|
|
$this->ready = $ready;
|
|
return $this;
|
|
}
|
|
|
|
private function canBeSupportedAt(Block $block) : bool{
|
|
return $block->getSide(Facing::DOWN)->getTypeId() === BlockTypeIds::FARMLAND;
|
|
}
|
|
|
|
private function getNextState() : Block{
|
|
if($this->ready){
|
|
return VanillaBlocks::TORCHFLOWER();
|
|
}else{
|
|
return VanillaBlocks::TORCHFLOWER_CROP()->setReady(true);
|
|
}
|
|
}
|
|
|
|
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
|
|
if($item instanceof Fertilizer){
|
|
if(BlockEventHelper::grow($this, $this->getNextState(), $player)){
|
|
$item->pop();
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public function ticksRandomly() : bool{
|
|
return true;
|
|
}
|
|
|
|
public function onRandomTick() : void{
|
|
if(CropGrowthHelper::canGrow($this)){
|
|
BlockEventHelper::grow($this, $this->getNextState(), null);
|
|
}
|
|
}
|
|
|
|
public function asItem() : Item{
|
|
return VanillaItems::TORCHFLOWER_SEEDS();
|
|
}
|
|
}
|