, XenialDan * @link https://github.com/Ad5001/BetterGen * @category World Generator * @api 3.0.0 * @version 1.1 */ namespace Ad5001\BetterGen\populator; use Ad5001\BetterGen\utils\BuildingUtils; use Ad5001\BetterGen\structure\Dungeons; use pocketmine\block\Block; use pocketmine\level\ChunkManager; use pocketmine\level\Level; use pocketmine\math\Vector3; use pocketmine\utils\Random; class DungeonPopulator extends AmountPopulator { /** @var ChunkManager */ protected $level; /** * Populates the chunk * * @param ChunkManager $level * @param int $chunkX * @param int $chunkZ * @param Random $random * @return void */ public function populate(ChunkManager $level, $chunkX, $chunkZ, Random $random) { $this->level = $level; $amount = $this->getAmount($random); if($amount == 5) { // 1 out of 10 chunks $x = $random->nextRange($chunkX << 4, ($chunkX << 4) + 15); $z = $random->nextRange($chunkZ << 4, ($chunkZ << 4) + 15); $y = $random->nextRange(10, $this->getHighestWorkableBlock($x, $z)); $d = new Dungeons(); $d->placeObject($level, $x, $y, $z, $random); } } /** * 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::DIRT or $b === Block::GRASS or $b === Block::PODZOL or $b === Block::SAND or $b === Block::SNOW_BLOCK or $b === Block::SANDSTONE) { break; } elseif ($b !== 0 and $b !== Block::SNOW_LAYER and $b !== Block::WATER) { return - 1; } } return ++$y; } }