Dungeons!

This commit is contained in:
Ad5001 2017-11-13 19:49:01 +01:00
parent 2a9c440d10
commit 4b5cdeed6e
5 changed files with 112 additions and 65 deletions

View file

@ -29,6 +29,7 @@ use Ad5001\BetterGen\populator\CavePopulator;
use Ad5001\BetterGen\populator\FloatingIslandPopulator;
use Ad5001\BetterGen\populator\MineshaftPopulator;
use Ad5001\BetterGen\populator\RavinePopulator;
use Ad5001\BetterGen\populator\DungeonPopulator;
use pocketmine\block\Block;
use pocketmine\block\CoalOre;
use pocketmine\block\DiamondOre;
@ -210,6 +211,13 @@ class BetterNormal extends Generator {
$this->populators[] = $fisl;
}
if(!\Ad5001\BetterGen\utils\CommonUtils::in_arrayi("Dungeons", self::$options["delStruct"])) {
$dungeon = new DungeonPopulator();
$dungeon->setBaseAmount(0);
$dungeon->setRandomAmount(20);
$this->populators[] = $dungeon;
}
if(!\Ad5001\BetterGen\utils\CommonUtils::in_arrayi("Ores", self::$options["delStruct"])) {
$ores = Main::isOtherNS() ? new \pocketmine\level\generator\normal\populator\Ore() : new \pocketmine\level\generator\populator\Ore();
if(Main::isOtherNS()) $ores->setOreTypes([

View file

@ -44,7 +44,7 @@ class DungeonPopulator extends AmountPopulator {
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));
$y = $random->nextRange(10, $this->getHighestWorkableBlock($x, $z) - 6);
$d = new Dungeons();
$d->placeObject($level, $x, $y, $z, $random);
}

View file

@ -45,25 +45,57 @@ class Dungeons extends PopulatorObject {
* @return void
*/
public function placeObject(ChunkManager $level, $x, $y, $z, Random $random) {
$xDepth = 2 + $random->nextBoundedInt(4);
$zDepth = 2 + $random->nextBoundedInt(4);
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) {
$xDepth = 3 + $random->nextBoundedInt(3);
$zDepth = 3 + $random->nextBoundedInt(3);
// echo "Building dungeon at $x, $y, $z\n";
// Building walls
list($pos1, $pos2) = BuildingUtils::minmax(new Vector3($x + $xDepth, $y, $z + $zDepth), new Vector3($x - $xDepth, $y + 5, $z - $zDepth));
for($y = $pos1->y; $y >= $pos2->y; $y--) {
for($x = $pos1->x; $x >= $pos2->x; $x--) {
for($z = $pos1->z; $z >= $pos2->z; $z--) { // Cleaning the area first
$level->setBlockIdAt($x, $y, $z, Block::AIR);
}
// Starting random walls.
if($random->nextBoolean()) {
$level->setBlockIdAt($v3->x, $v3->y, $v3->z, Block::MOSS_STONE);
$level->setBlockIdAt($x, $y, $pos1->z, Block::MOSS_STONE);
} else {
$level->setBlockIdAt($v3->x, $v3->y, $v3->z, Block::COBBLESTONE);
$level->setBlockIdAt($x, $y, $pos1->z, Block::COBBLESTONE);
}
if($random->nextBoolean()) {
$level->setBlockIdAt($x, $y, $pos2->z, Block::MOSS_STONE);
} else {
$level->setBlockIdAt($v3->x, $v3->y, $v3->z, Block::AIR);
$level->setBlockIdAt($x, $y, $pos2->z, Block::COBBLESTONE);
}
}, $level, new Vector3($x, $y, $z), $xDepth, $zDepth, $random);
}
for($z = $pos1->z; $z >= $pos2->z; $z--) {
if($random->nextBoolean()) {
$level->setBlockIdAt($pos1->x, $y, $z, Block::MOSS_STONE);
} else {
$level->setBlockIdAt($pos1->x, $y, $z, Block::COBBLESTONE);
}
if($random->nextBoolean()) {
$level->setBlockIdAt($pos2->x, $y, $z, Block::MOSS_STONE);
} else {
$level->setBlockIdAt($pos2->x, $y, $z, Block::COBBLESTONE);
}
}
}
// Bottom & top
for($x = $pos1->x; $x >= $pos2->x; $x--) {
for($z = $pos1->z; $z >= $pos2->z; $z--) {
if($random->nextBoolean()) {
$level->setBlockIdAt($x, $pos1->y, $z, Block::MOSS_STONE);
} else {
$level->setBlockIdAt($x, $pos1->y, $z, Block::COBBLESTONE);
}
if($random->nextBoolean()) {
$level->setBlockIdAt($x, $pos2->y, $z, Block::MOSS_STONE);
} else {
$level->setBlockIdAt($x, $pos2->y, $z, Block::COBBLESTONE);
}
}
}
// Setting the spawner
$level->setBlockIdAt($x, $y + 1, $z, Block::MOB_SPAWNER);
}
}

View file

@ -473,6 +473,7 @@ class SakuraTree extends Tree {
* @return void
*/
public function placeObject(ChunkManager $level, $x, $y, $z, Random $random) {
$this->random = $random;
$percentage = $random->nextBoundedInt(100);
if ($percentage > 10) {
return;
@ -671,6 +672,12 @@ class SakuraTree extends Tree {
public function setLog(ChunkManager $level, $x, $y, $z) {
$level->setBlockIdAt($x, $y, $z, $this->trunkBlock);
$level->setBlockDataAt($x, $y, $z, $this->type);
if($this->random->nextBoundedInt(3) == 0){ // Setting a log near.
$x += $this->random->nextBoundedInt(3) - 1;
$z += $this->random->nextBoundedInt(3) - 1;
$level->setBlockIdAt($x, $y, $z, $this->trunkBlock);
$level->setBlockDataAt($x, $y, $z, $this->type);
}
}
/**

View file

@ -210,7 +210,7 @@ class BuildingUtils {
* @param Vector3 $pos2
* @return array
*/
protected static function minmax(Vector3 $pos1, Vector3 $pos2): array {
public static function minmax(Vector3 $pos1, Vector3 $pos2): array {
$v1 = new Vector3(max($pos1->x, $pos2->x), max($pos1->y, $pos2->y), max($pos1->z, $pos2->z));
$v2 = new Vector3(min($pos1->x, $pos2->x), min($pos1->y, $pos2->y), min($pos1->z, $pos2->z));
return [