mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 00:33:59 +00:00
Clean up garbage in Tree populators
This commit is contained in:
parent
cfee0a4e0b
commit
70054de575
@ -29,13 +29,11 @@ use pocketmine\level\ChunkManager;
|
||||
use pocketmine\utils\Random;
|
||||
|
||||
class BirchTree extends Tree{
|
||||
|
||||
/** @var bool */
|
||||
protected $superBirch = false;
|
||||
|
||||
public function __construct(bool $superBirch = false){
|
||||
$this->trunkBlock = Block::LOG;
|
||||
$this->leafBlock = Block::LEAVES;
|
||||
$this->type = Wood::BIRCH;
|
||||
parent::__construct(Block::LOG, Block::LEAVES, Wood::BIRCH);
|
||||
$this->superBirch = $superBirch;
|
||||
}
|
||||
|
||||
|
@ -29,9 +29,6 @@ use pocketmine\block\Wood;
|
||||
class JungleTree extends Tree{
|
||||
|
||||
public function __construct(){
|
||||
$this->trunkBlock = Block::LOG;
|
||||
$this->leafBlock = Block::LEAVES;
|
||||
$this->type = Wood::JUNGLE;
|
||||
$this->treeHeight = 8;
|
||||
parent::__construct(Block::LOG, Block::LEAVES, Wood::JUNGLE, 8);
|
||||
}
|
||||
}
|
||||
|
@ -31,9 +31,7 @@ use pocketmine\utils\Random;
|
||||
class OakTree extends Tree{
|
||||
|
||||
public function __construct(){
|
||||
$this->trunkBlock = Block::LOG;
|
||||
$this->leafBlock = Block::LEAVES;
|
||||
$this->type = Wood::OAK;
|
||||
parent::__construct(Block::LOG, Block::LEAVES, Wood::OAK);
|
||||
}
|
||||
|
||||
public function placeObject(ChunkManager $level, int $x, int $y, int $z, Random $random) : void{
|
||||
|
@ -32,10 +32,7 @@ use pocketmine\utils\Random;
|
||||
class SpruceTree extends Tree{
|
||||
|
||||
public function __construct(){
|
||||
$this->trunkBlock = Block::LOG;
|
||||
$this->leafBlock = Block::LEAVES;
|
||||
$this->type = Wood::SPRUCE;
|
||||
$this->treeHeight = 10;
|
||||
parent::__construct(Block::LOG, Block::LEAVES, Wood::SPRUCE, 10);
|
||||
}
|
||||
|
||||
public function placeObject(ChunkManager $level, int $x, int $y, int $z, Random $random) : void{
|
||||
@ -63,7 +60,7 @@ class SpruceTree extends Tree{
|
||||
|
||||
if(!BlockFactory::get($level->getBlockIdAt($xx, $yyy, $zz))->isSolid()){
|
||||
$level->setBlockIdAt($xx, $yyy, $zz, $this->leafBlock);
|
||||
$level->setBlockDataAt($xx, $yyy, $zz, $this->type);
|
||||
$level->setBlockDataAt($xx, $yyy, $zz, $this->blockMeta);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,25 +25,30 @@ namespace pocketmine\level\generator\object;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
use pocketmine\block\Leaves;
|
||||
use pocketmine\block\Sapling;
|
||||
use pocketmine\block\utils\WoodType;
|
||||
use pocketmine\block\Wood;
|
||||
use pocketmine\level\ChunkManager;
|
||||
use pocketmine\utils\Random;
|
||||
|
||||
abstract class Tree{
|
||||
public $overridable = [
|
||||
Block::AIR => true,
|
||||
Block::SAPLING => true,
|
||||
Block::LOG => true,
|
||||
Block::LEAVES => true,
|
||||
Block::SNOW_LAYER => true,
|
||||
Block::LOG2 => true,
|
||||
Block::LEAVES2 => true
|
||||
];
|
||||
|
||||
public $type = 0;
|
||||
public $trunkBlock = Block::LOG;
|
||||
public $leafBlock = Block::LEAVES;
|
||||
public $treeHeight = 7;
|
||||
/** @var int */
|
||||
protected $blockMeta;
|
||||
/** @var int */
|
||||
protected $trunkBlock;
|
||||
/** @var int */
|
||||
protected $leafBlock;
|
||||
/** @var int */
|
||||
protected $treeHeight;
|
||||
|
||||
public function __construct(int $trunkBlock, int $leafBlock, int $blockMeta, int $treeHeight = 7){
|
||||
$this->trunkBlock = $trunkBlock;
|
||||
$this->leafBlock = $leafBlock;
|
||||
$this->blockMeta = $blockMeta;
|
||||
$this->treeHeight = $treeHeight;
|
||||
}
|
||||
|
||||
public static function growTree(ChunkManager $level, int $x, int $y, int $z, Random $random, int $type = WoodType::OAK) : void{
|
||||
switch($type){
|
||||
@ -86,7 +91,7 @@ abstract class Tree{
|
||||
}
|
||||
for($xx = -$radiusToCheck; $xx < ($radiusToCheck + 1); ++$xx){
|
||||
for($zz = -$radiusToCheck; $zz < ($radiusToCheck + 1); ++$zz){
|
||||
if(!isset($this->overridable[$level->getBlockIdAt($x + $xx, $y + $yy, $z + $zz)])){
|
||||
if(!$this->canOverride(BlockFactory::get($level->getBlockIdAt($x + $xx, $y + $yy, $z + $zz)))){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -111,7 +116,7 @@ abstract class Tree{
|
||||
}
|
||||
if(!BlockFactory::get($level->getBlockIdAt($xx, $yy, $zz))->isSolid()){
|
||||
$level->setBlockIdAt($xx, $yy, $zz, $this->leafBlock);
|
||||
$level->setBlockDataAt($xx, $yy, $zz, $this->type);
|
||||
$level->setBlockDataAt($xx, $yy, $zz, $this->blockMeta);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -124,10 +129,14 @@ abstract class Tree{
|
||||
|
||||
for($yy = 0; $yy < $trunkHeight; ++$yy){
|
||||
$blockId = $level->getBlockIdAt($x, $y + $yy, $z);
|
||||
if(isset($this->overridable[$blockId])){
|
||||
if($this->canOverride(BlockFactory::get($blockId))){
|
||||
$level->setBlockIdAt($x, $y + $yy, $z, $this->trunkBlock);
|
||||
$level->setBlockDataAt($x, $y + $yy, $z, $this->type);
|
||||
$level->setBlockDataAt($x, $y + $yy, $z, $this->blockMeta);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function canOverride(Block $block) : bool{
|
||||
return $block->canBeReplaced() or $block instanceof Wood or $block instanceof Sapling or $block instanceof Leaves;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user