From 5362a4cb815f9b5ce2101ec252fbbbed0f960920 Mon Sep 17 00:00:00 2001 From: Ad5001 Date: Thu, 11 May 2017 07:46:44 +0200 Subject: [PATCH] Adding fallen trees + some tweaking.. --- src/Ad5001/BetterGen/Main.php | 3 --- src/Ad5001/BetterGen/biome/BetterForest.php | 10 +++++++++- src/Ad5001/BetterGen/generator/BetterNormal.php | 1 - src/Ad5001/BetterGen/populator/CavePopulator.php | 2 +- .../BetterGen/populator/FallenTreePopulator.php | 7 ++++--- src/Ad5001/BetterGen/structure/FallenTree.php | 14 +++++--------- 6 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/Ad5001/BetterGen/Main.php b/src/Ad5001/BetterGen/Main.php index b457aa3..8fe39cd 100644 --- a/src/Ad5001/BetterGen/Main.php +++ b/src/Ad5001/BetterGen/Main.php @@ -138,7 +138,6 @@ class Main extends PluginBase implements \pocketmine\event\Listener { $options["preset"] = json_encode($options); if((int) $seed == 0/*String*/){ $seed = $this->generateRandomSeed(); - echo "Rechoosen seed"; } $this->getServer()->broadcastMessage(Main::PREFIX . "§aGenerating level $name with generator $generatorName and seed $seed.."); $this->getServer()->generateLevel($name, $seed, $generator, $options); @@ -211,7 +210,6 @@ class Main extends PluginBase implements \pocketmine\event\Listener { $cfg = new Config(LootTable::getPluginFolder() . "processingLoots.json", Config::JSON); if($event->getBlock()->getId() !== Block::CHEST) return; if(!$cfg->exists($event->getBlock()->getX() . ";" . $event->getBlock()->getY() . ";" . $event->getBlock()->getZ())) return; - echo "Doing {$event->getBlock()}"; $chest = new \pocketmine\block\Chest(0); $nbt = new CompoundTag("", [ new ListTag("Items", []), @@ -236,7 +234,6 @@ class Main extends PluginBase implements \pocketmine\event\Listener { $cfg = new Config(LootTable::getPluginFolder() . "processingLoots.json", Config::JSON); if($event->getBlock()->getId() !== Block::CHEST) return; if(!$cfg->exists($event->getBlock()->getX() . ";" . $event->getBlock()->getY() . ";" . $event->getBlock()->getZ())) return; - echo "Doing {$event->getBlock()}"; $chest = new \pocketmine\block\Chest(0); $nbt = new CompoundTag("", [ new ListTag("Items", []), diff --git a/src/Ad5001/BetterGen/biome/BetterForest.php b/src/Ad5001/BetterGen/biome/BetterForest.php index 95396f2..eaffb3b 100644 --- a/src/Ad5001/BetterGen/biome/BetterForest.php +++ b/src/Ad5001/BetterGen/biome/BetterForest.php @@ -20,6 +20,8 @@ use pocketmine\level\generator\biome\Biome; use Ad5001\BetterGen\Main; use Ad5001\BetterGen\populator\TreePopulator; use Ad5001\BetterGen\populator\BushPopulator; +use Ad5001\BetterGen\populator\FallenTreePopulator; + class BetterForest extends ForestBiome implements Mountainable { static $types = [ @@ -41,6 +43,12 @@ class BetterForest extends ForestBiome implements Mountainable { $bush = new BushPopulator($type); $bush->setBaseAmount(10); $this->addPopulator($bush); + + $ft = new FallenTreePopulator($type); + $ft->setBaseAmount(0); + $ft->setRandomAmount(4); + $this->addPopulator($ft); + $trees = new TreePopulator($type); $trees->setBaseAmount((null !== @constant(TreePopulator::$types [$type] . "::maxPerChunk" )) ? constant(TreePopulator::$types [$type] . "::maxPerChunk" ) : 5); $this->addPopulator($trees); @@ -50,7 +58,7 @@ class BetterForest extends ForestBiome implements Mountainable { $this->addPopulator($tallGrass); - $this->setElevation(63, 81); + $this->setElevation(63, 69); $this->temperature = $infos [0]; $this->rainfall = $infos [1]; diff --git a/src/Ad5001/BetterGen/generator/BetterNormal.php b/src/Ad5001/BetterGen/generator/BetterNormal.php index e1fd9cf..e9a56ea 100644 --- a/src/Ad5001/BetterGen/generator/BetterNormal.php +++ b/src/Ad5001/BetterGen/generator/BetterNormal.php @@ -214,7 +214,6 @@ class BetterNormal extends Generator { */ public static function registerBiome(Biome $biome): bool { if(\Ad5001\BetterGen\utils\CommonUtils::in_arrayi($biome->getName(), self::$options["deleteBiomes"])) { - echo "Removing " . $biome->getName() . "...\n"; return false; } foreach(self::$levels as $lvl ) if(isset($lvl->selector)) $lvl->selector->addBiome($biome); // If no selector created, it would cause errors. These will be added when selectoes diff --git a/src/Ad5001/BetterGen/populator/CavePopulator.php b/src/Ad5001/BetterGen/populator/CavePopulator.php index eb4b946..76510b8 100644 --- a/src/Ad5001/BetterGen/populator/CavePopulator.php +++ b/src/Ad5001/BetterGen/populator/CavePopulator.php @@ -45,7 +45,7 @@ class CavePopulator extends AmountPopulator { } // echo "Finished Populating chunk $chunkX, $chunkZ !" . PHP_EOL; // Filling water & lava sources randomly - for($i = 0; $i < $random->nextBoundedInt(10 ) + 15; $i ++) { + for($i = 0; $i < $random->nextBoundedInt(5) + 3; $i ++) { $x = $random->nextRange($chunkX << 4, ($chunkX << 4) + 15); $z = $random->nextRange($chunkZ << 4, ($chunkZ << 4) + 15); $y = $random->nextRange(10, $this->getHighestWorkableBlock($x, $z )); diff --git a/src/Ad5001/BetterGen/populator/FallenTreePopulator.php b/src/Ad5001/BetterGen/populator/FallenTreePopulator.php index 6e11758..0910ccc 100644 --- a/src/Ad5001/BetterGen/populator/FallenTreePopulator.php +++ b/src/Ad5001/BetterGen/populator/FallenTreePopulator.php @@ -20,6 +20,7 @@ use pocketmine\utils\Random; use Ad5001\BetterGen\structure\FallenTree; use Ad5001\BetterGen\populator\AmountPopulator; + class FallenTreePopulator extends AmountPopulator { protected $level; protected $type; @@ -28,7 +29,7 @@ class FallenTreePopulator extends AmountPopulator { * @param $type int */ public function __construct(int $type = 0) { - + $this->type = $type; $this->setBaseAmount(1); $this->setRandomAmount(2); } @@ -49,8 +50,8 @@ class FallenTreePopulator extends AmountPopulator { $x = $random->nextRange($chunkX * 16, $chunkX * 16 + 15); $z = $random->nextRange($chunkZ * 16, $chunkZ * 16 + 15); $y = $this->getHighestWorkableBlock($x, $z); - if ($y !== -1 and $fallenTree->canPlaceObject($level, $x, $y, $z, $random )) { - $fallenTree->placeObject($level, $x, $y, $z, $random); + if ($y !== -1 and $fallenTree->canPlaceObject($level, $x, $y + 1, $z, $random )) { + $fallenTree->placeObject($level, $x, $y + 1, $z, $random); } } } diff --git a/src/Ad5001/BetterGen/structure/FallenTree.php b/src/Ad5001/BetterGen/structure/FallenTree.php index 385047f..8efdba3 100644 --- a/src/Ad5001/BetterGen/structure/FallenTree.php +++ b/src/Ad5001/BetterGen/structure/FallenTree.php @@ -19,8 +19,6 @@ use pocketmine\block\Block; use pocketmine\level\ChunkManager; use pocketmine\utils\Random; use pocketmine\math\Vector3; -use pocketmine\level\generator\object\Tree; -use pocketmine\level\generator\normal\object\Tree as Tree2; use pocketmine\level\generator\object\Object; use Ad5001\BetterGen\utils\BuildingUtils; @@ -44,13 +42,10 @@ class FallenTree extends Object { /* * Constructs the class - * @param $tree Tree + * @param $tree Tree * @throws Exeption */ - public function __construct($tree) { - if(!is_subclass_of($tree, Tree::class) && !is_subclass_of($tree, Tree2::class)) { - throw new Exception("Argument 1 passed to \\Ad5001\\BetterGen\\structure\\FallenTree must be an instance of pocketmine\\level\\generator\\normal\\object\\Tree or pocketmine\\level\\generator\\object\\Tree. Instance of " . get_class($tree) . " given."); - } + public function __construct(Tree $tree) { $this->tree = $tree; } @@ -71,7 +66,7 @@ class FallenTree extends Object { case 0: case 1:// Z+ if(in_array(false, BuildingUtils::fillCallback(new Vector3($x, $y, $z), new Vector3($x, $y, $z + $this->length), function($v3, $level) { - if(!in_array($level->getBlockIdAt($v3->x, $v3->y, $v3->z), \Ad5001\BetterGen\structure\FallenTree::$overridable)) return false; + if(!in_array($level->getBlockIdAt($v3->x, $v3->y, $v3->z), $this->overridable)) return false; }, $level))) { return false; } @@ -79,7 +74,7 @@ class FallenTree extends Object { case 2: case 3: // X+ if(in_array(false, BuildingUtils::fillCallback(new Vector3($x, $y, $z), new Vector3($x + $this->length, $y, $z), function($v3, $level) { - if(!in_array($level->getBlockIdAt($v3->x, $v3->y, $v3->z), \Ad5001\BetterGen\structure\FallenTree::$overridable)) return false; + if(!in_array($level->getBlockIdAt($v3->x, $v3->y, $v3->z), $this->overridable)) return false; }, $level))) { return false; } @@ -96,6 +91,7 @@ class FallenTree extends Object { * @param $z int */ public function placeObject(ChunkManager $level, $x, $y, $z) { + echo "Placing at $x $y $z FallenTree\n"; switch($this->direction) { case 0: $level->setBlockIdAt($x, $y, $z, $this->tree->trunkBlock);