66 lines
2 KiB
PHP
66 lines
2 KiB
PHP
<?php
|
|
/**
|
|
* ____ __ __ ____
|
|
* /\ _`\ /\ \__ /\ \__ /\ _`\
|
|
* \ \ \L\ \ __ \ \ ,_\\ \ ,_\ __ _ __ \ \ \L\_\ __ ___
|
|
* \ \ _ <' /'__`\\ \ \/ \ \ \/ /'__`\/\`'__\\ \ \L_L /'__`\ /' _ `\
|
|
* \ \ \L\ \/\ __/ \ \ \_ \ \ \_ /\ __/\ \ \/ \ \ \/, \/\ __/ /\ \/\ \
|
|
* \ \____/\ \____\ \ \__\ \ \__\\ \____\\ \_\ \ \____/\ \____\\ \_\ \_\
|
|
* \/___/ \/____/ \/__/ \/__/ \/____/ \/_/ \/___/ \/____/ \/_/\/_/
|
|
* Tomorrow's pocketmine generator.
|
|
* @author Ad5001 <mail@ad5001.eu>, XenialDan <https://github.com/thebigsmileXD>
|
|
* @link https://github.com/Ad5001/BetterGen
|
|
* @category World Generator
|
|
* @api 3.0.0
|
|
* @version 1.1
|
|
*/
|
|
|
|
namespace Ad5001\BetterGen\populator;
|
|
|
|
use Ad5001\BetterGen\structure\Temple;
|
|
use pocketmine\block\Block;
|
|
use pocketmine\level\ChunkManager;
|
|
use pocketmine\level\Level;
|
|
use pocketmine\utils\Random;
|
|
|
|
class TemplePopulator extends AmountPopulator {
|
|
/** @var Level */
|
|
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;
|
|
if ($random->nextBoundedInt(1000) > 70)
|
|
return;
|
|
$temple = new Temple ();
|
|
$x = $random->nextRange($chunkX << 4, ($chunkX << 4) + 15);
|
|
$z = $random->nextRange($chunkZ << 4, ($chunkZ << 4) + 15);
|
|
$y = $this->getHighestWorkableBlock($x, $z);
|
|
if ($temple->canPlaceObject($level, $x, $y, $z, $random))
|
|
$temple->placeObject($level, $x, $y - 1, $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::SAND) {
|
|
break;
|
|
}
|
|
}
|
|
|
|
return ++$y;
|
|
}
|
|
} |