mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-30 14:38:36 +00:00
89 lines
2.3 KiB
PHP
89 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\BlockDataValidator;
|
|
use pocketmine\event\block\BlockGrowEvent;
|
|
use pocketmine\item\Item;
|
|
use pocketmine\math\Facing;
|
|
use pocketmine\math\Vector3;
|
|
use pocketmine\Player;
|
|
use function mt_rand;
|
|
|
|
class NetherWartPlant extends Flowable{
|
|
|
|
/** @var int */
|
|
protected $age = 0;
|
|
|
|
protected function writeStateToMeta() : int{
|
|
return $this->age;
|
|
}
|
|
|
|
public function readStateFromData(int $id, int $stateMeta) : void{
|
|
$this->age = BlockDataValidator::readBoundedInt("age", $stateMeta, 0, 3);
|
|
}
|
|
|
|
public function getStateBitmask() : int{
|
|
return 0b11;
|
|
}
|
|
|
|
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
|
$down = $this->getSide(Facing::DOWN);
|
|
if($down->getId() === BlockIds::SOUL_SAND){
|
|
return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public function onNearbyBlockChange() : void{
|
|
if($this->getSide(Facing::DOWN)->getId() !== BlockIds::SOUL_SAND){
|
|
$this->getLevel()->useBreakOn($this);
|
|
}
|
|
}
|
|
|
|
public function ticksRandomly() : bool{
|
|
return true;
|
|
}
|
|
|
|
public function onRandomTick() : void{
|
|
if($this->age < 3 and mt_rand(0, 10) === 0){ //Still growing
|
|
$block = clone $this;
|
|
$block->age++;
|
|
$ev = new BlockGrowEvent($this, $block);
|
|
$ev->call();
|
|
if(!$ev->isCancelled()){
|
|
$this->getLevel()->setBlock($this, $ev->getNewState());
|
|
}
|
|
}
|
|
}
|
|
|
|
public function getDropsForCompatibleTool(Item $item) : array{
|
|
return [
|
|
$this->asItem()->setCount($this->age === 3 ? mt_rand(2, 4) : 1)
|
|
];
|
|
}
|
|
}
|