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-10 15:03:04 +00:00
|
|
|
* @author Ad5001
|
|
|
|
* @link https://github.com/Ad5001/BetterGen
|
2017-04-23 14:42:51 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Ad5001\BetterGen\populator;
|
|
|
|
|
2017-05-11 09:49:57 +00:00
|
|
|
use pocketmine\level\generator\object\Tree;
|
|
|
|
use pocketmine\level\Level;
|
2017-04-23 14:42:51 +00:00
|
|
|
use pocketmine\utils\Random;
|
|
|
|
use pocketmine\block\Block;
|
|
|
|
use pocketmine\level\ChunkManager;
|
|
|
|
use Ad5001\BetterGen\structure\SakuraTree;
|
|
|
|
use Ad5001\BetterGen\populator\AmountPopulator;
|
2017-05-01 10:03:56 +00:00
|
|
|
use Ad5001\BetterGen\Main;
|
|
|
|
|
2017-04-23 14:42:51 +00:00
|
|
|
|
|
|
|
class TreePopulator extends AmountPopulator {
|
2017-05-11 09:49:57 +00:00
|
|
|
/** @var Tree[] */
|
2017-04-23 14:42:51 +00:00
|
|
|
static $types = [
|
|
|
|
"pocketmine\\level\\generator\\object\\OakTree",
|
|
|
|
"pocketmine\\level\\generator\\object\\BirchTree",
|
|
|
|
"Ad5001\\BetterGen\\structure\\SakuraTree"
|
|
|
|
];
|
2017-05-11 09:49:57 +00:00
|
|
|
/** @var ChunkManager */
|
2017-04-23 14:42:51 +00:00
|
|
|
protected $level;
|
|
|
|
protected $type;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Constructs the class
|
|
|
|
*/
|
|
|
|
public function __construct($type = 0) {
|
|
|
|
$this->type = $type;
|
2017-05-01 10:03:56 +00:00
|
|
|
if(Main::isOtherNS()) {
|
|
|
|
self::$types = [
|
|
|
|
"pocketmine\\level\\generator\\normal\\object\\OakTree",
|
|
|
|
"pocketmine\\level\\generator\\normal\\object\\BirchTree",
|
|
|
|
"Ad5001\\BetterGen\\structure\\SakuraTree"
|
|
|
|
];
|
|
|
|
}
|
2017-04-23 14:42:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Populate the chunk
|
|
|
|
* @param $level pocketmine\level\ChunkManager
|
|
|
|
* @param $chunkX int
|
|
|
|
* @param $chunkZ int
|
|
|
|
* @param $random pocketmine\utils\Random
|
|
|
|
*/
|
|
|
|
public function populate(ChunkManager $level, $chunkX, $chunkZ, Random $random) {
|
|
|
|
$this->level = $level;
|
2017-04-29 09:59:44 +00:00
|
|
|
$amount = $this->getAmount($random);
|
|
|
|
for($i = 0; $i < $amount; $i++) {
|
|
|
|
$x = $random->nextRange($chunkX << 4, ($chunkX << 4) + 15);
|
|
|
|
$z = $random->nextRange($chunkZ << 4, ($chunkZ << 4) + 15);
|
|
|
|
$y = $this->getHighestWorkableBlock($x, $z);
|
|
|
|
if ($y === -1) {
|
2017-04-23 14:42:51 +00:00
|
|
|
continue;
|
|
|
|
}
|
2017-05-10 15:03:04 +00:00
|
|
|
$treeC = self::$types [$this->type];
|
2017-05-11 09:49:57 +00:00
|
|
|
/** @var Tree $tree */
|
|
|
|
$tree = new $treeC();
|
2017-05-10 15:03:04 +00:00
|
|
|
$tree->placeObject($level, $x, $y, $z, $random);
|
2017-04-23 14:42:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Gets the top block (y) on an x and z axes
|
|
|
|
* @param $x int
|
|
|
|
* @param $z int
|
|
|
|
*/
|
|
|
|
protected function getHighestWorkableBlock($x, $z) {
|
2017-05-11 09:49:57 +00:00
|
|
|
for($y = Level::Y_MAX; $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-04-29 09:59:44 +00:00
|
|
|
return $y++;
|
2017-04-23 14:42:51 +00:00
|
|
|
}
|
|
|
|
}
|