From a7b8469c9ca037c20d842d46da927c0a279c9044 Mon Sep 17 00:00:00 2001 From: thebigsmileXD Date: Thu, 11 May 2017 16:41:42 +0200 Subject: [PATCH] Fix generation issues --- .../BetterGen/generator/BetterNormal.php | 2 +- .../BetterGen/populator/BushPopulator.php | 2 +- .../BetterGen/populator/CactusPopulator.php | 2 +- .../BetterGen/populator/CavePopulator.php | 2 +- .../BetterGen/populator/DeadbushPopulator.php | 29 ++++++++++++------- .../populator/FallenTreePopulator.php | 11 ++++--- .../populator/FloatingIslandPopulator.php | 2 +- .../BetterGen/populator/IglooPopulator.php | 2 +- .../BetterGen/populator/LakePopulator.php | 2 +- .../BetterGen/populator/RavinePopulator.php | 2 +- .../populator/SugarCanePopulator.php | 2 +- .../BetterGen/populator/TemplePopulator.php | 2 +- .../BetterGen/populator/TreePopulator.php | 2 +- .../BetterGen/populator/WellPopulator.php | 2 +- src/Ad5001/BetterGen/structure/SakuraTree.php | 3 +- src/Ad5001/BetterGen/structure/Temple.php | 17 ++++++----- 16 files changed, 47 insertions(+), 37 deletions(-) diff --git a/src/Ad5001/BetterGen/generator/BetterNormal.php b/src/Ad5001/BetterGen/generator/BetterNormal.php index be0936a..70c914c 100644 --- a/src/Ad5001/BetterGen/generator/BetterNormal.php +++ b/src/Ad5001/BetterGen/generator/BetterNormal.php @@ -438,7 +438,7 @@ class BetterNormal extends Generator { * @param $z int */ protected function getHighestWorkableBlock($x, $z) { - for($y = Level::Y_MAX; $y > 0; -- $y) { + for($y = Level::Y_MAX - 1; $y > 0; -- $y) { $b = $this->level->getBlockIdAt($x, $y, $z); if ($b === Block::DIRT or $b === Block::GRASS or $b === Block::PODZOL) { break; diff --git a/src/Ad5001/BetterGen/populator/BushPopulator.php b/src/Ad5001/BetterGen/populator/BushPopulator.php index 6c58765..c1363cb 100644 --- a/src/Ad5001/BetterGen/populator/BushPopulator.php +++ b/src/Ad5001/BetterGen/populator/BushPopulator.php @@ -62,7 +62,7 @@ class BushPopulator extends AmountPopulator { * @param $z int */ protected function getHighestWorkableBlock($x, $z) { - for($y = Level::Y_MAX; $y > 0; -- $y) { + for($y = Level::Y_MAX - 1; $y > 0; -- $y) { $b = $this->level->getBlockIdAt($x, $y, $z); if ($b === Block::DIRT or $b === Block::GRASS or $b === Block::PODZOL) { break; diff --git a/src/Ad5001/BetterGen/populator/CactusPopulator.php b/src/Ad5001/BetterGen/populator/CactusPopulator.php index bc0b114..9a2e28d 100644 --- a/src/Ad5001/BetterGen/populator/CactusPopulator.php +++ b/src/Ad5001/BetterGen/populator/CactusPopulator.php @@ -59,7 +59,7 @@ class CactusPopulator extends AmountPopulator { * @param $z int */ protected function getHighestWorkableBlock($x, $z) { - for($y = Level::Y_MAX; $y >= 0; -- $y) { + for($y = Level::Y_MAX - 1; $y >= 0; -- $y) { $b = $this->level->getBlockIdAt($x, $y, $z); if ($b !== Block::AIR and $b !== Block::LEAVES and $b !== Block::LEAVES2) { break; diff --git a/src/Ad5001/BetterGen/populator/CavePopulator.php b/src/Ad5001/BetterGen/populator/CavePopulator.php index c68e3a8..feb31a1 100644 --- a/src/Ad5001/BetterGen/populator/CavePopulator.php +++ b/src/Ad5001/BetterGen/populator/CavePopulator.php @@ -66,7 +66,7 @@ class CavePopulator extends AmountPopulator { * @param $z int */ protected function getHighestWorkableBlock($x, $z) { - for($y = Level::Y_MAX; $y > 0; -- $y) { + for($y = Level::Y_MAX - 1; $y > 0; -- $y) { $b = $this->level->getBlockIdAt($x, $y, $z); if ($b === Block::DIRT or $b === Block::GRASS or $b === Block::PODZOL or $b === Block::SAND or $b === Block::SNOW_BLOCK or $b === Block::SANDSTONE) { break; diff --git a/src/Ad5001/BetterGen/populator/DeadbushPopulator.php b/src/Ad5001/BetterGen/populator/DeadbushPopulator.php index 67a3536..0859a69 100644 --- a/src/Ad5001/BetterGen/populator/DeadbushPopulator.php +++ b/src/Ad5001/BetterGen/populator/DeadbushPopulator.php @@ -14,8 +14,10 @@ namespace Ad5001\BetterGen\populator; +use Ad5001\BetterGen\generator\BetterBiomeSelector; use pocketmine\block\Block; use pocketmine\level\ChunkManager; +use pocketmine\level\generator\biome\Biome; use pocketmine\level\Level; use pocketmine\utils\Random; @@ -36,26 +38,31 @@ class DeadbushPopulator extends AmountPopulator { for($i = 0; $i < $amount; $i++) { $x = $random->nextRange($chunkX * 16, $chunkX * 16 + 15); $z = $random->nextRange($chunkZ * 16, $chunkZ * 16 + 15); + if(!in_array($level->getChunk($chunkX, $chunkZ)->getBiomeId(abs($x % 16), ($z % 16)), [40, 39, Biome::DESERT])) continue; $y = $this->getHighestWorkableBlock($x, $z); - if ($y !== -1 && $level->getBlockIdAt($x, $y - 1, $z ) == Block::SAND) { - $level->setBlockIdAt($x, $y + 1, $z, Block::DEAD_BUSH); - $level->setBlockDataAt($x, $y + 1, $z, 1); + if ($y !== -1) { + $level->setBlockIdAt($x, $y, $z, Block::DEAD_BUSH); + $level->setBlockDataAt($x, $y, $z, 1); } } } - - /* + + /** * Gets the top block (y) on an x and z axes - * @param $x int - * @param $z int + * @param $x + * @param $z + * @return int */ - protected function getHighestWorkableBlock($x, $z) { - for($y = Level::Y_MAX; $y >= 0; -- $y) { + private function getHighestWorkableBlock($x, $z){ + for($y = Level::Y_MAX - 1; $y > 0; --$y){ $b = $this->level->getBlockIdAt($x, $y, $z); - if ($b !== Block::AIR and $b !== Block::LEAVES and $b !== Block::LEAVES2) { + if($b === Block::DIRT or $b === Block::GRASS or $b === Block::SAND or $b === Block::SANDSTONE or $b === Block::HARDENED_CLAY or $b === Block::STAINED_HARDENED_CLAY){ break; + }elseif($b !== Block::AIR){ + return -1; } } - return $y === 0 ? - 1 : ++$y; + + return ++$y; } } \ No newline at end of file diff --git a/src/Ad5001/BetterGen/populator/FallenTreePopulator.php b/src/Ad5001/BetterGen/populator/FallenTreePopulator.php index a8caa04..9570d19 100644 --- a/src/Ad5001/BetterGen/populator/FallenTreePopulator.php +++ b/src/Ad5001/BetterGen/populator/FallenTreePopulator.php @@ -65,13 +65,16 @@ class FallenTreePopulator extends AmountPopulator { * @param $z * @return int */ - protected function getHighestWorkableBlock($x, $z) { - for($y = Level::Y_MAX; $y >= 0; -- $y) { + private function getHighestWorkableBlock($x, $z){ + for($y = Level::Y_MAX - 1; $y > 0; --$y){ $b = $this->level->getBlockIdAt($x, $y, $z); - if ($b !== Block::AIR and $b !== Block::LEAVES and $b !== Block::LEAVES2) { + if($b === Block::DIRT or $b === Block::GRASS){ break; + }elseif($b !== Block::AIR and $b !== Block::SNOW_LAYER){ + return -1; } } - return $y === 0 ? - 1 : ++$y; + + return ++$y; } } \ No newline at end of file diff --git a/src/Ad5001/BetterGen/populator/FloatingIslandPopulator.php b/src/Ad5001/BetterGen/populator/FloatingIslandPopulator.php index 3a8f239..f3e06b0 100644 --- a/src/Ad5001/BetterGen/populator/FloatingIslandPopulator.php +++ b/src/Ad5001/BetterGen/populator/FloatingIslandPopulator.php @@ -69,7 +69,7 @@ class FloatingIslandPopulator extends AmountPopulator { * @param $z int */ protected function getHighestWorkableBlock($x, $z) { - for($y = Level::Y_MAX; $y > 0; -- $y) { + for($y = Level::Y_MAX - 1; $y > 0; -- $y) { $b = $this->level->getBlockIdAt($x, $y, $z); if ($b === Block::DIRT or $b === Block::GRASS or $b === Block::PODZOL or $b === Block::SAND) { break; diff --git a/src/Ad5001/BetterGen/populator/IglooPopulator.php b/src/Ad5001/BetterGen/populator/IglooPopulator.php index db76366..352763c 100644 --- a/src/Ad5001/BetterGen/populator/IglooPopulator.php +++ b/src/Ad5001/BetterGen/populator/IglooPopulator.php @@ -49,7 +49,7 @@ class IglooPopulator extends AmountPopulator { * @param $z int */ protected function getHighestWorkableBlock($x, $z) { - for($y = Level::Y_MAX; $y > 0; -- $y) { + for($y = Level::Y_MAX - 1; $y > 0; -- $y) { $b = $this->level->getBlockIdAt($x, $y, $z); if ($b === Block::DIRT or $b === Block::GRASS or $b === Block::PODZOL) { break; diff --git a/src/Ad5001/BetterGen/populator/LakePopulator.php b/src/Ad5001/BetterGen/populator/LakePopulator.php index 021aa1a..1462379 100644 --- a/src/Ad5001/BetterGen/populator/LakePopulator.php +++ b/src/Ad5001/BetterGen/populator/LakePopulator.php @@ -58,7 +58,7 @@ class LakePopulator extends AmountPopulator { * @param $z int */ protected function getHighestWorkableBlock($x, $z) { - for($y = Level::Y_MAX; $y > 0; -- $y) { + for($y = Level::Y_MAX - 1; $y > 0; -- $y) { $b = $this->level->getBlockIdAt($x, $y, $z); if ($b === Block::DIRT or $b === Block::GRASS or $b === Block::PODZOL) { break; diff --git a/src/Ad5001/BetterGen/populator/RavinePopulator.php b/src/Ad5001/BetterGen/populator/RavinePopulator.php index 05e49c2..d278bf0 100644 --- a/src/Ad5001/BetterGen/populator/RavinePopulator.php +++ b/src/Ad5001/BetterGen/populator/RavinePopulator.php @@ -75,7 +75,7 @@ class RavinePopulator extends AmountPopulator { * @param $z int */ protected function getHighestWorkableBlock($x, $z) { - for($y = Level::Y_MAX; $y > 0; -- $y) { + for($y = Level::Y_MAX - 1; $y > 0; -- $y) { $b = $this->level->getBlockIdAt($x, $y, $z); if ($b === Block::DIRT or $b === Block::GRASS or $b === Block::PODZOL or $b === Block::SAND or $b === Block::SNOW_BLOCK or $b === Block::SANDSTONE) { break; diff --git a/src/Ad5001/BetterGen/populator/SugarCanePopulator.php b/src/Ad5001/BetterGen/populator/SugarCanePopulator.php index 07c1ddf..b027d20 100644 --- a/src/Ad5001/BetterGen/populator/SugarCanePopulator.php +++ b/src/Ad5001/BetterGen/populator/SugarCanePopulator.php @@ -58,7 +58,7 @@ class SugarCanePopulator extends AmountPopulator { * @param $z int */ protected function getHighestWorkableBlock($x, $z) { - for($y = Level::Y_MAX; $y >= 0; -- $y) { + for($y = Level::Y_MAX - 1; $y >= 0; -- $y) { $b = $this->level->getBlockIdAt($x, $y, $z); if ($b !== Block::AIR and $b !== Block::LEAVES and $b !== Block::LEAVES2) { break; diff --git a/src/Ad5001/BetterGen/populator/TemplePopulator.php b/src/Ad5001/BetterGen/populator/TemplePopulator.php index a1016ce..36b0147 100644 --- a/src/Ad5001/BetterGen/populator/TemplePopulator.php +++ b/src/Ad5001/BetterGen/populator/TemplePopulator.php @@ -49,7 +49,7 @@ class TemplePopulator extends AmountPopulator { * @param $z int */ protected function getHighestWorkableBlock($x, $z) { - for($y = Level::Y_MAX; $y > 0; -- $y) { + for($y = Level::Y_MAX - 1; $y > 0; -- $y) { $b = $this->level->getBlockIdAt($x, $y, $z); if ($b === Block::SAND) { break; diff --git a/src/Ad5001/BetterGen/populator/TreePopulator.php b/src/Ad5001/BetterGen/populator/TreePopulator.php index 5954b93..b85470a 100644 --- a/src/Ad5001/BetterGen/populator/TreePopulator.php +++ b/src/Ad5001/BetterGen/populator/TreePopulator.php @@ -77,7 +77,7 @@ class TreePopulator extends AmountPopulator { * @param $z int */ protected function getHighestWorkableBlock($x, $z) { - for($y = Level::Y_MAX; $y > 0; -- $y) { + for($y = Level::Y_MAX - 1; $y > 0; -- $y) { $b = $this->level->getBlockIdAt($x, $y, $z); if ($b === Block::DIRT or $b === Block::GRASS or $b === Block::PODZOL) { break; diff --git a/src/Ad5001/BetterGen/populator/WellPopulator.php b/src/Ad5001/BetterGen/populator/WellPopulator.php index 5a867f3..33e2aa0 100644 --- a/src/Ad5001/BetterGen/populator/WellPopulator.php +++ b/src/Ad5001/BetterGen/populator/WellPopulator.php @@ -49,7 +49,7 @@ class WellPopulator extends AmountPopulator { * @param $z int */ protected function getHighestWorkableBlock($x, $z) { - for($y = Level::Y_MAX; $y > 0; -- $y) { + for($y = Level::Y_MAX - 1; $y > 0; -- $y) { $b = $this->level->getBlockIdAt($x, $y, $z); if ($b === Block::SAND) { break; diff --git a/src/Ad5001/BetterGen/structure/SakuraTree.php b/src/Ad5001/BetterGen/structure/SakuraTree.php index 9c89c5a..e855c3c 100644 --- a/src/Ad5001/BetterGen/structure/SakuraTree.php +++ b/src/Ad5001/BetterGen/structure/SakuraTree.php @@ -569,7 +569,7 @@ class SakuraTree extends Tree { $sideLen = $totalLength ** 2; // Side length //TODO CHECK WHAT THIS IS SUPPOSED TO BE - $numForward = $sideLen; + $numForward = ($totalLength % 2 == 0) ? $totalLength - 1 : $totalLength; //TODO END $lX1 = $lZ1 = $lX = $lZ = 0; @@ -589,7 +589,6 @@ class SakuraTree extends Tree { } // Second branch part. + second leave part - $numForward = ($totalLength % 2 == 0) ? $totalLength - 1 : $totalLength; for ($i = 1; $i < $stickLen + 1; $i++) { $lX = $lX1 + ($xd * $i); $lZ = $lZ1 + ($zd * $i); diff --git a/src/Ad5001/BetterGen/structure/Temple.php b/src/Ad5001/BetterGen/structure/Temple.php index d379db9..d719aef 100644 --- a/src/Ad5001/BetterGen/structure/Temple.php +++ b/src/Ad5001/BetterGen/structure/Temple.php @@ -14,13 +14,13 @@ namespace Ad5001\BetterGen\structure; -use Ad5001\BetterGen\loot\LootTable; -use Ad5001\BetterGen\utils\BuildingUtils; use pocketmine\block\Block; use pocketmine\level\ChunkManager; -use pocketmine\level\generator\object\Object; -use pocketmine\math\Vector3; use pocketmine\utils\Random; +use pocketmine\math\Vector3; +use pocketmine\level\generator\object\Object; +use Ad5001\BetterGen\loot\LootTable; +use Ad5001\BetterGen\utils\BuildingUtils; class Temple extends Object { const DIRECTION_PLUSX = 0; @@ -109,7 +109,6 @@ class Temple extends Object { 1 ] ]; - private $direction; /* * Checks if a temple is placeable @@ -172,7 +171,7 @@ class Temple extends Object { for($zz = $z - 1; $zz <= $z + 1; $zz ++) $this->placeBlock($xx, $yy, $zz, 0); - // Floor pattern + // Floor patern foreach($this->directions as $dir ) { // Building pillar for($yy = $y + 1; $yy <= $y + 3; $yy ++) @@ -183,6 +182,8 @@ class Temple extends Object { $this->placeBlock($x + ($dir [0] * 3), $y, $z, Block::STAINED_HARDENED_CLAY, 1); $this->placeBlock($x, $y, $z + ($dir [1] * 2), Block::STAINED_HARDENED_CLAY, 1); $this->placeBlock($x, $y, $z + ($dir [1] * 3), Block::STAINED_HARDENED_CLAY, 1); + $this->placeBlock($x + ($dir [0] * 2), $yy, $z + ($dir [1]), Block::STAINED_HARDENED_CLAY, 1); + $this->placeBlock($x + ($dir [0]), $yy, $z + ($dir [1] * 2), Block::STAINED_HARDENED_CLAY, 1); // Sandstone $this->placeBlock($x + $dir [0], $y, $z); @@ -417,7 +418,7 @@ class Temple extends Object { } /* - * Places one of the towers. Out is inverted $direction1, stairs come from inverted $direction2 to $direction2, patterns are on $direction1 and $direction2 + * Places one of the towers. Out is inversed $direction1, stairs come from inversed $direction2 to $direction2, patterns are on $direction1 and $direction2 * @param $x int * @param $y int * @param $z int @@ -894,7 +895,7 @@ class Temple extends Object { * @param $direction int * @return int */ - protected function getInvertedDirection(int $direction): int { + protected function getInversedDirection(int $direction): int { switch ($direction) { case self::DIRECTION_PLUSX : // x+ (0) return self::DIRECTION_MINX;