From b5fb3c21ae34b08af74f6a62a23f1ba3cd0e1c79 Mon Sep 17 00:00:00 2001 From: Ad5001 Date: Sun, 14 May 2017 22:18:21 +0200 Subject: [PATCH] Fixing a level error --- .../populator/MineshaftPopulator.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Ad5001/BetterGen/populator/MineshaftPopulator.php b/src/Ad5001/BetterGen/populator/MineshaftPopulator.php index 57492d5..e2109c8 100644 --- a/src/Ad5001/BetterGen/populator/MineshaftPopulator.php +++ b/src/Ad5001/BetterGen/populator/MineshaftPopulator.php @@ -23,6 +23,7 @@ use pocketmine\block\Block; use pocketmine\level\ChunkManager; use pocketmine\math\Vector3; use pocketmine\utils\Random; +use pocketmine\level\Level; class MineshaftPopulator extends AmountPopulator { /** var int */ @@ -86,7 +87,7 @@ class MineshaftPopulator extends AmountPopulator { * @param Random $random */ public function generateMineshaftPart(int $x, int $y, int $z, int $dir, Random $random) { - if ($this->maxPath -- < 1 || $y >= $this->level->getChunk(($x - ($x % 16)) / 16, ($z - ($z % 16)) / 16)->getHighestBlockAt($x % 16, $z % 16) - 10) + if ($this->maxPath -- < 1 || $y >= $this->getHighestBlockAt($x, $z) - 10) return; $type = $random->nextBoundedInt(3); $level = $this->level; @@ -425,5 +426,21 @@ class MineshaftPopulator extends AmountPopulator { break; } } + + /** + * Gets the top block (y) on an x and z axes + * @param int $x + * @param int $z + */ + protected function getHighestWorkableBlock($x, $z) { + for($y = Level::Y_MAX - 1; $y > 0; -- $y) { + $b = $this->level->getBlockIdAt($x, $y, $z); + if ($b === Block::SAND) { + break; + } + } + + return ++$y; + } } ?> \ No newline at end of file