mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 00:33:59 +00:00
Remove circular dependency between Tree and its children
This commit is contained in:
parent
4778c1483a
commit
beba0ffe15
@ -26,7 +26,6 @@ namespace pocketmine\world\generator\object;
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\Leaves;
|
||||
use pocketmine\block\Sapling;
|
||||
use pocketmine\block\utils\TreeType;
|
||||
use pocketmine\block\VanillaBlocks;
|
||||
use pocketmine\utils\Random;
|
||||
use pocketmine\world\BlockTransaction;
|
||||
@ -49,32 +48,6 @@ abstract class Tree{
|
||||
$this->treeHeight = $treeHeight;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TreeType|null $type default oak
|
||||
*/
|
||||
public static function get(Random $random, ?TreeType $type = null) : ?self{
|
||||
$type = $type ?? TreeType::OAK();
|
||||
if($type->equals(TreeType::SPRUCE())){
|
||||
return new SpruceTree();
|
||||
}elseif($type->equals(TreeType::BIRCH())){
|
||||
if($random->nextBoundedInt(39) === 0){
|
||||
return new BirchTree(true);
|
||||
}else{
|
||||
return new BirchTree();
|
||||
}
|
||||
}elseif($type->equals(TreeType::JUNGLE())){
|
||||
return new JungleTree();
|
||||
}elseif($type->equals(TreeType::OAK())){ //default
|
||||
return new OakTree();
|
||||
/*if($random->nextRange(0, 9) === 0){
|
||||
$tree = new BigTree();
|
||||
}else{*/
|
||||
|
||||
//}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function canPlaceObject(ChunkManager $world, int $x, int $y, int $z, Random $random) : bool{
|
||||
$radiusToCheck = 0;
|
||||
for($yy = 0; $yy < $this->treeHeight + 3; ++$yy){
|
||||
|
56
src/world/generator/object/TreeFactory.php
Normal file
56
src/world/generator/object/TreeFactory.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?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\world\generator\object;
|
||||
|
||||
use pocketmine\block\utils\TreeType;
|
||||
use pocketmine\utils\Random;
|
||||
|
||||
final class TreeFactory{
|
||||
|
||||
/**
|
||||
* @param TreeType|null $type default oak
|
||||
*/
|
||||
public static function get(Random $random, ?TreeType $type = null) : ?Tree{
|
||||
$type = $type ?? TreeType::OAK();
|
||||
if($type->equals(TreeType::SPRUCE())){
|
||||
return new SpruceTree();
|
||||
}elseif($type->equals(TreeType::BIRCH())){
|
||||
if($random->nextBoundedInt(39) === 0){
|
||||
return new BirchTree(true);
|
||||
}else{
|
||||
return new BirchTree();
|
||||
}
|
||||
}elseif($type->equals(TreeType::JUNGLE())){
|
||||
return new JungleTree();
|
||||
}elseif($type->equals(TreeType::OAK())){ //default
|
||||
return new OakTree();
|
||||
/*if($random->nextRange(0, 9) === 0){
|
||||
$tree = new BigTree();
|
||||
}else{*/
|
||||
|
||||
//}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -27,7 +27,7 @@ use pocketmine\block\BlockLegacyIds;
|
||||
use pocketmine\block\utils\TreeType;
|
||||
use pocketmine\utils\Random;
|
||||
use pocketmine\world\ChunkManager;
|
||||
use pocketmine\world\generator\object\Tree as ObjectTree;
|
||||
use pocketmine\world\generator\object\TreeFactory;
|
||||
|
||||
class Tree extends Populator{
|
||||
/** @var int */
|
||||
@ -62,7 +62,7 @@ class Tree extends Populator{
|
||||
if($y === -1){
|
||||
continue;
|
||||
}
|
||||
$tree = ObjectTree::get($random, $this->type);
|
||||
$tree = TreeFactory::get($random, $this->type);
|
||||
$transaction = $tree?->getBlockTransaction($world, $x, $y, $z, $random);
|
||||
$transaction?->apply();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user