More typehints, documentation fixes and static analysis cleanup

This commit is contained in:
Dylan K. Taylor
2017-07-15 12:12:06 +01:00
parent 24bdf330d5
commit dbb92096e4
66 changed files with 309 additions and 219 deletions

View File

@ -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()];
}

View File

@ -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){

View File

@ -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){

View File

@ -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[] */

View File

@ -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[] */

View File

@ -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;

View File

@ -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)
]);
}
}

View File

@ -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)
]);
}
}

View File

@ -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);

View File

@ -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;

View File

@ -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);
}

View File

@ -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;

View File

@ -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;
}
}

View File

@ -42,6 +42,7 @@ class Pond{
}
public function placeObject(ChunkManager $level, Vector3 $pos){
}
}

View File

@ -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));

View File

@ -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],

View File

@ -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);

View File

@ -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){

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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);
}

View File

@ -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){

View File

@ -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){