mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-01 17:53:41 +00:00
this makes some stuff a lot less pretty, but this seems to be the bare minimum necessary to do this task. It can be enhanced later.
94 lines
2.6 KiB
PHP
94 lines
2.6 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\BlockDataSerializer;
|
|
use pocketmine\event\block\BlockGrowEvent;
|
|
use pocketmine\item\Item;
|
|
use pocketmine\math\Facing;
|
|
use pocketmine\math\Vector3;
|
|
use pocketmine\player\Player;
|
|
use pocketmine\world\BlockTransaction;
|
|
use function mt_rand;
|
|
|
|
class NetherWartPlant extends Flowable{
|
|
|
|
/** @var int */
|
|
protected $age = 0;
|
|
|
|
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
|
|
parent::__construct($idInfo, $name, $breakInfo ?? BlockBreakInfo::instant());
|
|
}
|
|
|
|
protected function writeStateToMeta() : int{
|
|
return $this->age;
|
|
}
|
|
|
|
public function readStateFromData(int $id, int $stateMeta) : void{
|
|
$this->age = BlockDataSerializer::readBoundedInt("age", $stateMeta, 0, 3);
|
|
}
|
|
|
|
public function getStateBitmask() : int{
|
|
return 0b11;
|
|
}
|
|
|
|
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
|
$down = $this->getSide(Facing::DOWN);
|
|
if($down->getId() === BlockLegacyIds::SOUL_SAND){
|
|
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public function onNearbyBlockChange() : void{
|
|
if($this->getSide(Facing::DOWN)->getId() !== BlockLegacyIds::SOUL_SAND){
|
|
$this->pos->getWorld()->useBreakOn($this->pos);
|
|
}
|
|
}
|
|
|
|
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->pos->getWorld()->setBlock($this->pos, $ev->getNewState());
|
|
}
|
|
}
|
|
}
|
|
|
|
public function getDropsForCompatibleTool(Item $item) : array{
|
|
return [
|
|
$this->asItem()->setCount($this->age === 3 ? mt_rand(2, 4) : 1)
|
|
];
|
|
}
|
|
}
|