Browse Source

Make Generation max height depend on the actual maxheight, fix PHPstorm namespaces

pull/18/head
thebigsmileXD 2 years ago
parent
commit
38f9faecd8

+ 1
- 0
.gitignore View File

@@ -0,0 +1 @@
.idea/*

+ 3
- 1
src/Ad5001/BetterGen/generator/BetterNormal.php View File

@@ -15,6 +15,7 @@
namespace Ad5001\BetterGen\generator;

use pocketmine\level\ChunkManager;
use pocketmine\math\Vector3;
use pocketmine\utils\Random;
use pocketmine\level\generator\biome\Biome;
use pocketmine\level\generator\Generator;
@@ -61,6 +62,7 @@ class BetterNormal extends Generator {
Block::STILL_WATER
];
protected $selector;
/** @var Level */
protected $level;
protected $random;
protected $populators = [ ];
@@ -434,7 +436,7 @@ class BetterNormal extends Generator {
* @param $z int
*/
protected function getHighestWorkableBlock($x, $z) {
for($y = 127; $y > 0; -- $y) {
for($y = Level::Y_MAX; $y > 0; -- $y) {
$b = $this->level->getBlockIdAt($x, $y, $z);
if ($b === Block::DIRT or $b === Block::GRASS or $b === Block::PODZOL) {
break;

+ 3
- 1
src/Ad5001/BetterGen/populator/BushPopulator.php View File

@@ -14,6 +14,7 @@

namespace Ad5001\BetterGen\populator;

use pocketmine\level\Level;
use pocketmine\utils\Random;
use pocketmine\block\Block;
use pocketmine\level\ChunkManager;
@@ -22,6 +23,7 @@ use Ad5001\BetterGen\populator\AmountPopulator;
use Ad5001\BetterGen\structure\Bush;

class BushPopulator extends AmountPopulator {
/** @var ChunkManager */
protected $level;
protected $type;
@@ -62,7 +64,7 @@ class BushPopulator extends AmountPopulator {
* @param $z int
*/
protected function getHighestWorkableBlock($x, $z) {
for($y = 127; $y > 0; -- $y) {
for($y = Level::Y_MAX; $y > 0; -- $y) {
$b = $this->level->getBlockIdAt($x, $y, $z);
if ($b === Block::DIRT or $b === Block::GRASS or $b === Block::PODZOL) {
break;

+ 3
- 1
src/Ad5001/BetterGen/populator/CactusPopulator.php View File

@@ -17,11 +17,13 @@ namespace Ad5001\BetterGen\populator;

use pocketmine\block\Block;
use pocketmine\level\ChunkManager;
use pocketmine\level\Level;
use pocketmine\utils\Random;
use Ad5001\BetterGen\structure\Cactus;
use Ad5001\BetterGen\populator\AmountPopulator;

class CactusPopulator extends AmountPopulator {
/** @var ChunkManager */
protected $level;
/*
* Constructs the class
@@ -58,7 +60,7 @@ class CactusPopulator extends AmountPopulator {
* @param $z int
*/
protected function getHighestWorkableBlock($x, $z) {
for($y = 127; $y >= 0; -- $y) {
for($y = Level::Y_MAX; $y >= 0; -- $y) {
$b = $this->level->getBlockIdAt($x, $y, $z);
if ($b !== Block::AIR and $b !== Block::LEAVES and $b !== Block::LEAVES2) {
break;

+ 3
- 1
src/Ad5001/BetterGen/populator/CavePopulator.php View File

@@ -14,6 +14,7 @@

namespace Ad5001\BetterGen\populator;

use pocketmine\level\Level;
use pocketmine\utils\Random;
use pocketmine\block\Block;
use pocketmine\level\ChunkManager;
@@ -22,6 +23,7 @@ use Ad5001\BetterGen\utils\BuildingUtils;
use Ad5001\BetterGen\populator\AmountPopulator;

class CavePopulator extends AmountPopulator {
/** @var ChunkManager */
protected $level;
const STOP = false;
const CONTINUE = true;
@@ -65,7 +67,7 @@ class CavePopulator extends AmountPopulator {
* @param $z int
*/
protected function getHighestWorkableBlock($x, $z) {
for($y = 127; $y > 0; -- $y) {
for($y = Level::Y_MAX; $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;

+ 3
- 1
src/Ad5001/BetterGen/populator/DeadbushPopulator.php View File

@@ -16,10 +16,12 @@ namespace Ad5001\BetterGen\populator;

use pocketmine\block\Block;
use pocketmine\level\ChunkManager;
use pocketmine\level\Level;
use pocketmine\utils\Random;
use Ad5001\BetterGen\populator\AmountPopulator;

class DeadbushPopulator extends AmountPopulator {
/** @var ChunkManager */
protected $level;
/*
@@ -49,7 +51,7 @@ class DeadbushPopulator extends AmountPopulator {
* @param $z int
*/
protected function getHighestWorkableBlock($x, $z) {
for($y = 127; $y >= 0; -- $y) {
for($y = Level::Y_MAX; $y >= 0; -- $y) {
$b = $this->level->getBlockIdAt($x, $y, $z);
if ($b !== Block::AIR and $b !== Block::LEAVES and $b !== Block::LEAVES2) {
break;

+ 4
- 2
src/Ad5001/BetterGen/populator/FallenTreePopulator.php View File

@@ -16,12 +16,14 @@ namespace Ad5001\BetterGen\populator;

use pocketmine\block\Block;
use pocketmine\level\ChunkManager;
use pocketmine\level\Level;
use pocketmine\utils\Random;
use Ad5001\BetterGen\structure\FallenTree;
use Ad5001\BetterGen\populator\AmountPopulator;


class FallenTreePopulator extends AmountPopulator {
/** @var ChunkManager */
protected $level;
protected $type;
/*
@@ -51,7 +53,7 @@ class FallenTreePopulator extends AmountPopulator {
$z = $random->nextRange($chunkZ * 16, $chunkZ * 16 + 15);
$y = $this->getHighestWorkableBlock($x, $z);
if ($y !== -1 and $fallenTree->canPlaceObject($level, $x, $y + 1, $z, $random )) {
$fallenTree->placeObject($level, $x, $y + 1, $z, $random);
$fallenTree->placeObject($level, $x, $y + 1, $z);
}
}
}
@@ -62,7 +64,7 @@ class FallenTreePopulator extends AmountPopulator {
* @param $z int
*/
protected function getHighestWorkableBlock($x, $z) {
for($y = 127; $y >= 0; -- $y) {
for($y = Level::Y_MAX; $y >= 0; -- $y) {
$b = $this->level->getBlockIdAt($x, $y, $z);
if ($b !== Block::AIR and $b !== Block::LEAVES and $b !== Block::LEAVES2) {
break;

+ 10
- 5
src/Ad5001/BetterGen/populator/FloatingIslandPopulator.php View File

@@ -15,6 +15,8 @@
namespace Ad5001\BetterGen\populator;

use pocketmine\level\ChunkManager;
use pocketmine\level\format\Chunk;
use pocketmine\level\Level;
use pocketmine\utils\Random;
use Ad5001\BetterGen\generator\BetterNormal;
use pocketmine\block\Block;
@@ -39,6 +41,9 @@ class FloatingIslandPopulator extends AmountPopulator {
* @param $chunkZ int
* @param $random pocketmine\utils\Random
*/
/** @var ChunkManager */
private $level;

public function populate(ChunkManager $level, $chunkX, $chunkZ, Random $random) {
$this->level = $level;
if($this->getAmount($random) > 130) {
@@ -49,7 +54,7 @@ class FloatingIslandPopulator extends AmountPopulator {
$height = $this->buildIslandBottomShape($level, new Vector3($x, $y, $z), $radius, $random);
$this->populateOres($level, new Vector3($x, $y - 1, $z), $radius * 2, $height, $random);
$chunk = $level->getChunk($chunkX, $chunkZ);
$biome = BetterNormal::getBiomeById($chunk->getBiomeId($x % 16, $z % 16));
$biome = BetterNormal::getBiomeById($chunk->getBiomeId($x % 16, $z % 16));//static call
$populators = $biome->getPopulators();
foreach($populators as $populator) {
$populator->populate($level, $chunkX, $chunkZ, $random);
@@ -65,7 +70,7 @@ class FloatingIslandPopulator extends AmountPopulator {
* @param $z int
*/
protected function getHighestWorkableBlock($x, $z) {
for($y = 127; $y > 0; -- $y) {
for($y = Level::Y_MAX; $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) {
break;
@@ -90,7 +95,7 @@ class FloatingIslandPopulator extends AmountPopulator {
public function buildIslandBottomShape(ChunkManager $level, Vector3 $pos, int $radius, Random $random) {
$pos = $pos->round();
$xx = $pos->x;
$zz = $z;
$zz = $z; //undefined
$currentLen = 1;
$isEdge = false;
$hBound = 0;
@@ -105,7 +110,7 @@ class FloatingIslandPopulator extends AmountPopulator {
}
if(abs(abs($x - $pos->x) ** 2) + abs(abs($z - $pos->z) ** 2) <= ($radius ** 2) * 0.67 && $y < 128) {
if($chunk = $level->getChunk($x >> 4, $z >> 4)) {
$biome = BetterNormal::getBiomeById($chunk->getBiomeId($x % 16, $z % 16));
$biome = BetterNormal::getBiomeById($chunk->getBiomeId($x % 16, $z % 16));//static call
$block = $biome->getGroundCover()[$pos->y - $y - 1] ?? Block::get(Block::STONE);
$block = $block->getId();
} elseif($random->nextBoundedInt(5) == 0 && $isEdge) {
@@ -160,6 +165,6 @@ class FloatingIslandPopulator extends AmountPopulator {
new OreType(new GoldOre (), 2, 8, $pos->y - $height, $pos->y - round($height / 2)),
new OreType(new DiamondOre (), 1, 7, $pos->y - $height, $pos->y - round($height / 4))
]);
$ores->populate($level, $x >> 4, $z >> 4, $random);
$ores->populate($level, $x >> 4, $z >> 4, $random);//x z undefined
}
}

+ 3
- 1
src/Ad5001/BetterGen/populator/IglooPopulator.php View File

@@ -14,6 +14,7 @@
namespace Ad5001\BetterGen\populator;

use pocketmine\level\Level;
use pocketmine\utils\Random;
use pocketmine\block\Block;
use pocketmine\level\ChunkManager;
@@ -21,6 +22,7 @@ use Ad5001\BetterGen\populator\AmountPopulator;
use Ad5001\BetterGen\structure\Igloo;

class IglooPopulator extends AmountPopulator {
/** @var ChunkManager */
protected $level;
/*
@@ -48,7 +50,7 @@ class IglooPopulator extends AmountPopulator {
* @param $z int
*/
protected function getHighestWorkableBlock($x, $z) {
for($y = 127; $y > 0; -- $y) {
for($y = Level::Y_MAX; $y > 0; -- $y) {
$b = $this->level->getBlockIdAt($x, $y, $z);
if ($b === Block::DIRT or $b === Block::GRASS or $b === Block::PODZOL) {
break;

+ 3
- 1
src/Ad5001/BetterGen/populator/LakePopulator.php View File

@@ -14,6 +14,7 @@
namespace Ad5001\BetterGen\populator;

use pocketmine\level\Level;
use pocketmine\utils\Random;
use pocketmine\block\Block;
use pocketmine\level\ChunkManager;
@@ -22,6 +23,7 @@ use Ad5001\BetterGen\utils\BuildingUtils;
use Ad5001\BetterGen\populator\AmountPopulator;

class LakePopulator extends AmountPopulator {
/** @var ChunkManager */
protected $level;
/*
@@ -57,7 +59,7 @@ class LakePopulator extends AmountPopulator {
* @param $z int
*/
protected function getHighestWorkableBlock($x, $z) {
for($y = 127; $y > 0; -- $y) {
for($y = Level::Y_MAX; $y > 0; -- $y) {
$b = $this->level->getBlockIdAt($x, $y, $z);
if ($b === Block::DIRT or $b === Block::GRASS or $b === Block::PODZOL) {
break;

+ 3
- 1
src/Ad5001/BetterGen/populator/RavinePopulator.php View File

@@ -14,6 +14,7 @@

namespace Ad5001\BetterGen\populator;

use pocketmine\level\Level;
use pocketmine\utils\Random;
use pocketmine\block\Block;
use pocketmine\level\ChunkManager;
@@ -21,6 +22,7 @@ use Ad5001\BetterGen\populator\AmountPopulator;
use Ad5001\BetterGen\utils\BuildingUtils;

class RavinePopulator extends AmountPopulator {
/** @var ChunkManager */
protected $level;
const NOISE = 250;
@@ -74,7 +76,7 @@ class RavinePopulator extends AmountPopulator {
* @param $z int
*/
protected function getHighestWorkableBlock($x, $z) {
for($y = 127; $y > 0; -- $y) {
for($y = Level::Y_MAX; $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;

+ 3
- 1
src/Ad5001/BetterGen/populator/SugarCanePopulator.php View File

@@ -16,11 +16,13 @@ namespace Ad5001\BetterGen\populator;

use pocketmine\block\Block;
use pocketmine\level\ChunkManager;
use pocketmine\level\Level;
use pocketmine\utils\Random;
use Ad5001\BetterGen\structure\SugarCane;
use Ad5001\BetterGen\populator\AmountPopulator;

class SugarCanePopulator extends AmountPopulator {
/** @var ChunkManager */
protected $level;
/*
* Constructs the class
@@ -57,7 +59,7 @@ class SugarCanePopulator extends AmountPopulator {
* @param $z int
*/
protected function getHighestWorkableBlock($x, $z) {
for($y = 127; $y >= 0; -- $y) {
for($y = Level::Y_MAX; $y >= 0; -- $y) {
$b = $this->level->getBlockIdAt($x, $y, $z);
if ($b !== Block::AIR and $b !== Block::LEAVES and $b !== Block::LEAVES2) {
break;

+ 3
- 1
src/Ad5001/BetterGen/populator/TemplePopulator.php View File

@@ -14,6 +14,7 @@

namespace Ad5001\BetterGen\populator;

use pocketmine\level\Level;
use pocketmine\utils\Random;
use pocketmine\block\Block;
use pocketmine\level\ChunkManager;
@@ -21,6 +22,7 @@ use Ad5001\BetterGen\structure\Temple;
use Ad5001\BetterGen\populator\AmountPopulator;

class TemplePopulator extends AmountPopulator {
/** @var Level */
protected $level;
/*
@@ -48,7 +50,7 @@ class TemplePopulator extends AmountPopulator {
* @param $z int
*/
protected function getHighestWorkableBlock($x, $z) {
for($y = 127; $y > 0; -- $y) {
for($y = Level::Y_MAX; $y > 0; -- $y) {
$b = $this->level->getBlockIdAt($x, $y, $z);
if ($b === Block::SAND) {
break;

+ 7
- 2
src/Ad5001/BetterGen/populator/TreePopulator.php View File

@@ -14,6 +14,8 @@

namespace Ad5001\BetterGen\populator;

use pocketmine\level\generator\object\Tree;
use pocketmine\level\Level;
use pocketmine\utils\Random;
use pocketmine\block\Block;
use pocketmine\level\ChunkManager;
@@ -23,11 +25,13 @@ use Ad5001\BetterGen\Main;


class TreePopulator extends AmountPopulator {
/** @var Tree[] */
static $types = [
"pocketmine\\level\\generator\\object\\OakTree",
"pocketmine\\level\\generator\\object\\BirchTree",
"Ad5001\\BetterGen\\structure\\SakuraTree"
];
/** @var ChunkManager */
protected $level;
protected $type;
@@ -63,7 +67,8 @@ class TreePopulator extends AmountPopulator {
continue;
}
$treeC = self::$types [$this->type];
$tree = new $treeC();
/** @var Tree $tree */
$tree = new $treeC();
$tree->placeObject($level, $x, $y, $z, $random);
}
}
@@ -74,7 +79,7 @@ class TreePopulator extends AmountPopulator {
* @param $z int
*/
protected function getHighestWorkableBlock($x, $z) {
for($y = 127; $y > 0; -- $y) {
for($y = Level::Y_MAX; $y > 0; -- $y) {
$b = $this->level->getBlockIdAt($x, $y, $z);
if ($b === Block::DIRT or $b === Block::GRASS or $b === Block::PODZOL) {
break;

+ 3
- 1
src/Ad5001/BetterGen/populator/WellPopulator.php View File

@@ -14,6 +14,7 @@

namespace Ad5001\BetterGen\populator;

use pocketmine\level\Level;
use pocketmine\utils\Random;
use pocketmine\block\Block;
use pocketmine\level\ChunkManager;
@@ -21,6 +22,7 @@ use Ad5001\BetterGen\structure\Well;
use Ad5001\BetterGen\populator\AmountPopulator;

class WellPopulator extends AmountPopulator {
/** @var ChunkManager */
protected $level;
/*
@@ -48,7 +50,7 @@ class WellPopulator extends AmountPopulator {
* @param $z int
*/
protected function getHighestWorkableBlock($x, $z) {
for($y = 127; $y > 0; -- $y) {
for($y = Level::Y_MAX; $y > 0; -- $y) {
$b = $this->level->getBlockIdAt($x, $y, $z);
if ($b === Block::SAND) {
break;

Loading…
Cancel
Save