diff --git a/src/Ad5001/BetterGen/Main.php b/src/Ad5001/BetterGen/Main.php index 0f35978..9cf5720 100644 --- a/src/Ad5001/BetterGen/Main.php +++ b/src/Ad5001/BetterGen/Main.php @@ -245,4 +245,12 @@ class Main extends PluginBase implements \pocketmine\event\Listener { LootTable::fillChest($inv->getInventory(), $event->getBlock()); $event->setCancelled(); } + + /* + * Check if it's a Tesseract like namespace + * @return bool + */ + public static function isOtherNS() { + return @class_exists("pocketmine\\level\\generator\\normal\\object\\OakTree"); + } } \ No newline at end of file diff --git a/src/Ad5001/BetterGen/biome/BetterForest.php b/src/Ad5001/BetterGen/biome/BetterForest.php index 8870dae..83384d0 100644 --- a/src/Ad5001/BetterGen/biome/BetterForest.php +++ b/src/Ad5001/BetterGen/biome/BetterForest.php @@ -10,7 +10,6 @@ namespace Ad5001\BetterGen\biome; use pocketmine\level\generator\normal\biome\ForestBiome; use pocketmine\level\generator\biome\Biome; -use pocketmine\level\generator\populator\TallGrass; use Ad5001\BetterGen\Main; use Ad5001\BetterGen\populator\TreePopulator; use Ad5001\BetterGen\populator\BushPopulator; @@ -39,7 +38,7 @@ class BetterForest extends ForestBiome implements Mountainable { $trees->setBaseAmount((null !== @constant(TreePopulator::$types [$type] . "::maxPerChunk" )) ? constant(TreePopulator::$types [$type] . "::maxPerChunk" ) : 5); $this->addPopulator($trees); - $tallGrass = new TallGrass (); + $tallGrass = Main::isOtherNS() ? new \pocketmine\level\generator\normal\populator\TallGrass () : new \pocketmine\level\generator\populator\TallGrass(); $tallGrass->setBaseAmount(3); $this->addPopulator($tallGrass); diff --git a/src/Ad5001/BetterGen/biome/BetterIcePlains.php b/src/Ad5001/BetterGen/biome/BetterIcePlains.php index 507ac46..f85e2e3 100644 --- a/src/Ad5001/BetterGen/biome/BetterIcePlains.php +++ b/src/Ad5001/BetterGen/biome/BetterIcePlains.php @@ -12,8 +12,8 @@ namespace Ad5001\BetterGen\biome; use pocketmine\level\generator\normal\biome\SnowyBiome; use pocketmine\level\generator\biome\Biome; use pocketmine\block\Block; -use pocketmine\level\generator\populator\TallGrass; use Ad5001\BetterGen\populator\IglooPopulator; +use Ad5001\BetterGen\Main; class BetterIcePlains extends SnowyBiome implements Mountainable { public function __construct() { @@ -26,8 +26,8 @@ class BetterIcePlains extends SnowyBiome implements Mountainable { Block::get(Block::DIRT, 0 ) ]); $this->addPopulator(new IglooPopulator ()); - - $tallGrass = new TallGrass (); + + $tallGrass = Main::isOtherNS() ? new \pocketmine\level\generator\normal\populator\TallGrass() : new \pocketmine\level\generator\populator\TallGrass(); $tallGrass->setBaseAmount(3); $this->addPopulator($tallGrass); diff --git a/src/Ad5001/BetterGen/biome/BetterMesa.php b/src/Ad5001/BetterGen/biome/BetterMesa.php index e78b27b..98745c6 100644 --- a/src/Ad5001/BetterGen/biome/BetterMesa.php +++ b/src/Ad5001/BetterGen/biome/BetterMesa.php @@ -15,6 +15,7 @@ use pocketmine\level\generator\object\OreType; use pocketmine\level\generator\biome\Biome; use pocketmine\block\Block; use pocketmine\block\GoldOre; +use Ad5001\BetterGen\Main; use Ad5001\BetterGen\populator\TreePopulator; use Ad5001\BetterGen\populator\CactusPopulator; use Ad5001\BetterGen\populator\DeadbushPopulator; @@ -37,10 +38,10 @@ class BetterMesa extends SandyBiome { $sugarCane = new TreePopulator (); $sugarCane->setRandomAmount(2); $sugarCane->setBaseAmount(0); - - $ores = new Ore (); + + $ores = Main::isOtherNS() ? new \pocketmine\level\generator\normal\populator\Ore() : new \pocketmine\level\generator\populator\Ore(); $ores->setOreTypes([ - new OreType(new GoldOre (), 2, 8, 0, 32 ) + Main::isOtherNS() ? new \pocketmine\level\generator\normal\object\OreType(new GoldOre (), 2, 8, 0, 32 ) : new \pocketmine\level\generator\object\OreType(new GoldOre (), 2, 8, 0, 32 ) ]); $this->addPopulator($cactus); diff --git a/src/Ad5001/BetterGen/biome/BetterMesaPlains.php b/src/Ad5001/BetterGen/biome/BetterMesaPlains.php index 3644898..31ae280 100644 --- a/src/Ad5001/BetterGen/biome/BetterMesaPlains.php +++ b/src/Ad5001/BetterGen/biome/BetterMesaPlains.php @@ -9,7 +9,6 @@ namespace Ad5001\BetterGen\biome; use pocketmine\level\generator\normal\biome\SandyBiome; -use pocketmine\level\generator\populator\Ore; use pocketmine\level\generator\object\OreType; use pocketmine\level\generator\biome\Biome; use pocketmine\block\Block; @@ -17,6 +16,7 @@ use pocketmine\block\GoldOre; use Ad5001\BetterGen\populator\CactusPopulator; use Ad5001\BetterGen\populator\DeadbushPopulator; use Ad5001\BetterGen\populator\SugarCanePopulator; +use Ad5001\BetterGen\Main; class BetterMesaPlains extends SandyBiome { public function __construct() { @@ -31,10 +31,10 @@ class BetterMesaPlains extends SandyBiome { $sugarCane = new SugarCanePopulator (); $sugarCane->setRandomAmount(20); $sugarCane->setBaseAmount(3); - - $ores = new Ore (); + + $ores = Main::isOtherNS() ? new \pocketmine\level\generator\normal\populator\Ore() : new \pocketmine\level\generator\populator\Ore(); $ores->setOreTypes([ - new OreType(new GoldOre (), 20, 8, 0, 32 ) + Main::isOtherNS() ? new \pocketmine\level\generator\normal\object\OreType(new GoldOre (), 2, 8, 0, 32 ) : new \pocketmine\level\generator\object\OreType(new GoldOre (), 2, 8, 0, 32 ) ]); $this->addPopulator($cactus); diff --git a/src/Ad5001/BetterGen/generator/BetterNormal.php b/src/Ad5001/BetterGen/generator/BetterNormal.php index 49f119a..a054306 100644 --- a/src/Ad5001/BetterGen/generator/BetterNormal.php +++ b/src/Ad5001/BetterGen/generator/BetterNormal.php @@ -14,7 +14,7 @@ use pocketmine\level\generator\biome\Biome; use pocketmine\level\generator\Generator; use pocketmine\level\generator\noise\Simplex; use pocketmine\level\generator\object\OreType; -use pocketmine\level\generator\populator\GroundCover; +use pocketmine\level\generator\normal\object\OreType as OreType2; use pocketmine\level\generator\populator\Ore; use pocketmine\block\Block; use pocketmine\block\CoalOre; @@ -38,6 +38,7 @@ use Ad5001\BetterGen\populator\RavinePopulator; use Ad5001\BetterGen\populator\LakePopulator; use Ad5001\BetterGen\populator\MineshaftPopulator; use Ad5001\BetterGen\populator\FloatingIslandPopulator; +use Ad5001\BetterGen\Main; class BetterNormal extends Generator { const NOT_OVERWRITABLE = [ @@ -135,7 +136,7 @@ class BetterNormal extends Generator { $this->selector->recalculate (); - $cover = new GroundCover (); + $cover = Main::isOtherNS() ? new \pocketmine\level\generator\normal\populator\GroundCover() : new \pocketmine\level\generator\populator\GroundCover(); $this->generationPopulators [] = $cover; $cave = new CavePopulator (); @@ -163,8 +164,18 @@ class BetterNormal extends Generator { $fisl->setRandomAmount(132); $this->populators [] = $fisl; - $ores = new Ore (); - $ores->setOreTypes([ + $ores = Main::isOtherNS() ? new \pocketmine\level\generator\normal\populator\Ore() : new \pocketmine\level\generator\populator\Ore(); + if(Main::isOtherNS()) $ores->setOreTypes([ + new OreType2(new CoalOre (), 20, 16, 0, 128 ), + new OreType2(new IronOre (), 20, 8, 0, 64 ), + new OreType2(new RedstoneOre (), 8, 7, 0, 16 ), + new OreType2(new LapisOre (), 1, 6, 0, 32 ), + new OreType2(new GoldOre (), 2, 8, 0, 32 ), + new OreType2(new DiamondOre (), 1, 7, 0, 16 ), + new OreType2(new Dirt (), 20, 32, 0, 128 ), + new OreType2(new Gravel (), 10, 16, 0, 128 ) + ]); + if(!Main::isOtherNS()) $ores->setOreTypes([ new OreType(new CoalOre (), 20, 16, 0, 128 ), new OreType(new IronOre (), 20, 8, 0, 64 ), new OreType(new RedstoneOre (), 8, 7, 0, 16 ), diff --git a/src/Ad5001/BetterGen/populator/BushPopulator.php b/src/Ad5001/BetterGen/populator/BushPopulator.php index 87e2eef..5a89957 100644 --- a/src/Ad5001/BetterGen/populator/BushPopulator.php +++ b/src/Ad5001/BetterGen/populator/BushPopulator.php @@ -44,7 +44,7 @@ class BushPopulator extends AmountPopulator { if ($y === -1) { continue; } - $tree = new TreePopulator::$types [$this->type] (); + $tree = new TreePopulator::$types[$this->type](); $bush = new Bush($tree->leafBlock, $tree->leafType ?? $tree->type); $bush->placeObject($level, $x, $y, $z, $random); } diff --git a/src/Ad5001/BetterGen/populator/FallenTreePopulator.php b/src/Ad5001/BetterGen/populator/FallenTreePopulator.php index 0fe32ee..3d9fb33 100644 --- a/src/Ad5001/BetterGen/populator/FallenTreePopulator.php +++ b/src/Ad5001/BetterGen/populator/FallenTreePopulator.php @@ -17,11 +17,13 @@ use Ad5001\BetterGen\populator\AmountPopulator; class FallenTreePopulator extends AmountPopulator { protected $level; + protected $type; /* * Constructs the class * @param $type int */ - public function __construct() { + public function __construct(int $type = 0) { + $this->setBaseAmount(1); $this->setRandomAmount(2); } @@ -36,13 +38,13 @@ class FallenTreePopulator extends AmountPopulator { public function populate(ChunkManager $level, $chunkX, $chunkZ, Random $random) { $this->level = $level; $amount = $this->getAmount($random); - $fallenTree = new FallenTree(); + $fallenTree = new FallenTree(new TreePopulator::$types[$this->type]()); for($i = 0; $i < $amount; $i++) { $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); + $fallenTree->placeObject($level, $x, $y, $z, $random); } } } diff --git a/src/Ad5001/BetterGen/populator/FloatingIslandPopulator.php b/src/Ad5001/BetterGen/populator/FloatingIslandPopulator.php index 5d387d1..056aebe 100644 --- a/src/Ad5001/BetterGen/populator/FloatingIslandPopulator.php +++ b/src/Ad5001/BetterGen/populator/FloatingIslandPopulator.php @@ -6,8 +6,8 @@ use pocketmine\level\ChunkManager; use pocketmine\utils\Random; use Ad5001\BetterGen\generator\BetterNormal; use pocketmine\block\Block; -use pocketmine\level\generator\populator\Ore; use pocketmine\level\generator\object\OreType; +use pocketmine\level\generator\normal\object\OreType as OreType2; use pocketmine\math\Vector3; use pocketmine\block\CoalOre; use pocketmine\block\IronOre; @@ -15,6 +15,7 @@ use pocketmine\block\RedstoneOre; use pocketmine\block\LapisOre; use pocketmine\block\GoldOre; use pocketmine\block\DiamondOre; +use Ad5001\BetterGen\Main; /* * FloatingIslandPopulator from BetterGen @@ -137,8 +138,16 @@ class FloatingIslandPopulator extends AmountPopulator { * @return void */ public function populateOres(ChunkManager $level, Vector3 $pos, int $width, int $height, Random $random) { - $ores = new Ore (); - $ores->setOreTypes([ + $ores = Main::isOtherNS() ? new \pocketmine\level\generator\normal\populator\Ore() : new \pocketmine\level\generator\populator\Ore(); + if(Main::isOtherNS()) $ores->setOreTypes([ + new OreType2(new CoalOre (), 20, 16, $pos->y - $height, $pos->y ), + new OreType2(new IronOre (), 20, 8, $pos->y - $height, $pos->y - round($height * 0.75)), + new OreType2(new RedstoneOre (), 8, 7, $pos->y - $height, $pos->y - round($height / 2)), + new OreType2(new LapisOre (), 1, 6, $pos->y - $height, $pos->y - round($height / 2)), + new OreType2(new GoldOre (), 2, 8, $pos->y - $height, $pos->y - round($height / 2)), + new OreType2(new DiamondOre (), 1, 7, $pos->y - $height, $pos->y - round($height / 4)) + ]); + if(!Main::isOtherNS()) $ores->setOreTypes([ new OreType(new CoalOre (), 20, 16, $pos->y - $height, $pos->y ), new OreType(new IronOre (), 20, 8, $pos->y - $height, $pos->y - round($height * 0.75)), new OreType(new RedstoneOre (), 8, 7, $pos->y - $height, $pos->y - round($height / 2)), diff --git a/src/Ad5001/BetterGen/populator/TreePopulator.php b/src/Ad5001/BetterGen/populator/TreePopulator.php index ee90e1d..72c431a 100644 --- a/src/Ad5001/BetterGen/populator/TreePopulator.php +++ b/src/Ad5001/BetterGen/populator/TreePopulator.php @@ -14,6 +14,8 @@ use pocketmine\block\Block; use pocketmine\level\ChunkManager; use Ad5001\BetterGen\structure\SakuraTree; use Ad5001\BetterGen\populator\AmountPopulator; +use Ad5001\BetterGen\Main; + class TreePopulator extends AmountPopulator { static $types = [ @@ -29,6 +31,13 @@ class TreePopulator extends AmountPopulator { */ public function __construct($type = 0) { $this->type = $type; + if(Main::isOtherNS()) { + self::$types = [ + "pocketmine\\level\\generator\\normal\\object\\OakTree", + "pocketmine\\level\\generator\\normal\\object\\BirchTree", + "Ad5001\\BetterGen\\structure\\SakuraTree" + ]; + } } /* diff --git a/src/Ad5001/BetterGen/structure/FallenTree.php b/src/Ad5001/BetterGen/structure/FallenTree.php index 58105c7..d93ed97 100644 --- a/src/Ad5001/BetterGen/structure/FallenTree.php +++ b/src/Ad5001/BetterGen/structure/FallenTree.php @@ -1,7 +1,7 @@ true, 17 => true, Block::SNOW_LAYER => true, Block::LOG2 => true ]; - protected $trunk; + protected $tree; protected $direction; /* * Constructs the class - * @param $trunkId int - * @param $trunkData int + * @param $tree Tree + * @throws Exeption */ - public function __construct($trunk = Block::WOOD, $trunkData = 0) { - $this->trunk = [ - $trunkId, - $trunkData - ]; + 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."); + } + $this->tree = $tree; } /* @@ -46,7 +48,19 @@ class Bush extends Object { * @param $z int * @param $random pocketmine\utils\Random */ - public function placeObject(ChunkManager $level, $x, $y, $z, Random $random) { + public function canPlaceObject(ChunkManager $level, $x, $y, $z, Random $random) { + $randomHeight = round($random->nextBoundedInt(6) - 3); + $this->length = $this->tree->trunkHeight + $randomHeight; + } + + /* + * Places a fallen tree + * @param $level pocketmine\level\ChunkManager + * @param $x int + * @param $y int + * @param $z int + */ + public function placeObject(ChunkManager $level, $x, $y, $z) { $number = $random->nextBoundedInt(6); $pos = new Vector3($x, $y, $z); $this->placeLeaf($pos->x, $pos->y, $pos->z, $level); diff --git a/src/Ad5001/BetterGen/structure/SakuraTree.php b/src/Ad5001/BetterGen/structure/SakuraTree.php index 70f5821..d801473 100644 --- a/src/Ad5001/BetterGen/structure/SakuraTree.php +++ b/src/Ad5001/BetterGen/structure/SakuraTree.php @@ -13,7 +13,12 @@ use pocketmine\block\Block; use pocketmine\block\Wood; use pocketmine\level\ChunkManager; use pocketmine\utils\Random; -use pocketmine\level\generator\object\Tree; +use Ad5001\BetterGen\Main; +if(Main::isOtherNS()) { + class_alias("pocketmine\\level\\generator\\normal\\object\\Tree", "Ad5001\\BetterGen\\structure\\Tree"); +} else { + class_alias("pocketmine\\level\\generator\\object\\Tree", "Ad5001\\BetterGen\\structure\\Tree"); +} class SakuraTree extends Tree { const TRUNK_POS = [ // Checks for trees trunks. Not automaticly generated but there is no point of making more or less @@ -427,6 +432,9 @@ class SakuraTree extends Tree { ] ]; const maxPerChunk = 2; + + + public $trunkHeight = 11; /* * Constructs the class diff --git a/src/Ad5001/BetterGen/tasks/ChestGenerateTask.php b/src/Ad5001/BetterGen/tasks/ChestGenerateTask.php deleted file mode 100644 index 2881fbc..0000000 --- a/src/Ad5001/BetterGen/tasks/ChestGenerateTask.php +++ /dev/null @@ -1,44 +0,0 @@ -block = $block; - $this->pos = $pos; - $this->item = $item; - } - - /* - * Runs when the delay comes - */ - public function onRun($currentTick) { - $this->block->place($this->item, $this->pos->getLevel()->getBlock($this->pos), $this->block, 0, 0, 0, 0); - $inv = $this->pos->getLevel()->getTile($this->pos); - LootTable::fillChest($inv->getInventory(), $this->pos); - } -} \ No newline at end of file