mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 01:46:04 +00:00
More typehints, documentation fixes and static analysis cleanup
This commit is contained in:
@ -74,8 +74,8 @@ class Flat extends Generator{
|
||||
new object\OreType(new GoldOre(), 2, 8, 0, 32),
|
||||
new object\OreType(new DiamondOre(), 1, 7, 0, 16),
|
||||
new object\OreType(new Dirt(), 20, 32, 0, 128),
|
||||
new object\OreType(new Gravel(), 10, 16, 0, 128),
|
||||
]);
|
||||
new object\OreType(new Gravel(), 10, 16, 0, 128)
|
||||
]);
|
||||
$this->populators[] = $ores;
|
||||
}
|
||||
|
||||
@ -90,7 +90,7 @@ class Flat extends Generator{
|
||||
$y = 0;
|
||||
foreach($matches[3] as $i => $b){
|
||||
$b = Item::fromString($b . $matches[4][$i]);
|
||||
$cnt = $matches[2][$i] === "" ? 1 : (int) ($matches[2][$i]);
|
||||
$cnt = $matches[2][$i] === "" ? 1 : (int) $matches[2][$i];
|
||||
for($cY = $y, $y += $cnt; $cY < $y; ++$cY){
|
||||
$result[$cY] = [$b->getId(), $b->getDamage()];
|
||||
}
|
||||
|
@ -65,8 +65,11 @@ abstract class Biome{
|
||||
/** @var Biome[] */
|
||||
private static $biomes = [];
|
||||
|
||||
/** @var int */
|
||||
private $id;
|
||||
/** @var bool */
|
||||
private $registered = false;
|
||||
|
||||
/** @var Populator[] */
|
||||
private $populators = [];
|
||||
|
||||
@ -75,9 +78,12 @@ abstract class Biome{
|
||||
/** @var int */
|
||||
private $maxElevation;
|
||||
|
||||
/** @var Block[] */
|
||||
private $groundCover = [];
|
||||
|
||||
/** @var float */
|
||||
protected $rainfall = 0.5;
|
||||
/** @var float */
|
||||
protected $temperature = 0.5;
|
||||
|
||||
protected static function register(int $id, Biome $biome){
|
||||
|
@ -39,8 +39,10 @@ class BiomeSelector{
|
||||
/** @var Biome[] */
|
||||
private $biomes = [];
|
||||
|
||||
private $map = [];
|
||||
/** @var \SplFixedArray */
|
||||
private $map = null;
|
||||
|
||||
/** @var callable */
|
||||
private $lookup;
|
||||
|
||||
public function __construct(Random $random, callable $lookup, Biome $fallback){
|
||||
|
@ -41,10 +41,15 @@ class Nether extends Generator{
|
||||
private $level;
|
||||
/** @var Random */
|
||||
private $random;
|
||||
/** @var int */
|
||||
private $waterHeight = 32;
|
||||
/** @var int */
|
||||
private $emptyHeight = 64;
|
||||
/** @var int */
|
||||
private $emptyAmplitude = 1;
|
||||
/** @var float */
|
||||
private $density = 0.5;
|
||||
/** @var int */
|
||||
private $bedrockDepth = 5;
|
||||
|
||||
/** @var Populator[] */
|
||||
|
@ -53,7 +53,9 @@ class Normal extends Generator{
|
||||
private $level;
|
||||
/** @var Random */
|
||||
private $random;
|
||||
/** @var int */
|
||||
private $waterHeight = 62;
|
||||
/** @var int */
|
||||
private $bedrockDepth = 5;
|
||||
|
||||
/** @var Populator[] */
|
||||
|
@ -34,7 +34,7 @@ class ForestBiome extends GrassyBiome{
|
||||
|
||||
public $type;
|
||||
|
||||
public function __construct($type = self::TYPE_NORMAL){
|
||||
public function __construct(int $type = self::TYPE_NORMAL){
|
||||
parent::__construct();
|
||||
|
||||
$this->type = $type;
|
||||
|
@ -33,7 +33,7 @@ abstract class SandyBiome extends NormalBiome{
|
||||
Block::get(Block::SAND, 0),
|
||||
Block::get(Block::SANDSTONE, 0),
|
||||
Block::get(Block::SANDSTONE, 0),
|
||||
Block::get(Block::SANDSTONE, 0),
|
||||
Block::get(Block::SANDSTONE, 0)
|
||||
]);
|
||||
}
|
||||
}
|
@ -33,7 +33,7 @@ abstract class SnowyBiome extends NormalBiome{
|
||||
Block::get(Block::GRASS, 0),
|
||||
Block::get(Block::DIRT, 0),
|
||||
Block::get(Block::DIRT, 0),
|
||||
Block::get(Block::DIRT, 0),
|
||||
Block::get(Block::DIRT, 0)
|
||||
]);
|
||||
}
|
||||
}
|
@ -45,7 +45,7 @@ class BigTree extends Tree{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function placeObject(ChunkManager $level, $x, $y, $z, Random $random){
|
||||
public function placeObject(ChunkManager $level, int $x, int $y, int $z, Random $random){
|
||||
|
||||
/*$this->trunkHeight = (int) ($this->totalHeight * $this->trunkHeightMultiplier);
|
||||
$leaves = $this->getLeafGroupPoints($level, $pos);
|
||||
|
@ -32,14 +32,14 @@ class BirchTree extends Tree{
|
||||
|
||||
protected $superBirch = false;
|
||||
|
||||
public function __construct($superBirch = false){
|
||||
public function __construct(bool $superBirch = false){
|
||||
$this->trunkBlock = Block::LOG;
|
||||
$this->leafBlock = Block::LEAVES;
|
||||
$this->type = Wood::BIRCH;
|
||||
$this->superBirch = (bool) $superBirch;
|
||||
$this->superBirch = $superBirch;
|
||||
}
|
||||
|
||||
public function placeObject(ChunkManager $level, $x, $y, $z, Random $random){
|
||||
public function placeObject(ChunkManager $level, int $x, int $y, int $z, Random $random){
|
||||
$this->treeHeight = $random->nextBoundedInt(3) + 5;
|
||||
if($this->superBirch){
|
||||
$this->treeHeight += 5;
|
||||
|
@ -36,7 +36,7 @@ class OakTree extends Tree{
|
||||
$this->type = Wood::OAK;
|
||||
}
|
||||
|
||||
public function placeObject(ChunkManager $level, $x, $y, $z, Random $random){
|
||||
public function placeObject(ChunkManager $level, int $x, int $y, int $z, Random $random){
|
||||
$this->treeHeight = $random->nextBoundedInt(3) + 4;
|
||||
parent::placeObject($level, $x, $y, $z, $random);
|
||||
}
|
||||
|
@ -23,12 +23,15 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\level\generator\object;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\level\ChunkManager;
|
||||
use pocketmine\math\VectorMath;
|
||||
use pocketmine\utils\Random;
|
||||
|
||||
class Ore{
|
||||
/** @var Random */
|
||||
private $random;
|
||||
/** @var OreType */
|
||||
public $type;
|
||||
|
||||
public function __construct(Random $random, OreType $type){
|
||||
@ -36,16 +39,16 @@ class Ore{
|
||||
$this->random = $random;
|
||||
}
|
||||
|
||||
public function getType(){
|
||||
public function getType() : OreType{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
public function canPlaceObject(ChunkManager $level, $x, $y, $z){
|
||||
return ($level->getBlockIdAt($x, $y, $z) === 1);
|
||||
public function canPlaceObject(ChunkManager $level, int $x, int $y, int $z) : bool{
|
||||
return $level->getBlockIdAt($x, $y, $z) === Block::STONE;
|
||||
}
|
||||
|
||||
public function placeObject(ChunkManager $level, $x, $y, $z){
|
||||
$clusterSize = (int) $this->type->clusterSize;
|
||||
public function placeObject(ChunkManager $level, int $x, int $y, int $z){
|
||||
$clusterSize = $this->type->clusterSize;
|
||||
$angle = $this->random->nextFloat() * M_PI;
|
||||
$offset = VectorMath::getDirection2D($angle)->multiply($clusterSize)->divide(8);
|
||||
$x1 = $x + 8 + $offset->x;
|
||||
|
@ -26,13 +26,22 @@ namespace pocketmine\level\generator\object;
|
||||
use pocketmine\block\Block;
|
||||
|
||||
class OreType{
|
||||
public $material, $clusterCount, $clusterSize, $maxHeight, $minHeight;
|
||||
/** @var Block */
|
||||
public $material;
|
||||
/** @var int */
|
||||
public $clusterCount;
|
||||
/** @var int */
|
||||
public $clusterSize;
|
||||
/** @var int */
|
||||
public $maxHeight;
|
||||
/** @var int */
|
||||
public $minHeight;
|
||||
|
||||
public function __construct(Block $material, $clusterCount, $clusterSize, $minHeight, $maxHeight){
|
||||
public function __construct(Block $material, int $clusterCount, int $clusterSize, int $minHeight, int $maxHeight){
|
||||
$this->material = $material;
|
||||
$this->clusterCount = (int) $clusterCount;
|
||||
$this->clusterSize = (int) $clusterSize;
|
||||
$this->maxHeight = (int) $maxHeight;
|
||||
$this->minHeight = (int) $minHeight;
|
||||
$this->clusterCount = $clusterCount;
|
||||
$this->clusterSize = $clusterSize;
|
||||
$this->maxHeight = $maxHeight;
|
||||
$this->minHeight = $minHeight;
|
||||
}
|
||||
}
|
@ -42,6 +42,7 @@ class Pond{
|
||||
}
|
||||
|
||||
public function placeObject(ChunkManager $level, Vector3 $pos){
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -37,7 +37,7 @@ class SpruceTree extends Tree{
|
||||
$this->treeHeight = 10;
|
||||
}
|
||||
|
||||
public function placeObject(ChunkManager $level, $x, $y, $z, Random $random){
|
||||
public function placeObject(ChunkManager $level, int $x, int $y, int $z, Random $random){
|
||||
$this->treeHeight = $random->nextBoundedInt(4) + 6;
|
||||
|
||||
$topSize = $this->treeHeight - (1 + $random->nextBoundedInt(2));
|
||||
|
@ -29,7 +29,8 @@ use pocketmine\math\Vector3;
|
||||
use pocketmine\utils\Random;
|
||||
|
||||
class TallGrass{
|
||||
public static function growGrass(ChunkManager $level, Vector3 $pos, Random $random, $count = 15, $radius = 10){
|
||||
|
||||
public static function growGrass(ChunkManager $level, Vector3 $pos, Random $random, int $count = 15, int $radius = 10){
|
||||
$arr = [
|
||||
[Block::DANDELION, 0],
|
||||
[Block::POPPY, 0],
|
||||
|
@ -44,7 +44,7 @@ abstract class Tree{
|
||||
public $leafBlock = Block::LEAVES;
|
||||
public $treeHeight = 7;
|
||||
|
||||
public static function growTree(ChunkManager $level, $x, $y, $z, Random $random, $type = 0){
|
||||
public static function growTree(ChunkManager $level, int $x, int $y, int $z, Random $random, int $type = 0){
|
||||
switch($type){
|
||||
case Sapling::SPRUCE:
|
||||
$tree = new SpruceTree();
|
||||
@ -78,7 +78,7 @@ abstract class Tree{
|
||||
public function canPlaceObject(ChunkManager $level, int $x, int $y, int $z, Random $random) : bool{
|
||||
$radiusToCheck = 0;
|
||||
for($yy = 0; $yy < $this->treeHeight + 3; ++$yy){
|
||||
if($yy == 1 or $yy === $this->treeHeight){
|
||||
if($yy === 1 or $yy === $this->treeHeight){
|
||||
++$radiusToCheck;
|
||||
}
|
||||
for($xx = -$radiusToCheck; $xx < ($radiusToCheck + 1); ++$xx){
|
||||
@ -93,7 +93,7 @@ abstract class Tree{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function placeObject(ChunkManager $level, $x, $y, $z, Random $random){
|
||||
public function placeObject(ChunkManager $level, int $x, int $y, int $z, Random $random){
|
||||
|
||||
$this->placeTrunk($level, $x, $y, $z, $random, $this->treeHeight - 1);
|
||||
|
||||
@ -116,7 +116,7 @@ abstract class Tree{
|
||||
}
|
||||
}
|
||||
|
||||
protected function placeTrunk(ChunkManager $level, $x, $y, $z, Random $random, $trunkHeight){
|
||||
protected function placeTrunk(ChunkManager $level, int $x, int $y, int $z, Random $random, int $trunkHeight){
|
||||
// The base dirt block
|
||||
$level->setBlockIdAt($x, $y - 1, $z, Block::DIRT);
|
||||
|
||||
|
@ -30,7 +30,7 @@ use pocketmine\utils\Random;
|
||||
|
||||
class GroundCover extends Populator{
|
||||
|
||||
public function populate(ChunkManager $level, $chunkX, $chunkZ, Random $random){
|
||||
public function populate(ChunkManager $level, int $chunkX, int $chunkZ, Random $random){
|
||||
$chunk = $level->getChunk($chunkX, $chunkZ);
|
||||
for($x = 0; $x < 16; ++$x){
|
||||
for($z = 0; $z < 16; ++$z){
|
||||
|
@ -33,7 +33,7 @@ class Mineshaft extends Populator{
|
||||
private static $BASE_Y = 35;
|
||||
private static $RAND_Y = 11;
|
||||
|
||||
public function populate(ChunkManager $level, $chunkX, $chunkZ, Random $random){
|
||||
public function populate(ChunkManager $level, int $chunkX, int $chunkZ, Random $random){
|
||||
if($random->nextRange(0, self::$ODD) === 0){
|
||||
//$mineshaft = new Mineshaft($random);
|
||||
}
|
||||
|
@ -25,12 +25,14 @@ namespace pocketmine\level\generator\populator;
|
||||
|
||||
use pocketmine\level\ChunkManager;
|
||||
use pocketmine\level\generator\object\Ore as ObjectOre;
|
||||
use pocketmine\level\generator\object\OreType;
|
||||
use pocketmine\utils\Random;
|
||||
|
||||
class Ore extends Populator{
|
||||
/** @var OreType[] */
|
||||
private $oreTypes = [];
|
||||
|
||||
public function populate(ChunkManager $level, $chunkX, $chunkZ, Random $random){
|
||||
public function populate(ChunkManager $level, int $chunkX, int $chunkZ, Random $random){
|
||||
foreach($this->oreTypes as $type){
|
||||
$ore = new ObjectOre($random, $type);
|
||||
for($i = 0; $i < $ore->type->clusterCount; ++$i){
|
||||
@ -44,6 +46,9 @@ class Ore extends Populator{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param OreType[] $types
|
||||
*/
|
||||
public function setOreTypes(array $types){
|
||||
$this->oreTypes = $types;
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ class Pond extends Populator{
|
||||
private $lavaOdd = 4;
|
||||
private $lavaSurfaceOdd = 4;
|
||||
|
||||
public function populate(ChunkManager $level, $chunkX, $chunkZ, Random $random){
|
||||
public function populate(ChunkManager $level, int $chunkX, int $chunkZ, Random $random){
|
||||
if($random->nextRange(0, $this->waterOdd) === 0){
|
||||
$x = $random->nextRange($chunkX << 4, ($chunkX << 4) + 16);
|
||||
$y = $random->nextBoundedInt(128);
|
||||
@ -45,15 +45,15 @@ class Pond extends Populator{
|
||||
}
|
||||
}
|
||||
|
||||
public function setWaterOdd($waterOdd){
|
||||
public function setWaterOdd(int $waterOdd){
|
||||
$this->waterOdd = $waterOdd;
|
||||
}
|
||||
|
||||
public function setLavaOdd($lavaOdd){
|
||||
public function setLavaOdd(int $lavaOdd){
|
||||
$this->lavaOdd = $lavaOdd;
|
||||
}
|
||||
|
||||
public function setLavaSurfaceOdd($lavaSurfaceOdd){
|
||||
public function setLavaSurfaceOdd(int $lavaSurfaceOdd){
|
||||
$this->lavaSurfaceOdd = $lavaSurfaceOdd;
|
||||
}
|
||||
}
|
@ -30,5 +30,14 @@ use pocketmine\level\ChunkManager;
|
||||
use pocketmine\utils\Random;
|
||||
|
||||
abstract class Populator{
|
||||
abstract public function populate(ChunkManager $level, $chunkX, $chunkZ, Random $random);
|
||||
|
||||
/**
|
||||
* @param ChunkManager $level
|
||||
* @param int $chunkX
|
||||
* @param int $chunkZ
|
||||
* @param Random $random
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function populate(ChunkManager $level, int $chunkX, int $chunkZ, Random $random);
|
||||
}
|
@ -41,7 +41,7 @@ class TallGrass extends Populator{
|
||||
$this->baseAmount = $amount;
|
||||
}
|
||||
|
||||
public function populate(ChunkManager $level, $chunkX, $chunkZ, Random $random){
|
||||
public function populate(ChunkManager $level, int $chunkX, int $chunkZ, Random $random){
|
||||
$this->level = $level;
|
||||
$amount = $random->nextRange(0, $this->randomAmount + 1) + $this->baseAmount;
|
||||
for($i = 0; $i < $amount; ++$i){
|
||||
|
@ -49,7 +49,7 @@ class Tree extends Populator{
|
||||
$this->baseAmount = $amount;
|
||||
}
|
||||
|
||||
public function populate(ChunkManager $level, $chunkX, $chunkZ, Random $random){
|
||||
public function populate(ChunkManager $level, int $chunkX, int $chunkZ, Random $random){
|
||||
$this->level = $level;
|
||||
$amount = $random->nextRange(0, $this->randomAmount + 1) + $this->baseAmount;
|
||||
for($i = 0; $i < $amount; ++$i){
|
||||
|
Reference in New Issue
Block a user