From b73d3c981c61eb9efa381dbcb21dc2caca5eed3c Mon Sep 17 00:00:00 2001 From: Ad5001 Date: Wed, 10 May 2017 17:03:04 +0200 Subject: [PATCH] Big update ! - Updating headers, - Adding first setting, deleteBiomes, wiki comming soon --- plugin.yml | 20 ++++- src/Ad5001/BetterGen/Main.php | 31 ++++--- src/Ad5001/BetterGen/biome/BetterDesert.php | 19 +++-- src/Ad5001/BetterGen/biome/BetterForest.php | 19 +++-- .../BetterGen/biome/BetterIcePlains.php | 19 +++-- src/Ad5001/BetterGen/biome/BetterMesa.php | 19 +++-- .../BetterGen/biome/BetterMesaPlains.php | 20 +++-- src/Ad5001/BetterGen/biome/BetterRiver.php | 19 +++-- src/Ad5001/BetterGen/biome/Mountainable.php | 17 ++-- .../generator/BetterBiomeSelector.php | 20 +++-- .../BetterGen/generator/BetterNormal.php | 85 +++++++++++-------- src/Ad5001/BetterGen/loot/LootTable.php | 17 ++-- .../BetterGen/populator/AmountPopulator.php | 17 ++-- .../BetterGen/populator/BushPopulator.php | 18 ++-- .../BetterGen/populator/CactusPopulator.php | 18 ++-- .../BetterGen/populator/CavePopulator.php | 18 ++-- .../BetterGen/populator/DeadbushPopulator.php | 17 ++-- .../populator/FallenTreePopulator.php | 17 ++-- .../populator/FloatingIslandPopulator.php | 21 +++-- .../BetterGen/populator/IglooPopulator.php | 18 ++-- .../BetterGen/populator/LakePopulator.php | 18 ++-- .../populator/MineshaftPopulator.php | 18 ++-- .../BetterGen/populator/RavinePopulator.php | 18 ++-- .../populator/SugarCanePopulator.php | 17 ++-- .../BetterGen/populator/TemplePopulator.php | 18 ++-- .../BetterGen/populator/TreePopulator.php | 24 +++--- .../BetterGen/populator/WellPopulator.php | 18 ++-- src/Ad5001/BetterGen/structure/Bush.php | 17 ++-- src/Ad5001/BetterGen/structure/Cactus.php | 18 ++-- src/Ad5001/BetterGen/structure/FallenTree.php | 29 +++++-- src/Ad5001/BetterGen/structure/Igloo.php | 17 ++-- src/Ad5001/BetterGen/structure/SakuraTree.php | 17 ++-- src/Ad5001/BetterGen/structure/SugarCane.php | 17 ++-- src/Ad5001/BetterGen/structure/Temple.php | 17 ++-- src/Ad5001/BetterGen/structure/Well.php | 18 ++-- src/Ad5001/BetterGen/utils/BuildingUtils.php | 50 +++++++---- src/Ad5001/BetterGen/utils/CommonUtils.php | 29 +++++++ 37 files changed, 534 insertions(+), 275 deletions(-) create mode 100644 src/Ad5001/BetterGen/utils/CommonUtils.php diff --git a/plugin.yml b/plugin.yml index a91e916..db56c8c 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,17 +1,31 @@ --- -# Base generated with ImagicalPlugCreator by Ad5001 (C) 2017 for Ad5001 -# link: https://ad5001.eu +# ____ __ __ ____ +# /\ _`\ /\ \__ /\ \__ /\ _`\ +# \ \ \L\ \ __ \ \ ,_\\ \ ,_\ __ _ __ \ \ \L\_\ __ ___ +# \ \ _ <' /'__`\\ \ \/ \ \ \/ /'__`\/\`'__\\ \ \L_L /'__`\ /' _ `\ +# \ \ \L\ \/\ __/ \ \ \_ \ \ \_ /\ __/\ \ \/ \ \ \/, \/\ __/ /\ \/\ \ +# \ \____/\ \____\ \ \__\ \ \__\\ \____\\ \_\ \ \____/\ \____\\ \_\ \_\ +# \/___/ \/____/ \/__/ \/__/ \/____/ \/_/ \/___/ \/____/ \/_/\/_/ +# Tommorow's pocketmine generator. +# @author Ad5001 +# @link https://github.com/Ad5001/BetterGen name: BetterGen author: Ad5001 main: Ad5001\BetterGen\Main -version: 1.0 +version: 1.1 api: [3.0.1, 3.0.0-ALPHA3] commands: createworld: description: Generates a new world. usage: "/createworld [generator = betternormal] [seed = rand()] [options (json)]" permission: bettergen.cmd.createworld + worldtp: + description: Teleports you to an another world + usage: "/worldtp " + permission: bettergen.cmd.worldtp permissions: bettergen.cmd.createworld: default: op + bettergen.cmd.worldtp: + default: op ... \ No newline at end of file diff --git a/src/Ad5001/BetterGen/Main.php b/src/Ad5001/BetterGen/Main.php index 0bf52bc..b457aa3 100644 --- a/src/Ad5001/BetterGen/Main.php +++ b/src/Ad5001/BetterGen/Main.php @@ -1,10 +1,15 @@ generateRandomSeed(); if(preg_match("[^\d]", $args [2]) !== false) { $parts = str_split($args [2]); foreach($parts as $key => $str) { @@ -123,12 +129,17 @@ class Main extends PluginBase implements \pocketmine\event\Listener { } unset($args [0], $args [1], $args [2]); $options = json_decode($args [3], true); - if(! is_array($json)) { + if(! is_array($options)) { $sender->sendMessage(Main::PREFIX . "§4Invalid JSON for options."); return true; } break; } + $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); $this->getServer()->loadLevel($name); @@ -161,10 +172,6 @@ class Main extends PluginBase implements \pocketmine\event\Listener { * @return void */ public static function registerBiome(int $id, Biome $biome) { - $reflection = new \ReflectionClass('pocketmine\\level\\generator\\biome\\Biome'); - $register = $reflection->getMethod('register'); - $register->setAccessible(true); - $register->invoke(null, $id, $biome); BetterNormal::registerBiome($biome); } @@ -173,7 +180,7 @@ class Main extends PluginBase implements \pocketmine\event\Listener { * @return int */ public function generateRandomSeed(): int { - return(int) round(time() * rand(0, time()) / memory_get_usage()); + return (int) round(rand(0, round(time()) / memory_get_usage(true)) * (int) str_shuffle("127469453645108") / (int) str_shuffle("12746945364")); } // Listener diff --git a/src/Ad5001/BetterGen/biome/BetterDesert.php b/src/Ad5001/BetterGen/biome/BetterDesert.php index 1987419..b4e715d 100644 --- a/src/Ad5001/BetterGen/biome/BetterDesert.php +++ b/src/Ad5001/BetterGen/biome/BetterDesert.php @@ -1,10 +1,15 @@ rainfall = $infos [1]; } public function getName() { - return self::$types [$this->type]; + return str_ireplace(" ", "", self::$types[$this->type]); } /* diff --git a/src/Ad5001/BetterGen/biome/BetterIcePlains.php b/src/Ad5001/BetterGen/biome/BetterIcePlains.php index f85e2e3..5b58eb1 100644 --- a/src/Ad5001/BetterGen/biome/BetterIcePlains.php +++ b/src/Ad5001/BetterGen/biome/BetterIcePlains.php @@ -1,10 +1,15 @@ rainfall = 0.8; } public function getName() { - return "Better Ice Plains"; + return "BetterIcePlains"; } /* diff --git a/src/Ad5001/BetterGen/biome/BetterMesa.php b/src/Ad5001/BetterGen/biome/BetterMesa.php index 98745c6..f49eaf6 100644 --- a/src/Ad5001/BetterGen/biome/BetterMesa.php +++ b/src/Ad5001/BetterGen/biome/BetterMesa.php @@ -1,10 +1,15 @@ rainfall = 0.7; } public function getName() { - return "Better River"; + return "BetterRiver"; } /* diff --git a/src/Ad5001/BetterGen/biome/Mountainable.php b/src/Ad5001/BetterGen/biome/Mountainable.php index f250ab6..6c47f0d 100644 --- a/src/Ad5001/BetterGen/biome/Mountainable.php +++ b/src/Ad5001/BetterGen/biome/Mountainable.php @@ -1,10 +1,15 @@ getRainfall($x, $z )); $biomeId = BetterNormal::getBiome($temperature, $rainfall); - // $biomeId = new \Ad5001\BetterGen\biome\BetterDesert(); $b = (($biomeId instanceof Biome) ? $biomeId : ($this->biomes [$biomeId] ?? $this->fallback)); return $b; } diff --git a/src/Ad5001/BetterGen/generator/BetterNormal.php b/src/Ad5001/BetterGen/generator/BetterNormal.php index b4df4e4..e1fd9cf 100644 --- a/src/Ad5001/BetterGen/generator/BetterNormal.php +++ b/src/Ad5001/BetterGen/generator/BetterNormal.php @@ -1,11 +1,17 @@ [ + ] + ]; protected $waterHeight = 63; /* @@ -91,6 +101,13 @@ class BetterNormal extends Generator { } return $b; } + + /** + * Inits the class for the var + * @param ChunkManager $level + * @param Random $random + * @return void + */ public function init(ChunkManager $level, Random $random) { $this->level = $level; $this->random = $random; @@ -139,10 +156,16 @@ class BetterNormal extends Generator { $cover = Main::isOtherNS() ? new \pocketmine\level\generator\normal\populator\GroundCover() : new \pocketmine\level\generator\populator\GroundCover(); $this->generationPopulators [] = $cover; + // https://twitter.com/Ad5001P4F/status/859430935468670976 + // $lake = new LakePopulator (); + // $lake->setBaseAmount(0); + // $lake->setRandomAmount(1); + // $this->generationPopulators [] = $lake; + $cave = new CavePopulator (); $cave->setBaseAmount(0); $cave->setRandomAmount(2); - $this->populators [] = $cave; + $this->generationPopulators [] = $cave; $ravine = new RavinePopulator (); $ravine->setBaseAmount(0); @@ -153,12 +176,6 @@ class BetterNormal extends Generator { $mineshaft->setBaseAmount(0); $mineshaft->setRandomAmount(102); $this->populators [] = $mineshaft; - - // https://twitter.com/Ad5001P4F/status/859430935468670976 - // $lake = new LakePopulator (); - // $lake->setBaseAmount(0); - // $lake->setRandomAmount(1); - // $this->generationPopulators [] = $lake; $fisl = new FloatingIslandPopulator(); @@ -196,11 +213,12 @@ class BetterNormal extends Generator { * @return bool */ public static function registerBiome(Biome $biome): bool { - 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 - if (! isset(self::$biomes [( string ) $biome->getRainfall ()] )) - self::$biomes [( string ) $biome->getRainfall ()] = [ ]; + 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 + if (! isset(self::$biomes[(string) $biome->getRainfall ()] )) self::$biomes [( string ) $biome->getRainfall ()] = [ ]; self::$biomes [( string ) $biome->getRainfall ()] [( string ) $biome->getTemperature ()] = $biome; ksort(self::$biomes [( string ) $biome->getRainfall ()]); ksort(self::$biomes); @@ -256,7 +274,6 @@ class BetterNormal extends Generator { * @param $chunkZ int */ public function generateChunk($chunkX, $chunkZ) { - $this->reRegisterBiomes (); $this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed ()); @@ -343,7 +360,7 @@ class BetterNormal extends Generator { } $chunk = $this->level->getChunk($chunkX, $chunkZ); - $biome = Biome::getBiome($chunk->getBiomeId(7, 7 )); + $biome = self::getBiomeById($chunk->getBiomeId(7, 7 )); $biome->populateChunk($this->level, $chunkX, $chunkZ, $this->random); } @@ -352,6 +369,18 @@ class BetterNormal extends Generator { * @param $options array */ public function __construct(array $options = []) { + self::$options["preset"] = $options["preset"]; + $options = (array) json_decode($options["preset"]); + if(isset($options["deleteBiomes"]) && is_string($options["deleteBiomes"])) { + $options["deleteBiomes"] = explode(",", $options["deleteBiomes"]); + if(count($options["deleteBiomes"]) !== 0) { + self::$options["deleteBiomes"] = $options["deleteBiomes"]; + } + } + + if(isset($options["deleteBiomes"]) && count($options["deleteBiomes"]) !== 0) { + self::$options["deleteBiomes"] = $options["deleteBiomes"]; + } if (self::$GAUSSIAN_KERNEL === null) { self::generateKernel (); } @@ -387,7 +416,7 @@ class BetterNormal extends Generator { * @return array */ public function getSettings(): array { - return [ ]; + return self::$options; } public function getSpawn() { return new Vector3(127.5, 128, 127.5); @@ -417,18 +446,4 @@ class BetterNormal extends Generator { return $y++; } - - /* - * Re registers all biomes for async - */ - public function reRegisterBiomes() { - $reflection = new \ReflectionClass('pocketmine\\level\\generator\\biome\\Biome'); - $register = $reflection->getMethod('register'); - $register->setAccessible(true); - foreach(self::$biomes as $rainfall => $arr ) { - foreach($arr as $tmp => $biome ) { - $register->invoke(null, $biome->getId (), $biome); - } - } - } } \ No newline at end of file diff --git a/src/Ad5001/BetterGen/loot/LootTable.php b/src/Ad5001/BetterGen/loot/LootTable.php index 94446d7..cd0798f 100644 --- a/src/Ad5001/BetterGen/loot/LootTable.php +++ b/src/Ad5001/BetterGen/loot/LootTable.php @@ -1,10 +1,15 @@ type] (); - if ($tree->canPlaceObject($level, $x, $y, $z, $random )) { - $tree->placeObject($level, $x, $y, $z, $random); - } + $treeC = self::$types [$this->type]; + $tree = new $treeC(); + $tree->placeObject($level, $x, $y, $z, $random); } } diff --git a/src/Ad5001/BetterGen/populator/WellPopulator.php b/src/Ad5001/BetterGen/populator/WellPopulator.php index 2806e6c..f49d675 100644 --- a/src/Ad5001/BetterGen/populator/WellPopulator.php +++ b/src/Ad5001/BetterGen/populator/WellPopulator.php @@ -1,11 +1,17 @@ nextBoundedInt(6) - 3); $this->length = $this->tree->trunkHeight + $randomHeight; $this->direction = $random->nextBoundedInt(4); + $this->random = $random; switch($this->direction) { case 0: case 1:// Z+ @@ -70,7 +77,7 @@ class FallenTree extends Object { } break; case 2: - case 3: + 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; }, $level))) { @@ -96,13 +103,17 @@ class FallenTree extends Object { $z += 2; case 1:// Z+ BuildingUtils::fill($level, new Vector3($x, $y, $z), new Vector3($x, $y, $z + $this->length), Block::get($this->tree->trunkBlock, $this->tree->type + 4)); + BuildingUtils::fillRandom($level, new Vector3($x + 1, $y, $z), new Vector3($x, $y, $z + $this->length), Block::get(Block::VINE), $this->random); + BuildingUtils::fillRandom($level, new Vector3($x - 1, $y, $z), new Vector3($x, $y, $z + $this->length), Block::get(Block::VINE), $this->random); break; case 2: $level->setBlockIdAt($x, $y, $z, $this->tree->trunkBlock); $level->setBlockDataAt($x, $y, $z, $this->tree->type); $x += 2; - case 3: - BuildingUtils::fill($level, new Vector3($x, $y, $z), new Vector3($x, $y, $z + $this->length), Block::get($this->tree->trunkBlock, $this->tree->type + 4)); + case 3: // X+ + BuildingUtils::fill($level, new Vector3($x, $y, $z), new Vector3($x + $this->length, $y, $z), Block::get($this->tree->trunkBlock, $this->tree->type + 8)); + BuildingUtils::fillRandom($level, new Vector3($x, $y, $z + 1), new Vector3($x + $this->length, $y, $z), Block::get(Block::VINE), $this->random); + BuildingUtils::fillRandom($level, new Vector3($x, $y, $z - 1), new Vector3($x + $this->length, $y, $z), Block::get(Block::VINE), $this->random); break; } // Second call to build the last wood block diff --git a/src/Ad5001/BetterGen/structure/Igloo.php b/src/Ad5001/BetterGen/structure/Igloo.php index dab321e..71a231f 100644 --- a/src/Ad5001/BetterGen/structure/Igloo.php +++ b/src/Ad5001/BetterGen/structure/Igloo.php @@ -1,10 +1,15 @@ x; $x >= $pos2->x; $x --) - for($y = $pos1->y; $y >= $pos2->y; $y --) - for($z = $pos1->z; $z >= $pos2->z; $z --) { + for($x = $pos1->x; $x >= $pos2->x; $x --) for($y = $pos1->y; $y >= $pos2->y; $y --) for($z = $pos1->z; $z >= $pos2->z; $z --) { + $level->setBlockIdAt($x, $y, $z, $block->getId ()); + $level->setBlockDataAt($x, $y, $z, $block->getDamage ()); + } + } + + + /* + * Fills an area randomly + * @param $level pocketmine\level\ChunkManager + * @param $pos1 pocketmine\math\Vector3 + * @param $pos2 pocketmine\math\Vector3 + * @param $block pocketmine\block\Block + * @param $random pocketmine\utils + * @param $randMax pocketmine\utils + * @return void + */ + public static function fillRandom(ChunkManager $level, Vector3 $pos1, Vector3 $pos2, Block $block = null, Random $random = null, $randMax = 3) { + if ($block == null) $block = Block::get(Block::AIR); + list($pos1, $pos2 ) = self::minmax($pos1, $pos2); + for($x = $pos1->x; $x >= $pos2->x; $x --) for($y = $pos1->y; $y >= $pos2->y; $y --) for($z = $pos1->z; $z >= $pos2->z; $z --) if($random !== null ? $random->nextBoundedInt($randMax) == 0 : rand(0, $randMax) == 0) { $level->setBlockIdAt($x, $y, $z, $block->getId ()); $level->setBlockDataAt($x, $y, $z, $block->getDamage ()); } @@ -56,9 +78,7 @@ class BuildingUtils { public static function fillCallback(Vector3 $pos1, Vector3 $pos2, callable $call, ...$params) : array { list($pos1, $pos2 ) = self::minmax($pos1, $pos2); $return = []; - for($x = $pos1->x; $x >= $pos2->x; $x --) - for($y = $pos1->y; $y >= $pos2->y; $y --) - for($z = $pos1->z; $z >= $pos2->z; $z --) { + for($x = $pos1->x; $x >= $pos2->x; $x --) for($y = $pos1->y; $y >= $pos2->y; $y --) for($z = $pos1->z; $z >= $pos2->z; $z --) { $return[] = call_user_func($call, new Vector3($x, $y, $z ), ...$params); } return $return; diff --git a/src/Ad5001/BetterGen/utils/CommonUtils.php b/src/Ad5001/BetterGen/utils/CommonUtils.php new file mode 100644 index 0000000..edf21db --- /dev/null +++ b/src/Ad5001/BetterGen/utils/CommonUtils.php @@ -0,0 +1,29 @@ +