forked from Ad5001/BetterGen
Dungeons!
This commit is contained in:
parent
2a9c440d10
commit
4b5cdeed6e
5 changed files with 112 additions and 65 deletions
|
@ -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([
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -42,11 +42,11 @@ class BuildingUtils {
|
|||
* @return void
|
||||
*/
|
||||
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);
|
||||
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->setBlockDataAt($x, $y, $z, $block->getDamage ());
|
||||
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->setBlockDataAt($x, $y, $z, $block->getDamage());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,11 +63,11 @@ class BuildingUtils {
|
|||
* @return void
|
||||
*/
|
||||
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);
|
||||
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->setBlockDataAt($x, $y, $z, $block->getDamage ());
|
||||
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->setBlockDataAt($x, $y, $z, $block->getDamage());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -83,7 +83,7 @@ class BuildingUtils {
|
|||
public static function fillCallback(Vector3 $pos1, Vector3 $pos2, callable $call, ...$params) : array {
|
||||
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 --) {
|
||||
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 $return;
|
||||
|
@ -100,18 +100,18 @@ class BuildingUtils {
|
|||
*/
|
||||
public static function walls(ChunkManager $level, Vector3 $pos1, Vector3 $pos2, Block $block) {
|
||||
list($pos1, $pos2) = self::minmax($pos1, $pos2);
|
||||
for($y = $pos1->y; $y >= $pos2->y; $y --) {
|
||||
for($x = $pos1->x; $x >= $pos2->x; $x --) {
|
||||
$level->setBlockIdAt($x, $y, $pos1->z, $block->getId ());
|
||||
$level->setBlockDataAt($x, $y, $pos1->z, $block->getDamage ());
|
||||
$level->setBlockIdAt($x, $y, $pos2->z, $block->getId ());
|
||||
$level->setBlockDataAt($x, $y, $pos2->z, $block->getDamage ());
|
||||
for($y = $pos1->y; $y >= $pos2->y; $y--) {
|
||||
for($x = $pos1->x; $x >= $pos2->x; $x--) {
|
||||
$level->setBlockIdAt($x, $y, $pos1->z, $block->getId());
|
||||
$level->setBlockDataAt($x, $y, $pos1->z, $block->getDamage());
|
||||
$level->setBlockIdAt($x, $y, $pos2->z, $block->getId());
|
||||
$level->setBlockDataAt($x, $y, $pos2->z, $block->getDamage());
|
||||
}
|
||||
for($z = $pos1->z; $z >= $pos2->z; $z --) {
|
||||
$level->setBlockIdAt($pos1->x, $y, $z, $block->getId ());
|
||||
$level->setBlockDataAt($pos1->x, $y, $z, $block->getDamage ());
|
||||
$level->setBlockIdAt($pos2->x, $y, $z, $block->getId ());
|
||||
$level->setBlockDataAt($pos2->x, $y, $z, $block->getDamage ());
|
||||
for($z = $pos1->z; $z >= $pos2->z; $z--) {
|
||||
$level->setBlockIdAt($pos1->x, $y, $z, $block->getId());
|
||||
$level->setBlockDataAt($pos1->x, $y, $z, $block->getDamage());
|
||||
$level->setBlockIdAt($pos2->x, $y, $z, $block->getId());
|
||||
$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) {
|
||||
list($pos1, $pos2) = self::minmax($pos1, $pos2);
|
||||
for($x = $pos1->x; $x >= $pos2->x; $x --)
|
||||
for($z = $pos1->z; $z >= $pos2->z; $z --) {
|
||||
$level->setBlockIdAt($x, $pos1->y, $z, $block->getId ());
|
||||
$level->setBlockDataAt($x, $pos1->y, $z, $block->getDamage ());
|
||||
for($x = $pos1->x; $x >= $pos2->x; $x--)
|
||||
for($z = $pos1->z; $z >= $pos2->z; $z--) {
|
||||
$level->setBlockIdAt($x, $pos1->y, $z, $block->getId());
|
||||
$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) {
|
||||
list($pos1, $pos2) = self::minmax($pos1, $pos2);
|
||||
for($y = $pos1->y; $y >= $pos2->y; $y --) {
|
||||
$level->setBlockIdAt($pos1->x, $y, $pos1->z, $block->getId ());
|
||||
$level->setBlockDataAt($pos1->x, $y, $pos1->z, $block->getDamage ());
|
||||
$level->setBlockIdAt($pos2->x, $y, $pos1->z, $block->getId ());
|
||||
$level->setBlockDataAt($pos2->x, $y, $pos1->z, $block->getDamage ());
|
||||
$level->setBlockIdAt($pos1->x, $y, $pos2->z, $block->getId ());
|
||||
$level->setBlockDataAt($pos1->x, $y, $pos2->z, $block->getDamage ());
|
||||
$level->setBlockIdAt($pos2->x, $y, $pos2->z, $block->getId ());
|
||||
$level->setBlockDataAt($pos2->x, $y, $pos2->z, $block->getDamage ());
|
||||
for($y = $pos1->y; $y >= $pos2->y; $y--) {
|
||||
$level->setBlockIdAt($pos1->x, $y, $pos1->z, $block->getId());
|
||||
$level->setBlockDataAt($pos1->x, $y, $pos1->z, $block->getDamage());
|
||||
$level->setBlockIdAt($pos2->x, $y, $pos1->z, $block->getId());
|
||||
$level->setBlockDataAt($pos2->x, $y, $pos1->z, $block->getDamage());
|
||||
$level->setBlockIdAt($pos1->x, $y, $pos2->z, $block->getId());
|
||||
$level->setBlockDataAt($pos1->x, $y, $pos2->z, $block->getDamage());
|
||||
$level->setBlockIdAt($pos2->x, $y, $pos2->z, $block->getId());
|
||||
$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) {
|
||||
list($pos1, $pos2) = self::minmax($pos1, $pos2);
|
||||
for($x = $pos1->x; $x >= $pos2->x; $x --)
|
||||
for($z = $pos1->z; $z >= $pos2->z; $z --) {
|
||||
$level->setBlockIdAt($x, $pos2->y, $z, $block->getId ());
|
||||
$level->setBlockDataAt($x, $pos2->y, $z, $block->getDamage ());
|
||||
for($x = $pos1->x; $x >= $pos2->x; $x--)
|
||||
for($z = $pos1->z; $z >= $pos2->z; $z--) {
|
||||
$level->setBlockIdAt($x, $pos2->y, $z, $block->getId());
|
||||
$level->setBlockDataAt($x, $pos2->y, $z, $block->getDamage());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -189,14 +189,14 @@ class BuildingUtils {
|
|||
$xBounded = $random->nextBoundedInt(3) - 1;
|
||||
$yBounded = $random->nextBoundedInt(3) - 1;
|
||||
$zBounded = $random->nextBoundedInt(3) - 1;
|
||||
$pos = $pos->round ();
|
||||
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($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) < ((($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->setBlockDataAt($x, $y, $z, $block->getDamage ());
|
||||
$pos = $pos->round();
|
||||
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($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) <((($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->setBlockDataAt($x, $y, $z, $block->getDamage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 [
|
||||
|
|
Loading…
Reference in a new issue