2017-04-23 14:42:51 +00:00
|
|
|
<?php
|
2017-05-10 15:03:04 +00:00
|
|
|
/**
|
|
|
|
* ____ __ __ ____
|
|
|
|
* /\ _`\ /\ \__ /\ \__ /\ _`\
|
|
|
|
* \ \ \L\ \ __ \ \ ,_\\ \ ,_\ __ _ __ \ \ \L\_\ __ ___
|
|
|
|
* \ \ _ <' /'__`\\ \ \/ \ \ \/ /'__`\/\`'__\\ \ \L_L /'__`\ /' _ `\
|
|
|
|
* \ \ \L\ \/\ __/ \ \ \_ \ \ \_ /\ __/\ \ \/ \ \ \/, \/\ __/ /\ \/\ \
|
|
|
|
* \ \____/\ \____\ \ \__\ \ \__\\ \____\\ \_\ \ \____/\ \____\\ \_\ \_\
|
|
|
|
* \/___/ \/____/ \/__/ \/__/ \/____/ \/_/ \/___/ \/____/ \/_/\/_/
|
2017-05-11 11:29:22 +00:00
|
|
|
* Tomorrow's pocketmine generator.
|
2017-05-14 18:13:15 +00:00
|
|
|
* @author Ad5001 <mail@ad5001.eu>, XenialDan <https://github.com/thebigsmileXD>
|
2017-05-10 15:03:04 +00:00
|
|
|
* @link https://github.com/Ad5001/BetterGen
|
2017-05-14 18:13:15 +00:00
|
|
|
* @category World Generator
|
|
|
|
* @api 3.0.0
|
|
|
|
* @version 1.1
|
2017-04-23 14:42:51 +00:00
|
|
|
*/
|
2017-05-10 15:03:04 +00:00
|
|
|
|
2017-04-23 14:42:51 +00:00
|
|
|
namespace Ad5001\BetterGen\populator;
|
|
|
|
|
2017-05-11 12:07:26 +00:00
|
|
|
use Ad5001\BetterGen\utils\BuildingUtils;
|
2017-04-23 14:42:51 +00:00
|
|
|
use pocketmine\block\Block;
|
|
|
|
use pocketmine\level\ChunkManager;
|
2017-05-11 12:07:26 +00:00
|
|
|
use pocketmine\level\Level;
|
2017-04-23 14:42:51 +00:00
|
|
|
use pocketmine\math\Vector3;
|
2017-05-11 12:07:26 +00:00
|
|
|
use pocketmine\utils\Random;
|
2017-04-23 14:42:51 +00:00
|
|
|
|
|
|
|
class LakePopulator extends AmountPopulator {
|
2017-05-11 09:49:57 +00:00
|
|
|
/** @var ChunkManager */
|
2017-04-23 14:42:51 +00:00
|
|
|
protected $level;
|
|
|
|
|
2017-05-14 19:03:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Populates the chunk
|
|
|
|
*
|
|
|
|
* @param ChunkManager $level
|
|
|
|
* @param int $chunkX
|
|
|
|
* @param int $chunkZ
|
|
|
|
* @param Random $random
|
|
|
|
* @return void
|
2017-04-23 14:42:51 +00:00
|
|
|
*/
|
|
|
|
public function populate(ChunkManager $level, $chunkX, $chunkZ, Random $random) {
|
|
|
|
$this->level = $level;
|
2017-04-29 09:59:44 +00:00
|
|
|
$x = $random->nextRange($chunkX << 4, ($chunkX << 4) + 15);
|
|
|
|
$z = $random->nextRange($chunkZ << 4, ($chunkZ << 4) + 15);
|
|
|
|
$ory = $random->nextRange(20, 63); // Water level
|
2017-04-23 14:42:51 +00:00
|
|
|
$y = $ory;
|
|
|
|
for($i = 0; $i < 4; $i ++) {
|
2017-04-29 09:59:44 +00:00
|
|
|
$x += $random->nextRange(- 1, 1);
|
|
|
|
$y += $random->nextRange(- 1, 1);
|
|
|
|
$z += $random->nextRange(- 1, 1);
|
2017-05-13 21:27:10 +00:00
|
|
|
if ($level->getBlockIdAt($x, $y, $z) !== Block::AIR)
|
|
|
|
BuildingUtils::buildRandom($this->level, new Vector3($x, $y, $z), new Vector3(5, 5, 5), $random, Block::get(Block::WATER));
|
2017-04-23 14:42:51 +00:00
|
|
|
}
|
|
|
|
for($xx = $x - 8; $xx <= $x + 8; $xx ++)
|
|
|
|
for($zz = $z - 8; $zz <= $z + 8; $zz ++)
|
|
|
|
for($yy = $ory + 1; $yy <= $y + 3; $yy ++)
|
2017-05-13 21:27:10 +00:00
|
|
|
if ($level->getBlockIdAt($xx, $yy, $zz) == Block::WATER)
|
2017-04-29 09:59:44 +00:00
|
|
|
$level->setBlockIdAt($xx, $yy, $zz, Block::AIR);
|
2017-04-23 14:42:51 +00:00
|
|
|
}
|
|
|
|
|
2017-05-14 19:03:47 +00:00
|
|
|
/**
|
2017-04-23 14:42:51 +00:00
|
|
|
* Gets the top block (y) on an x and z axes
|
2017-05-14 19:03:47 +00:00
|
|
|
* @param int $x
|
|
|
|
* @param int $z
|
2017-04-23 14:42:51 +00:00
|
|
|
*/
|
|
|
|
protected function getHighestWorkableBlock($x, $z) {
|
2017-05-11 14:41:42 +00:00
|
|
|
for($y = Level::Y_MAX - 1; $y > 0; -- $y) {
|
2017-04-29 09:59:44 +00:00
|
|
|
$b = $this->level->getBlockIdAt($x, $y, $z);
|
2017-04-23 14:42:51 +00:00
|
|
|
if ($b === Block::DIRT or $b === Block::GRASS or $b === Block::PODZOL) {
|
|
|
|
break;
|
|
|
|
} elseif ($b !== 0 and $b !== Block::SNOW_LAYER) {
|
|
|
|
return - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-11 13:12:17 +00:00
|
|
|
return ++$y;
|
2017-04-23 14:42:51 +00:00
|
|
|
}
|
|
|
|
}
|