Dungeons!

This commit is contained in:
Adsooi 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\FloatingIslandPopulator;
use Ad5001\BetterGen\populator\MineshaftPopulator; use Ad5001\BetterGen\populator\MineshaftPopulator;
use Ad5001\BetterGen\populator\RavinePopulator; use Ad5001\BetterGen\populator\RavinePopulator;
use Ad5001\BetterGen\populator\DungeonPopulator;
use pocketmine\block\Block; use pocketmine\block\Block;
use pocketmine\block\CoalOre; use pocketmine\block\CoalOre;
use pocketmine\block\DiamondOre; use pocketmine\block\DiamondOre;
@ -202,13 +203,20 @@ class BetterNormal extends Generator {
$mineshaft->setRandomAmount(102); $mineshaft->setRandomAmount(102);
$this->populators[] = $mineshaft; $this->populators[] = $mineshaft;
} }
if(!\Ad5001\BetterGen\utils\CommonUtils::in_arrayi("FloatingIslands", self::$options["delStruct"])) { if(!\Ad5001\BetterGen\utils\CommonUtils::in_arrayi("FloatingIslands", self::$options["delStruct"])) {
$fisl = new FloatingIslandPopulator(); $fisl = new FloatingIslandPopulator();
$fisl->setBaseAmount(0); $fisl->setBaseAmount(0);
$fisl->setRandomAmount(132); $fisl->setRandomAmount(132);
$this->populators[] = $fisl; $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"])) { 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(); $ores = Main::isOtherNS() ? new \pocketmine\level\generator\normal\populator\Ore() : new \pocketmine\level\generator\populator\Ore();

View file

@ -44,7 +44,7 @@ class DungeonPopulator extends AmountPopulator {
if($amount == 5) { // 1 out of 10 chunks if($amount == 5) { // 1 out of 10 chunks
$x = $random->nextRange($chunkX << 4, ($chunkX << 4) + 15); $x = $random->nextRange($chunkX << 4, ($chunkX << 4) + 15);
$z = $random->nextRange($chunkZ << 4, ($chunkZ << 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 = new Dungeons();
$d->placeObject($level, $x, $y, $z, $random); $d->placeObject($level, $x, $y, $z, $random);
} }

View file

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

View file

@ -473,6 +473,7 @@ class SakuraTree extends Tree {
* @return void * @return void
*/ */
public function placeObject(ChunkManager $level, $x, $y, $z, Random $random) { public function placeObject(ChunkManager $level, $x, $y, $z, Random $random) {
$this->random = $random;
$percentage = $random->nextBoundedInt(100); $percentage = $random->nextBoundedInt(100);
if ($percentage > 10) { if ($percentage > 10) {
return; return;
@ -671,6 +672,12 @@ class SakuraTree extends Tree {
public function setLog(ChunkManager $level, $x, $y, $z) { public function setLog(ChunkManager $level, $x, $y, $z) {
$level->setBlockIdAt($x, $y, $z, $this->trunkBlock); $level->setBlockIdAt($x, $y, $z, $this->trunkBlock);
$level->setBlockDataAt($x, $y, $z, $this->type); $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

@ -42,11 +42,11 @@ class BuildingUtils {
* @return void * @return void
*/ */
public static function fill(ChunkManager $level, Vector3 $pos1, Vector3 $pos2, Block $block = null) { public static function fill(ChunkManager $level, Vector3 $pos1, Vector3 $pos2, Block $block = null) {
if ($block == null) $block = Block::get(Block::AIR); if($block == null) $block = Block::get(Block::AIR);
list($pos1, $pos2) = self::minmax($pos1, $pos2); list($pos1, $pos2) = self::minmax($pos1, $pos2);
for($x = $pos1->x; $x >= $pos2->x; $x --) for($y = $pos1->y; $y >= $pos2->y; $y --) for($z = $pos1->z; $z >= $pos2->z; $z --) { for($x = $pos1->x; $x >= $pos2->x; $x--) for($y = $pos1->y; $y >= $pos2->y; $y--) for($z = $pos1->z; $z >= $pos2->z; $z--) {
$level->setBlockIdAt($x, $y, $z, $block->getId ()); $level->setBlockIdAt($x, $y, $z, $block->getId());
$level->setBlockDataAt($x, $y, $z, $block->getDamage ()); $level->setBlockDataAt($x, $y, $z, $block->getDamage());
} }
} }
@ -63,11 +63,11 @@ class BuildingUtils {
* @return void * @return void
*/ */
public static function fillRandom(ChunkManager $level, Vector3 $pos1, Vector3 $pos2, Block $block = null, Random $random = null, $randMax = 3) { public static function fillRandom(ChunkManager $level, Vector3 $pos1, Vector3 $pos2, Block $block = null, Random $random = null, $randMax = 3) {
if ($block == null) $block = Block::get(Block::AIR); if($block == null) $block = Block::get(Block::AIR);
list($pos1, $pos2) = self::minmax($pos1, $pos2); list($pos1, $pos2) = self::minmax($pos1, $pos2);
for($x = $pos1->x; $x >= $pos2->x; $x --) for($y = $pos1->y; $y >= $pos2->y; $y --) for($z = $pos1->z; $z >= $pos2->z; $z --) if($random !== null ? $random->nextBoundedInt($randMax) == 0 : rand(0, $randMax) == 0) { for($x = $pos1->x; $x >= $pos2->x; $x--) for($y = $pos1->y; $y >= $pos2->y; $y--) for($z = $pos1->z; $z >= $pos2->z; $z--) if($random !== null ? $random->nextBoundedInt($randMax) == 0 : rand(0, $randMax) == 0) {
$level->setBlockIdAt($x, $y, $z, $block->getId ()); $level->setBlockIdAt($x, $y, $z, $block->getId());
$level->setBlockDataAt($x, $y, $z, $block->getDamage ()); $level->setBlockDataAt($x, $y, $z, $block->getDamage());
} }
} }
@ -83,7 +83,7 @@ class BuildingUtils {
public static function fillCallback(Vector3 $pos1, Vector3 $pos2, callable $call, ...$params) : array { public static function fillCallback(Vector3 $pos1, Vector3 $pos2, callable $call, ...$params) : array {
list($pos1, $pos2) = self::minmax($pos1, $pos2); list($pos1, $pos2) = self::minmax($pos1, $pos2);
$return = []; $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 --) { 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; return $return;
@ -100,18 +100,18 @@ class BuildingUtils {
*/ */
public static function walls(ChunkManager $level, Vector3 $pos1, Vector3 $pos2, Block $block) { public static function walls(ChunkManager $level, Vector3 $pos1, Vector3 $pos2, Block $block) {
list($pos1, $pos2) = self::minmax($pos1, $pos2); list($pos1, $pos2) = self::minmax($pos1, $pos2);
for($y = $pos1->y; $y >= $pos2->y; $y --) { for($y = $pos1->y; $y >= $pos2->y; $y--) {
for($x = $pos1->x; $x >= $pos2->x; $x --) { for($x = $pos1->x; $x >= $pos2->x; $x--) {
$level->setBlockIdAt($x, $y, $pos1->z, $block->getId ()); $level->setBlockIdAt($x, $y, $pos1->z, $block->getId());
$level->setBlockDataAt($x, $y, $pos1->z, $block->getDamage ()); $level->setBlockDataAt($x, $y, $pos1->z, $block->getDamage());
$level->setBlockIdAt($x, $y, $pos2->z, $block->getId ()); $level->setBlockIdAt($x, $y, $pos2->z, $block->getId());
$level->setBlockDataAt($x, $y, $pos2->z, $block->getDamage ()); $level->setBlockDataAt($x, $y, $pos2->z, $block->getDamage());
} }
for($z = $pos1->z; $z >= $pos2->z; $z --) { for($z = $pos1->z; $z >= $pos2->z; $z--) {
$level->setBlockIdAt($pos1->x, $y, $z, $block->getId ()); $level->setBlockIdAt($pos1->x, $y, $z, $block->getId());
$level->setBlockDataAt($pos1->x, $y, $z, $block->getDamage ()); $level->setBlockDataAt($pos1->x, $y, $z, $block->getDamage());
$level->setBlockIdAt($pos2->x, $y, $z, $block->getId ()); $level->setBlockIdAt($pos2->x, $y, $z, $block->getId());
$level->setBlockDataAt($pos2->x, $y, $z, $block->getDamage ()); $level->setBlockDataAt($pos2->x, $y, $z, $block->getDamage());
} }
} }
} }
@ -127,10 +127,10 @@ class BuildingUtils {
*/ */
public static function top(ChunkManager $level, Vector3 $pos1, Vector3 $pos2, Block $block) { public static function top(ChunkManager $level, Vector3 $pos1, Vector3 $pos2, Block $block) {
list($pos1, $pos2) = self::minmax($pos1, $pos2); list($pos1, $pos2) = self::minmax($pos1, $pos2);
for($x = $pos1->x; $x >= $pos2->x; $x --) for($x = $pos1->x; $x >= $pos2->x; $x--)
for($z = $pos1->z; $z >= $pos2->z; $z --) { for($z = $pos1->z; $z >= $pos2->z; $z--) {
$level->setBlockIdAt($x, $pos1->y, $z, $block->getId ()); $level->setBlockIdAt($x, $pos1->y, $z, $block->getId());
$level->setBlockDataAt($x, $pos1->y, $z, $block->getDamage ()); $level->setBlockDataAt($x, $pos1->y, $z, $block->getDamage());
} }
} }
@ -145,15 +145,15 @@ class BuildingUtils {
*/ */
public static function corners(ChunkManager $level, Vector3 $pos1, Vector3 $pos2, Block $block) { public static function corners(ChunkManager $level, Vector3 $pos1, Vector3 $pos2, Block $block) {
list($pos1, $pos2) = self::minmax($pos1, $pos2); list($pos1, $pos2) = self::minmax($pos1, $pos2);
for($y = $pos1->y; $y >= $pos2->y; $y --) { for($y = $pos1->y; $y >= $pos2->y; $y--) {
$level->setBlockIdAt($pos1->x, $y, $pos1->z, $block->getId ()); $level->setBlockIdAt($pos1->x, $y, $pos1->z, $block->getId());
$level->setBlockDataAt($pos1->x, $y, $pos1->z, $block->getDamage ()); $level->setBlockDataAt($pos1->x, $y, $pos1->z, $block->getDamage());
$level->setBlockIdAt($pos2->x, $y, $pos1->z, $block->getId ()); $level->setBlockIdAt($pos2->x, $y, $pos1->z, $block->getId());
$level->setBlockDataAt($pos2->x, $y, $pos1->z, $block->getDamage ()); $level->setBlockDataAt($pos2->x, $y, $pos1->z, $block->getDamage());
$level->setBlockIdAt($pos1->x, $y, $pos2->z, $block->getId ()); $level->setBlockIdAt($pos1->x, $y, $pos2->z, $block->getId());
$level->setBlockDataAt($pos1->x, $y, $pos2->z, $block->getDamage ()); $level->setBlockDataAt($pos1->x, $y, $pos2->z, $block->getDamage());
$level->setBlockIdAt($pos2->x, $y, $pos2->z, $block->getId ()); $level->setBlockIdAt($pos2->x, $y, $pos2->z, $block->getId());
$level->setBlockDataAt($pos2->x, $y, $pos2->z, $block->getDamage ()); $level->setBlockDataAt($pos2->x, $y, $pos2->z, $block->getDamage());
} }
} }
@ -168,10 +168,10 @@ class BuildingUtils {
*/ */
public static function bottom(ChunkManager $level, Vector3 $pos1, Vector3 $pos2, Block $block) { public static function bottom(ChunkManager $level, Vector3 $pos1, Vector3 $pos2, Block $block) {
list($pos1, $pos2) = self::minmax($pos1, $pos2); list($pos1, $pos2) = self::minmax($pos1, $pos2);
for($x = $pos1->x; $x >= $pos2->x; $x --) for($x = $pos1->x; $x >= $pos2->x; $x--)
for($z = $pos1->z; $z >= $pos2->z; $z --) { for($z = $pos1->z; $z >= $pos2->z; $z--) {
$level->setBlockIdAt($x, $pos2->y, $z, $block->getId ()); $level->setBlockIdAt($x, $pos2->y, $z, $block->getId());
$level->setBlockDataAt($x, $pos2->y, $z, $block->getDamage ()); $level->setBlockDataAt($x, $pos2->y, $z, $block->getDamage());
} }
} }
@ -189,14 +189,14 @@ class BuildingUtils {
$xBounded = $random->nextBoundedInt(3) - 1; $xBounded = $random->nextBoundedInt(3) - 1;
$yBounded = $random->nextBoundedInt(3) - 1; $yBounded = $random->nextBoundedInt(3) - 1;
$zBounded = $random->nextBoundedInt(3) - 1; $zBounded = $random->nextBoundedInt(3) - 1;
$pos = $pos->round (); $pos = $pos->round();
for($x = $pos->x - ($infos->x / 2); $x <= $pos->x + ($infos->x / 2); $x ++) { for($x = $pos->x -($infos->x / 2); $x <= $pos->x +($infos->x / 2); $x++) {
for($y = $pos->y - ($infos->y / 2); $y <= $pos->y + ($infos->y / 2); $y ++) { for($y = $pos->y -($infos->y / 2); $y <= $pos->y +($infos->y / 2); $y++) {
for($z = $pos->z - ($infos->z / 2); $z <= $pos->z + ($infos->z / 2); $z ++) { for($z = $pos->z -($infos->z / 2); $z <= $pos->z +($infos->z / 2); $z++) {
// if(abs((abs($x) - abs($pos->x)) ** 2 + ($y - $pos->y) ** 2 + (abs($z) - abs($pos->z)) ** 2) < (abs($infos->x / 2 + $xBounded) + abs($infos->y / 2 + $yBounded) + abs($infos->z / 2 + $zBounded)) ** 2 // if(abs((abs($x) - abs($pos->x)) ** 2 +($y - $pos->y) ** 2 +(abs($z) - abs($pos->z)) ** 2) <(abs($infos->x / 2 + $xBounded) + abs($infos->y / 2 + $yBounded) + abs($infos->z / 2 + $zBounded)) ** 2
if (abs((abs($x) - abs($pos->x)) ** 2 + ($y - $pos->y) ** 2 + (abs($z) - abs($pos->z)) ** 2) < ((($infos->x / 2 - $xBounded) + ($infos->y / 2 - $yBounded) + ($infos->z / 2 - $zBounded)) / 3) ** 2 && $y > 0 && ! in_array($level->getBlockIdAt($x, $y, $z), self::TO_NOT_OVERWRITE) && ! in_array($level->getBlockIdAt($x, $y + 1, $z), self::TO_NOT_OVERWRITE)) { if(abs((abs($x) - abs($pos->x)) ** 2 +($y - $pos->y) ** 2 +(abs($z) - abs($pos->z)) ** 2) <((($infos->x / 2 - $xBounded) +($infos->y / 2 - $yBounded) +($infos->z / 2 - $zBounded)) / 3) ** 2 && $y > 0 && ! in_array($level->getBlockIdAt($x, $y, $z), self::TO_NOT_OVERWRITE) && ! in_array($level->getBlockIdAt($x, $y + 1, $z), self::TO_NOT_OVERWRITE)) {
$level->setBlockIdAt($x, $y, $z, $block->getId ()); $level->setBlockIdAt($x, $y, $z, $block->getId());
$level->setBlockDataAt($x, $y, $z, $block->getDamage ()); $level->setBlockDataAt($x, $y, $z, $block->getDamage());
} }
} }
} }
@ -210,7 +210,7 @@ class BuildingUtils {
* @param Vector3 $pos2 * @param Vector3 $pos2
* @return array * @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)); $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)); $v2 = new Vector3(min($pos1->x, $pos2->x), min($pos1->y, $pos2->y), min($pos1->z, $pos2->z));
return [ return [