forked from Ad5001/BetterGen
Continuing on dungeons
This commit is contained in:
parent
bdb77f6e81
commit
a671c0c29c
6 changed files with 180 additions and 111 deletions
70
src/Ad5001/BetterGen/populator/DungeonPopulator.php
Normal file
70
src/Ad5001/BetterGen/populator/DungeonPopulator.php
Normal file
|
@ -0,0 +1,70 @@
|
|||
<?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\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;
|
||||
}
|
||||
}
|
|
@ -47,14 +47,21 @@ class Dungeons extends PopulatorObject {
|
|||
public function placeObject(ChunkManager $level, $x, $y, $z, Random $random) {
|
||||
$xDepth = 2 + $random->nextBoundedInt(4);
|
||||
$zDepth = 2 + $random->nextBoundedInt(4);
|
||||
BuildingUtils::fillCallback(new Vector3($x + $xDepth, $y, $x + $zDepth), new Vector3($x - $xDepth, $y, $z - $zDepth), function($v3, $level, $v3n2, $xDepth, $zDepth, $random) {
|
||||
if($v3->x == $v3n2->x + $xDepth || $v3->x == $v3n2->x - $xDepth || $v3->y == $v3n2->y || $v3->y == $v3n2->y + 5 || $v3->z == $v3n2->z + $zDepth || $v3->z == $v3n2->z - $zDepth) {
|
||||
echo "Building dungeon at $x, $y, $z\n";
|
||||
BuildingUtils::fillCallback(new Vector3($x + $xDepth, $y, $x + $zDepth), new Vector3($x - $xDepth, $y + 5, $z - $zDepth), function($v3, $level, $v3n2, $xDepth, $zDepth, $random) {
|
||||
if($v3->x == $v3n2->x + $xDepth ||
|
||||
$v3->x == $v3n2->x - $xDepth ||
|
||||
$v3->y == $v3n2->y ||
|
||||
$v3->y == $v3n2->y + 5 ||
|
||||
$v3->z == $v3n2->z + $zDepth ||
|
||||
$v3->z == $v3n2->z - $zDepth) {
|
||||
if($random->nextBoolean()) {
|
||||
$level->setBlockIdAt($v3->x, $v3->y, $v3->z, Block::MOSSY_STONE);
|
||||
$level->setBlockIdAt($v3->x, $v3->y, $v3->z, Block::MOSS_STONE);
|
||||
} else {
|
||||
$level->setBlockIdAt($v3->x, $v3->y, $v3->z, Block::COBBLESTONE);
|
||||
|
||||
}
|
||||
} else {
|
||||
$level->setBlockIdAt($v3->x, $v3->y, $v3->z, Block::AIR);
|
||||
}
|
||||
}, $level, new Vector3($x, $y, $z), $xDepth, $zDepth, $random);
|
||||
$level->setBlockIdAt($x, $y + 1, $z, Block::MOB_SPAWNER);
|
||||
|
|
|
@ -84,8 +84,8 @@ class BuildingUtils {
|
|||
list($pos1, $pos2) = self::minmax($pos1, $pos2);
|
||||
$return = [];
|
||||
for($x = $pos1->x; $x >= $pos2->x; $x --) for($y = $pos1->y; $y >= $pos2->y; $y --) for($z = $pos1->z; $z >= $pos2->z; $z --) {
|
||||
$return[] = call_user_func($call, new Vector3($x, $y, $z), ...$params);
|
||||
}
|
||||
$return[] = call_user_func($call, new Vector3($x, $y, $z), ...$params);
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue