BetterGen/src/Ad5001/BetterGen/populator/MineshaftPopulator.php

426 lines
18 KiB
PHP
Raw Normal View History

2017-04-23 14:42:51 +00:00
<?php
/**
* ____ __ __ ____
* /\ _`\ /\ \__ /\ \__ /\ _`\
* \ \ \L\ \ __ \ \ ,_\\ \ ,_\ __ _ __ \ \ \L\_\ __ ___
* \ \ _ <' /'__`\\ \ \/ \ \ \/ /'__`\/\`'__\\ \ \L_L /'__`\ /' _ `\
* \ \ \L\ \/\ __/ \ \ \_ \ \ \_ /\ __/\ \ \/ \ \ \/, \/\ __/ /\ \/\ \
* \ \____/\ \____\ \ \__\ \ \__\\ \____\\ \_\ \ \____/\ \____\\ \_\ \_\
* \/___/ \/____/ \/__/ \/__/ \/____/ \/_/ \/___/ \/____/ \/_/\/_/
* Tomorrow's pocketmine generator.
2017-05-14 18:13:15 +00:00
* @author Ad5001 <mail@ad5001.eu>, XenialDan <https://github.com/thebigsmileXD>
* @link https://github.com/Ad5001/BetterGen
2017-05-14 18:13:15 +00:00
* @category World Generator
* @api 3.0.0
* @version 1.1
2017-04-23 14:42:51 +00:00
*/
2017-04-23 14:42:51 +00:00
namespace Ad5001\BetterGen\populator;
2017-05-11 12:07:26 +00:00
use Ad5001\BetterGen\loot\LootTable;
2017-04-23 14:42:51 +00:00
use Ad5001\BetterGen\utils\BuildingUtils;
use pocketmine\block\Block;
2017-05-11 12:07:26 +00:00
use pocketmine\level\ChunkManager;
use pocketmine\math\Vector3;
use pocketmine\utils\Random;
2017-04-23 14:42:51 +00:00
class MineshaftPopulator extends AmountPopulator {
protected $maxPath;
/** @var ChunkManager */
2017-04-23 14:42:51 +00:00
protected $level;
const DIR_XPLUS = 0;
const DIR_XMIN = 1;
const DIR_ZPLUS = 2;
const DIR_ZMIN = 3;
const TYPE_FORWARD = 0;
const TYPE_CROSSPATH = 1;
const TYPE_STAIRS = 2;
/*
* 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) {
2017-05-13 21:27:10 +00:00
if ($this->getAmount($random) < 100)
2017-04-23 14:42:51 +00:00
return;
$this->level = $level;
2017-04-29 09:59:44 +00:00
$x = $random->nextRange($chunkX << 4, ($chunkX << 4) + 15);
$z = $random->nextRange($chunkZ << 4, ($chunkZ << 4) + 15);
$y = $random->nextRange(5, 50);
2017-04-23 14:42:51 +00:00
// First filling the large dirt place (center of the mineshaft)
2017-05-13 21:27:10 +00:00
BuildingUtils::fill($level, new Vector3($x - 6, $y, $x - 6), new Vector3($x + 6, $y + 8, $z + 6), Block::get(Block::AIR));
BuildingUtils::fill($level, new Vector3($x - 6, $y, $x - 6), new Vector3($x + 6, $y, $z + 6), Block::get(Block::DIRT));
2017-04-29 09:59:44 +00:00
$startingPath = $random->nextBoundedInt(4);
2017-05-13 21:27:10 +00:00
$this->maxPath = $random->nextBoundedInt(100) + 50;
foreach(array_fill(0, $startingPath, 1) as $hey) {
2017-04-29 09:59:44 +00:00
$dir = $random->nextBoundedInt(4);
2017-04-23 14:42:51 +00:00
switch ($dir) {
case self::DIR_XPLUS :
2017-05-13 21:27:10 +00:00
$this->generateMineshaftPart($x + 6, $y + $random->nextBoundedInt(5), $z + $random->nextBoundedInt(12) - 6, $dir, $random);
2017-04-23 14:42:51 +00:00
break;
case self::DIR_XMIN :
2017-05-13 21:27:10 +00:00
$this->generateMineshaftPart($x - 6, $y + $random->nextBoundedInt(5), $z + $random->nextBoundedInt(12) - 6, $dir, $random);
2017-04-23 14:42:51 +00:00
break;
case self::DIR_ZPLUS :
2017-05-13 21:27:10 +00:00
$this->generateMineshaftPart($x + $random->nextBoundedInt(12) - 6, $y + $random->nextBoundedInt(8), $z + 6, $dir, $random);
2017-04-23 14:42:51 +00:00
break;
case self::DIR_ZMIN :
2017-05-13 21:27:10 +00:00
$this->generateMineshaftPart($x + $random->nextBoundedInt(12) - 6, $y + $random->nextBoundedInt(8), $z - 6, $dir, $random);
2017-04-23 14:42:51 +00:00
break;
}
}
}
/**
2017-04-23 14:42:51 +00:00
* Builds a mineshaft part and return applicable directions
* @param int $x
* @param int $y
* @param int $z
* @param int $dir
* @param Random $random
2017-04-23 14:42:51 +00:00
*/
public function generateMineshaftPart(int $x, int $y, int $z, int $dir, Random $random) {
2017-05-14 18:13:15 +00:00
if ($this->maxPath -- < 1 || $y >= $this->level->getChunk(($x - ($x % 16)) / 16, ($z - ($z % 16)) / 16)->getHighestBlockAt($x % 16, $z % 16) - 10)
2017-04-23 14:42:51 +00:00
return;
2017-04-29 09:59:44 +00:00
$type = $random->nextBoundedInt(3);
2017-04-23 14:42:51 +00:00
$level = $this->level;
switch ($type) {
case self::TYPE_FORWARD :
switch ($dir) {
case self::DIR_XPLUS :
// First, filling everything blank.
2017-05-13 21:27:10 +00:00
BuildingUtils::fill($this->level, new Vector3($x, $y, $z - 1), new Vector3($x + 4, $y + 2, $z + 1), Block::get(Block::AIR));
2017-04-23 14:42:51 +00:00
// Then, making sure the floor is solid.
2017-05-13 21:27:10 +00:00
BuildingUtils::fillCallback(new Vector3($x, $y - 1, $z - 1), new Vector3($x + 4, $y - 1, $z + 1), function ($v3, ChunkManager $level) {
if ($level->getBlockIdAt($v3->x, $v3->y, $v3->z) == Block::AIR)
2017-04-29 09:59:44 +00:00
$level->setBlockIdAt($v3->x, $v3->y, $v3->z, Block::PLANK);
}, $this->level);
2017-04-23 14:42:51 +00:00
// Putting rails
2017-05-13 21:27:10 +00:00
BuildingUtils::fillCallback(new Vector3($x, $y, $z), new Vector3($x + 4, $y, $z), function ($v3, ChunkManager $level, Random $random) {
if ($random->nextBoundedInt(3) !== 0) {
2017-04-29 09:59:44 +00:00
$level->setBlockIdAt($v3->x, $v3->y, $v3->z, Block::RAIL);
$level->setBlockDataAt($v3->x, $v3->y, $v3->z, 1);
2017-04-23 14:42:51 +00:00
}
2017-04-29 09:59:44 +00:00
}, $this->level, $random);
// After this, building the floor maintainer (the wood structure)
2017-04-29 09:59:44 +00:00
$level->setBlockIdAt($x, $y, $z - 1, Block::FENCE);
$level->setBlockIdAt($x, $y, $z + 1, Block::FENCE);
$level->setBlockIdAt($x, $y + 1, $z - 1, Block::FENCE);
$level->setBlockIdAt($x, $y + 1, $z + 1, Block::FENCE);
$level->setBlockIdAt($x, $y + 2, $z - 1, Block::PLANK);
$level->setBlockIdAt($x, $y + 2, $z, Block::PLANK);
$level->setBlockIdAt($x, $y + 2, $z + 1, Block::PLANK);
$level->setBlockIdAt($x + 1, $y + 2, $z, Block::TORCH);
$level->setBlockDataAt($x + 1, $y + 2, $z, 2);
2017-04-23 14:42:51 +00:00
// Generating chest
2017-05-13 21:27:10 +00:00
if ($random->nextBoundedInt(30) == 0) {
$direction =(int) $random->nextBoolean ();
2017-04-23 14:42:51 +00:00
if ($direction == 0)
2017-04-29 09:59:44 +00:00
$direction = -1; // Choosing the part of the rail.
2017-05-13 21:27:10 +00:00
$direction2 =(int) $random->nextBoolean ();
2017-04-23 14:42:51 +00:00
if ($direction2 == 0)
$direction2 = 2;
if ($direction2 == 1)
$direction2 = 4;
2017-05-13 21:27:10 +00:00
LootTable::buildLootTable(new Vector3($x + $direction2, $y, $z + $direction), LootTable::LOOT_MINESHAFT, $random);
2017-04-23 14:42:51 +00:00
}
2017-05-13 21:27:10 +00:00
if ($random->nextBoundedInt(30) !== 0)
2017-04-29 09:59:44 +00:00
$this->generateMineshaftPart($x + 5, $y, $z, $dir, $random);
2017-04-23 14:42:51 +00:00
break;
case self::DIR_XMIN :
// First, filling everything blank.
2017-05-13 21:27:10 +00:00
BuildingUtils::fill($this->level, new Vector3($x, $y, $z - 1), new Vector3($x - 4, $y + 2, $z + 1));
2017-04-23 14:42:51 +00:00
// Then, making sure the floor is solid.
2017-05-13 21:27:10 +00:00
BuildingUtils::fillCallback(new Vector3($x, $y - 1, $z - 1), new Vector3($x - 4, $y - 1, $z + 1), function ($v3, ChunkManager $level) {
2017-05-13 21:27:10 +00:00
if ($level->getBlockIdAt($v3->x, $v3->y, $v3->z) == Block::AIR)
2017-04-29 09:59:44 +00:00
$level->setBlockIdAt($v3->x, $v3->y, $v3->z, Block::PLANK);
}, $this->level);
2017-04-23 14:42:51 +00:00
// Putting rails
2017-05-13 21:27:10 +00:00
BuildingUtils::fillCallback(new Vector3($x, $y, $z), new Vector3($x - 4, $y, $z), function ($v3, ChunkManager $level, Random $random) {
if ($random->nextBoundedInt(3) !== 0) {
2017-04-29 09:59:44 +00:00
$level->setBlockIdAt($v3->x, $v3->y, $v3->z, Block::RAIL);
$level->setBlockDataAt($v3->x, $v3->y, $v3->z, 1);
2017-04-23 14:42:51 +00:00
}
2017-04-29 09:59:44 +00:00
}, $this->level, $random);
// After this, building the floor maintainer (the wood structure)
2017-04-29 09:59:44 +00:00
$level->setBlockIdAt($x, $y, $z - 1, Block::FENCE);
$level->setBlockIdAt($x, $y, $z + 1, Block::FENCE);
$level->setBlockIdAt($x, $y + 1, $z - 1, Block::FENCE);
$level->setBlockIdAt($x, $y + 1, $z + 1, Block::FENCE);
$level->setBlockIdAt($x, $y + 2, $z - 1, Block::PLANK);
$level->setBlockIdAt($x, $y + 2, $z, Block::PLANK);
$level->setBlockIdAt($x, $y + 2, $z + 1, Block::PLANK);
$level->setBlockIdAt($x - 1, $y + 2, $z, Block::TORCH);
$level->setBlockDataAt($x - 1, $y + 2, $z, 1);
2017-04-23 14:42:51 +00:00
// Generating chest
2017-05-13 21:27:10 +00:00
if ($random->nextBoundedInt(30) == 0) {
$direction =(int) $random->nextBoolean ();
2017-04-23 14:42:51 +00:00
if ($direction == 0)
2017-04-29 09:59:44 +00:00
$direction = -1; // Choosing the part of the rail.
2017-05-13 21:27:10 +00:00
$direction2 =(int) $random->nextBoolean ();
2017-04-23 14:42:51 +00:00
if ($direction2 == 0)
$direction2 = 2;
if ($direction2 == 1)
$direction2 = 4;
2017-05-13 21:27:10 +00:00
LootTable::buildLootTable(new Vector3($x - $direction2, $y, $z + $direction), LootTable::LOOT_MINESHAFT, $random);
2017-04-23 14:42:51 +00:00
}
2017-05-13 21:27:10 +00:00
if ($random->nextBoundedInt(30) !== 0)
2017-04-29 09:59:44 +00:00
$this->generateMineshaftPart($x - 5, $y, $z, $dir, $random);
2017-04-23 14:42:51 +00:00
break;
case self::DIR_ZPLUS :
// First, filling everything blank.
2017-05-13 21:27:10 +00:00
BuildingUtils::fill($this->level, new Vector3($x - 1, $y, $z), new Vector3($x + 1, $y + 2, $z + 4));
2017-04-23 14:42:51 +00:00
// Then, making sure the floor is solid.
2017-05-13 21:27:10 +00:00
BuildingUtils::fillCallback(new Vector3($x - 1, $y - 1, $z), new Vector3($x + 1, $y - 1, $z + 4), function ($v3, ChunkManager $level) {
2017-05-13 21:27:10 +00:00
if ($level->getBlockIdAt($v3->x, $v3->y, $v3->z) == Block::AIR)
2017-04-29 09:59:44 +00:00
$level->setBlockIdAt($v3->x, $v3->y, $v3->z, Block::PLANK);
}, $this->level);
2017-04-23 14:42:51 +00:00
// Putting rails
2017-05-13 21:27:10 +00:00
BuildingUtils::fillCallback(new Vector3($x, $y, $z), new Vector3($x, $y, $z + 4), function ($v3, ChunkManager $level, Random $random) {
if ($random->nextBoundedInt(3) !== 0) {
2017-04-29 09:59:44 +00:00
$level->setBlockIdAt($v3->x, $v3->y, $v3->z, Block::RAIL);
$level->setBlockDataAt($v3->x, $v3->y, $v3->z, 0);
2017-04-23 14:42:51 +00:00
}
2017-04-29 09:59:44 +00:00
}, $this->level, $random);
// After this, building the floor maintainer (the wood structure)
2017-04-29 09:59:44 +00:00
$level->setBlockIdAt($x - 1, $y, $z, Block::FENCE);
$level->setBlockIdAt($x + 1, $y, $z, Block::FENCE);
$level->setBlockIdAt($x - 1, $y + 1, $z, Block::FENCE);
$level->setBlockIdAt($x + 1, $y + 1, $z, Block::FENCE);
$level->setBlockIdAt($x - 1, $y + 2, $z, Block::PLANK);
$level->setBlockIdAt($x, $y + 2, $z, Block::PLANK);
$level->setBlockIdAt($x + 1, $y + 2, $z, Block::PLANK);
$level->setBlockIdAt($x, $y + 2, $z - 1, Block::TORCH);
$level->setBlockDataAt($x, $y + 2, $z - 1, 4);
2017-04-23 14:42:51 +00:00
// Generating chest
2017-05-13 21:27:10 +00:00
if ($random->nextBoundedInt(30) == 0) {
$direction =(int) $random->nextBoolean ();
2017-04-23 14:42:51 +00:00
if ($direction == 0)
2017-04-29 09:59:44 +00:00
$direction = -1; // Choosing the part of the rail.
2017-05-13 21:27:10 +00:00
$direction2 =(int) $random->nextBoolean ();
2017-04-23 14:42:51 +00:00
if ($direction2 == 0)
$direction2 = 2;
if ($direction2 == 1)
$direction2 = 4;
2017-05-13 21:27:10 +00:00
LootTable::buildLootTable(new Vector3($x + $direction, $y, $z + $direction2), LootTable::LOOT_MINESHAFT, $random);
2017-04-23 14:42:51 +00:00
}
2017-05-13 21:27:10 +00:00
if ($random->nextBoundedInt(30) !== 0)
2017-04-29 09:59:44 +00:00
$this->generateMineshaftPart($x, $y, $z + 5, $dir, $random);
2017-04-23 14:42:51 +00:00
break;
case self::DIR_ZMIN :
// First, filling everything blank.
2017-05-13 21:27:10 +00:00
BuildingUtils::fill($this->level, new Vector3($x - 1, $y, $z), new Vector3($x + 1, $y + 2, $z - 4));
2017-04-23 14:42:51 +00:00
// Then, making sure the floor is solid.
2017-05-13 21:27:10 +00:00
BuildingUtils::fillCallback(new Vector3($x - 1, $y - 1, $z), new Vector3($x + 1, $y - 1, $z - 4), function ($v3, ChunkManager $level) {
2017-05-13 21:27:10 +00:00
if ($level->getBlockIdAt($v3->x, $v3->y, $v3->z) == Block::AIR)
2017-04-29 09:59:44 +00:00
$level->setBlockIdAt($v3->x, $v3->y, $v3->z, Block::PLANK);
}, $this->level);
2017-04-23 14:42:51 +00:00
// Putting rails
2017-05-13 21:27:10 +00:00
BuildingUtils::fillCallback(new Vector3($x, $y, $z), new Vector3($x, $y, $z - 4), function ($v3, ChunkManager $level, Random $random) {
if ($random->nextBoundedInt(3) !== 0) {
2017-04-29 09:59:44 +00:00
$level->setBlockIdAt($v3->x, $v3->y, $v3->z, Block::RAIL);
$level->setBlockDataAt($v3->x, $v3->y, $v3->z, 0);
2017-04-23 14:42:51 +00:00
}
2017-04-29 09:59:44 +00:00
}, $this->level, $random);
// After this, building the floor maintainer (the wood structure)
2017-04-29 09:59:44 +00:00
$level->setBlockIdAt($x - 1, $y, $z, Block::FENCE);
$level->setBlockIdAt($x + 1, $y, $z, Block::FENCE);
$level->setBlockIdAt($x - 1, $y + 1, $z, Block::FENCE);
$level->setBlockIdAt($x + 1, $y + 1, $z, Block::FENCE);
$level->setBlockIdAt($x - 1, $y + 2, $z, Block::PLANK);
$level->setBlockIdAt($x, $y + 2, $z, Block::PLANK);
$level->setBlockIdAt($x + 1, $y + 2, $z, Block::PLANK);
$level->setBlockIdAt($x, $y + 2, $z - 1, Block::TORCH);
$level->setBlockDataAt($x, $y + 2, $z - 1, 3);
2017-04-23 14:42:51 +00:00
// Generating chest
2017-05-13 21:27:10 +00:00
if ($random->nextBoundedInt(30) == 0) {
$direction =(int) $random->nextBoolean ();
2017-04-23 14:42:51 +00:00
if ($direction == 0)
2017-04-29 09:59:44 +00:00
$direction = -1; // Choosing the part of the rail.
2017-05-13 21:27:10 +00:00
$direction2 =(int) $random->nextBoolean ();
2017-04-23 14:42:51 +00:00
if ($direction2 == 0)
$direction2 = 2;
if ($direction2 == 1)
$direction2 = 4;
2017-05-13 21:27:10 +00:00
LootTable::buildLootTable(new Vector3($x + $direction, $y, $z - $direction2), LootTable::LOOT_MINESHAFT, $random);
2017-04-23 14:42:51 +00:00
}
2017-05-13 21:27:10 +00:00
if ($random->nextBoundedInt(30) !== 0)
2017-04-29 09:59:44 +00:00
$this->generateMineshaftPart($x, $y, $z - 5, $dir, $random);
2017-04-23 14:42:51 +00:00
break;
}
// Doing cobwebs
2017-05-13 21:27:10 +00:00
$webNum = $random->nextBoundedInt(5) + 2;
2017-04-23 14:42:51 +00:00
for($i = 0; $i < $webNum; $i ++) {
2017-05-13 21:27:10 +00:00
$xx = $x + $random->nextBoundedInt(5) - 2;
2017-04-29 09:59:44 +00:00
$yy = $y + $random->nextBoundedInt(3);
2017-05-13 21:27:10 +00:00
$zz = $z + $random->nextBoundedInt(5) - 2;
if ($level->getBlockIdAt($xx, $yy, $zz) == Block::AIR)
2017-04-29 09:59:44 +00:00
$level->setBlockIdAt($xx, $yy, $zz, Block::COBWEB);
2017-04-23 14:42:51 +00:00
}
break;
case self::TYPE_CROSSPATH :
$possiblePathes = [
self::DIR_XPLUS,
self::DIR_XMIN,
self::DIR_ZPLUS,
self::DIR_ZMIN
];
switch ($dir) {
case self::DIR_XPLUS :
$x ++;
2017-05-13 21:42:44 +00:00
unset($possiblePathes[0]);
2017-04-23 14:42:51 +00:00
break;
case self::DIR_XMIN :
$x --;
2017-05-13 21:42:44 +00:00
unset($possiblePathes[1]);
2017-04-23 14:42:51 +00:00
break;
case self::DIR_ZPLUS :
$z ++;
2017-05-13 21:42:44 +00:00
unset($possiblePathes[2]);
2017-04-23 14:42:51 +00:00
break;
case self::DIR_ZMIN :
$z --;
2017-05-13 21:42:44 +00:00
unset($possiblePathes[3]);
2017-04-23 14:42:51 +00:00
break;
}
// Then, making sure the floor is solid.
2017-05-13 21:27:10 +00:00
BuildingUtils::fillCallback(new Vector3($x + 1, $y - 1, $z - 1), new Vector3($x - 1, $y - 1, $z + 1), function ($v3, ChunkManager $level) {
2017-05-13 21:27:10 +00:00
if ($level->getBlockIdAt($v3->x, $v3->y, $v3->z) == Block::AIR)
2017-04-29 09:59:44 +00:00
$level->setBlockIdAt($v3->x, $v3->y, $v3->z, Block::PLANK);
}, $this->level);
2017-04-23 14:42:51 +00:00
// Putting rails
2017-05-13 21:27:10 +00:00
BuildingUtils::fill($this->level, new Vector3($x - 1, $y, $z - 1), new Vector3($x + 1, $y + 6, $z + 1), Block::get(Block::AIR));
2017-04-23 14:42:51 +00:00
2017-05-13 21:27:10 +00:00
BuildingUtils::corners($this->level, new Vector3($x - 1, $y, $z - 1), new Vector3($x + 1, $y + 6, $z + 1), Block::get(Block::PLANK));
2017-04-23 14:42:51 +00:00
$newFloor = $random->nextBoolean ();
2017-04-29 09:59:44 +00:00
$numberFloor = $random->nextBoundedInt(4 + ($newFloor ? 5 : 0));
2017-04-23 14:42:51 +00:00
$possiblePathes = [
$possiblePathes,
2017-05-13 21:42:44 +00:00
($newFloor ?[
2017-04-23 14:42:51 +00:00
self::DIR_XPLUS,
self::DIR_XMIN,
self::DIR_ZPLUS,
self::DIR_ZMIN
] : [ ])
];
2017-05-11 12:07:26 +00:00
for($i = 7; $i > $newFloor; $i --) {
2017-05-13 21:27:10 +00:00
$chooseNew =(int) $newFloor && $random->nextBoolean ();
2017-04-29 09:59:44 +00:00
$choose = $random->nextBoundedInt(4);
2017-05-13 21:42:44 +00:00
unset($possiblePathes[$chooseNew] [$choose]);
2017-04-23 14:42:51 +00:00
}
// Building pathes
2017-05-13 21:42:44 +00:00
foreach($possiblePathes[0] as $path) {
2017-04-23 14:42:51 +00:00
switch ($path) {
case self::DIR_XPLUS :
2017-04-29 09:59:44 +00:00
$this->generateMineshaftPart($x + 2, $y, $z, self::DIR_XPLUS, $random);
2017-04-23 14:42:51 +00:00
break;
case self::DIR_XMIN :
2017-04-29 09:59:44 +00:00
$this->generateMineshaftPart($x - 2, $y, $z, self::DIR_XMIN, $random);
2017-04-23 14:42:51 +00:00
break;
case self::DIR_ZPLUS :
2017-04-29 09:59:44 +00:00
$this->generateMineshaftPart($x, $y, $z + 2, self::DIR_ZPLUS, $random);
2017-04-23 14:42:51 +00:00
break;
case self::DIR_ZMIN :
2017-04-29 09:59:44 +00:00
$this->generateMineshaftPart($x, $y, $z - 2, self::DIR_ZMIN, $random);
2017-04-23 14:42:51 +00:00
break;
}
}
2017-05-13 21:42:44 +00:00
foreach($possiblePathes[1] as $path) {
2017-04-23 14:42:51 +00:00
switch ($path) {
case self::DIR_XPLUS :
2017-04-29 09:59:44 +00:00
$this->generateMineshaftPart($x + 2, $y + 4, $z, self::DIR_XPLUS, $random);
2017-04-23 14:42:51 +00:00
break;
case self::DIR_XMIN :
2017-04-29 09:59:44 +00:00
$this->generateMineshaftPart($x - 2, $y + 4, $z, self::DIR_XMIN, $random);
2017-04-23 14:42:51 +00:00
break;
case self::DIR_ZPLUS :
2017-04-29 09:59:44 +00:00
$this->generateMineshaftPart($x, $y + 4, $z + 2, self::DIR_ZPLUS, $random);
2017-04-23 14:42:51 +00:00
break;
case self::DIR_ZMIN :
2017-04-29 09:59:44 +00:00
$this->generateMineshaftPart($x, $y + 4, $z - 2, self::DIR_ZMIN, $random);
2017-04-23 14:42:51 +00:00
break;
}
}
// Doing cobwebs
2017-05-13 21:27:10 +00:00
$webNum = $random->nextBoundedInt(5) + 2;
2017-04-23 14:42:51 +00:00
for($i = 0; $i < $webNum; $i ++) {
2017-05-13 21:27:10 +00:00
$xx = $x + $random->nextBoundedInt(3) - 1;
2017-04-29 09:59:44 +00:00
$yy = $y + $random->nextBoundedInt(6);
2017-05-13 21:27:10 +00:00
$zz = $z + $random->nextBoundedInt(3) - 1;
if ($level->getBlockIdAt($xx, $yy, $zz) == Block::AIR)
2017-04-29 09:59:44 +00:00
$level->setBlockIdAt($xx, $yy, $zz, Block::COBWEB);
2017-04-23 14:42:51 +00:00
}
break;
case self::TYPE_STAIRS :
if($y <= 5) {
2017-04-29 09:59:44 +00:00
$this->generateMineshaftPart($x, $y, $z, $dir, $random);
2017-04-23 14:42:51 +00:00
return;
}
// Building stairs
for($i = 0; $i < 4; $i ++) {
2017-05-11 12:07:26 +00:00
switch ($i) {
2017-04-23 14:42:51 +00:00
case self::DIR_XPLUS :
2017-05-13 21:27:10 +00:00
BuildingUtils::fill($this->level, new Vector3($x + $i, $y - $i - 1, $z - 2), new Vector3($x + $i, $y - $i + 3, $z + 2), Block::get(Block::AIR));
BuildingUtils::fillCallback(new Vector3($x + $i, $y - $i - 2, $z - 2), new Vector3($x + $i, $y - $i - 2, $z + 2), function ($v3, ChunkManager $level) {
if ($level->getBlockIdAt($v3->x, $v3->y, $v3->z) == Block::AIR)
2017-04-29 09:59:44 +00:00
$level->setBlockIdAt($v3->x, $v3->y, $v3->z, Block::PLANK);
}, $this->level);
2017-04-23 14:42:51 +00:00
break;
case self::DIR_XMIN :
2017-05-13 21:27:10 +00:00
BuildingUtils::fill($this->level, new Vector3($x - $i, $y - $i - 1, $z - 2), new Vector3($x - $i, $y - $i + 3, $z + 2), Block::get(Block::AIR));
BuildingUtils::fillCallback(new Vector3($x - $i, $y - $i - 2, $z - 2), new Vector3($x - $i, $y - $i - 2, $z + 2), function ($v3, ChunkManager $level) {
2017-05-13 21:27:10 +00:00
if ($level->getBlockIdAt($v3->x, $v3->y, $v3->z) == Block::AIR)
2017-04-29 09:59:44 +00:00
$level->setBlockIdAt($v3->x, $v3->y, $v3->z, Block::PLANK);
}, $this->level);
2017-04-23 14:42:51 +00:00
break;
case self::DIR_ZPLUS :
2017-05-13 21:27:10 +00:00
BuildingUtils::fill($this->level, new Vector3($x - 2, $y - $i - 1, $z + $i), new Vector3($x + 2, $y - $i + 3, $z + $i), Block::get(Block::AIR));
BuildingUtils::fillCallback(new Vector3($x - 2, $y - $i - 2, $z + $i), new Vector3($x + 2, $y - $i - 2, $z + $i), function ($v3, ChunkManager $level) {
2017-05-13 21:27:10 +00:00
if ($level->getBlockIdAt($v3->x, $v3->y, $v3->z) == Block::AIR)
2017-04-29 09:59:44 +00:00
$level->setBlockIdAt($v3->x, $v3->y, $v3->z, Block::PLANK);
}, $this->level);
2017-04-23 14:42:51 +00:00
break;
case self::DIR_ZMIN :
2017-05-13 21:27:10 +00:00
BuildingUtils::fill($this->level, new Vector3($x - 2, $y - $i - 1, $z - $i), new Vector3($x + 2, $y - $i + 3, $z - $i), Block::get(Block::AIR));
BuildingUtils::fillCallback(new Vector3($x - 2, $y - $i - 2, $z - $i), new Vector3($x + 2, $y - $i - 2, $z - $i), function ($v3, ChunkManager $level) {
2017-05-13 21:27:10 +00:00
if ($level->getBlockIdAt($v3->x, $v3->y, $v3->z) == Block::AIR)
2017-04-29 09:59:44 +00:00
$level->setBlockIdAt($v3->x, $v3->y, $v3->z, Block::PLANK);
}, $this->level);
2017-04-23 14:42:51 +00:00
break;
}
}
// Next one
2017-05-11 12:07:26 +00:00
switch ($i) {
2017-04-23 14:42:51 +00:00
case self::DIR_XPLUS :
2017-04-29 09:59:44 +00:00
$this->generateMineshaftPart($x + 4, $y - 4, $z, self::DIR_XPLUS, $random);
2017-04-23 14:42:51 +00:00
break;
case self::DIR_XMIN :
2017-04-29 09:59:44 +00:00
$this->generateMineshaftPart($x - 4, $y - 4, $z, self::DIR_XMIN, $random);
2017-04-23 14:42:51 +00:00
break;
case self::DIR_ZPLUS :
2017-04-29 09:59:44 +00:00
$this->generateMineshaftPart($x, $y - 4, $z + 4, self::DIR_ZPLUS, $random);
2017-04-23 14:42:51 +00:00
break;
case self::DIR_ZMIN :
2017-04-29 09:59:44 +00:00
$this->generateMineshaftPart($x, $y - 4, $z - 4, self::DIR_ZMIN, $random);
2017-04-23 14:42:51 +00:00
break;
}
break;
}
}
}
?>