Merge branch 'moar-typehints'

This commit is contained in:
Dylan K. Taylor
2017-07-15 09:43:43 +01:00
176 changed files with 879 additions and 741 deletions

View File

@ -45,14 +45,14 @@ interface ChunkLoader{
*
* @return int
*/
public function getLoaderId();
public function getLoaderId() : int;
/**
* Returns if the chunk loader is currently active
*
* @return bool
*/
public function isLoaderActive();
public function isLoaderActive() : bool;
/**
* @return Position

View File

@ -130,7 +130,7 @@ interface ChunkManager{
*
* @return int
*/
public function getSeed();
public function getSeed() : int;
/**
* Returns the height of the world

View File

@ -63,7 +63,7 @@ class Explosion{
/**
* @return bool
*/
public function explodeA(){
public function explodeA() : bool{
if($this->size < 0.1){
return false;
}
@ -114,7 +114,7 @@ class Explosion{
return true;
}
public function explodeB(){
public function explodeB() : bool{
$send = [];
$updateBlocks = [];

View File

@ -173,7 +173,7 @@ class Level implements ChunkManager, Metadatable{
/** @var Player[][] */
private $playerLoaders = [];
/** @var DataPacket[] */
/** @var DataPacket[][] */
private $chunkPackets = [];
/** @var float[] */
@ -292,7 +292,7 @@ class Level implements ChunkManager, Metadatable{
}
public static function generateChunkLoaderId(ChunkLoader $loader) : int{
if($loader->getLoaderId() === 0 or $loader->getLoaderId() === null){
if($loader->getLoaderId() === 0){
return self::$chunkLoaderCounter++;
}else{
throw new \InvalidStateException("ChunkLoader has a loader id already assigned: " . $loader->getLoaderId());
@ -2774,9 +2774,9 @@ class Level implements ChunkManager, Metadatable{
/**
* Gets the level seed
*
* @return int|string int value of seed, or the string numeric representation of a long in 32-bit systems
* @return int
*/
public function getSeed(){
public function getSeed() : int{
return $this->provider->getSeed();
}

View File

@ -55,7 +55,7 @@ class Location extends Position{
*
* @return Location
*/
public static function fromObject(Vector3 $pos, Level $level = null, $yaw = 0.0, $pitch = 0.0){
public static function fromObject(Vector3 $pos, Level $level = null, $yaw = 0.0, $pitch = 0.0) : Location{
return new Location($pos->x, $pos->y, $pos->z, $yaw, $pitch, $level ?? (($pos instanceof Position) ? $pos->level : null));
}
@ -80,7 +80,7 @@ class Location extends Position{
return "Location (level=" . ($this->isValid() ? $this->getLevel()->getName() : "null") . ", x=$this->x, y=$this->y, z=$this->z, yaw=$this->yaw, pitch=$this->pitch)";
}
public function equals(Vector3 $v){
public function equals(Vector3 $v) : bool{
if($v instanceof Location){
return parent::equals($v) and $v->yaw == $this->yaw and $v->pitch == $this->pitch;
}

View File

@ -52,15 +52,15 @@ class MovingObjectPosition{
}
/**
* @param int $x
* @param int $y
* @param int $z
* @param int $side
* @param int $x
* @param int $y
* @param int $z
* @param int $side
* @param Vector3 $hitVector
*
* @return MovingObjectPosition
*/
public static function fromBlock($x, $y, $z, $side, Vector3 $hitVector){
public static function fromBlock(int $x, int $y, int $z, int $side, Vector3 $hitVector) : MovingObjectPosition{
$ob = new MovingObjectPosition;
$ob->typeOfHit = 0;
$ob->blockX = $x;
@ -75,7 +75,7 @@ class MovingObjectPosition{
*
* @return MovingObjectPosition
*/
public static function fromEntity(Entity $entity){
public static function fromEntity(Entity $entity) : MovingObjectPosition{
$ob = new MovingObjectPosition;
$ob->typeOfHit = 1;
$ob->entityHit = $entity;

View File

@ -95,7 +95,7 @@ class Position extends Vector3{
*
* @return bool
*/
public function isValid(){
public function isValid() : bool{
return $this->getLevel() instanceof Level;
}
@ -133,7 +133,7 @@ class Position extends Vector3{
return $this;
}
public function equals(Vector3 $v){
public function equals(Vector3 $v) : bool{
if($v instanceof Position){
return parent::equals($v) and $v->getLevel() === $this->getLevel();
}

View File

@ -164,7 +164,7 @@ class SimpleChunkManager implements ChunkManager{
*
* @return int
*/
public function getSeed(){
public function getSeed() : int{
return $this->seed;
}

View File

@ -28,7 +28,6 @@ namespace pocketmine\level\format;
use pocketmine\block\Block;
use pocketmine\entity\Entity;
use pocketmine\level\format\ChunkException;
use pocketmine\level\Level;
use pocketmine\nbt\NBT;
use pocketmine\nbt\tag\CompoundTag;
@ -989,7 +988,7 @@ class Chunk{
*
* @return Chunk
*/
public static function fastDeserialize(string $data){
public static function fastDeserialize(string $data) : Chunk{
$stream = new BinaryStream();
$stream->setBuffer($data);
$data = null;

View File

@ -76,7 +76,7 @@ abstract class BaseLevelProvider implements LevelProvider{
return $this->level->getServer();
}
public function getLevel(){
public function getLevel() : Level{
return $this->level;
}

View File

@ -174,7 +174,7 @@ interface LevelProvider{
/**
* @return string
*/
public function getName();
public function getName() : string;
/**
* @return int|string int, or the string numeric representation of a long in 32-bit systems
@ -216,7 +216,7 @@ interface LevelProvider{
/**
* @return Level
*/
public function getLevel();
public function getLevel() : Level;
public function close();

View File

@ -25,7 +25,6 @@ namespace pocketmine\level\format\io\leveldb;
use pocketmine\entity\Entity;
use pocketmine\level\format\Chunk;
use pocketmine\level\format\ChunkException;
use pocketmine\level\format\io\BaseLevelProvider;
use pocketmine\level\format\io\ChunkUtils;
use pocketmine\level\format\io\exception\UnsupportedChunkFormatException;
@ -576,7 +575,7 @@ class LevelDB extends BaseLevelProvider{
/**
* @return \LevelDB
*/
public function getDatabase(){
public function getDatabase() : \LevelDB{
return $this->db;
}

View File

@ -422,7 +422,7 @@ class McRegion extends BaseLevelProvider{
*
* @return Chunk
*/
public function getEmptyChunk(int $chunkX, int $chunkZ){
public function getEmptyChunk(int $chunkX, int $chunkZ) : Chunk{
return Chunk::getEmptyChunk($chunkX, $chunkZ);
}

View File

@ -50,11 +50,11 @@ class Flat extends Generator{
private $populators = [];
private $structure, $chunks, $options, $floorLevel, $preset;
public function getSettings(){
public function getSettings() : array{
return $this->options;
}
public function getName(){
public function getName() : string{
return "flat";
}
@ -155,7 +155,7 @@ class Flat extends Generator{
*/
}
public function generateChunk($chunkX, $chunkZ){
public function generateChunk(int $chunkX, int $chunkZ){
if($this->chunk === null){
if(isset($this->options["preset"]) and $this->options["preset"] != ""){
$this->parsePreset($this->options["preset"], $chunkX, $chunkZ);
@ -169,7 +169,7 @@ class Flat extends Generator{
$this->level->setChunk($chunkX, $chunkZ, $chunk);
}
public function populateChunk($chunkX, $chunkZ){
public function populateChunk(int $chunkX, int $chunkZ){
$this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed());
foreach($this->populators as $populator){
$populator->populate($this->level, $chunkX, $chunkZ, $this->random);
@ -177,7 +177,7 @@ class Flat extends Generator{
}
public function getSpawn(){
public function getSpawn() : Vector3{
return new Vector3(128, $this->floorLevel, 128);
}
}

View File

@ -29,12 +29,13 @@ namespace pocketmine\level\generator;
use pocketmine\level\ChunkManager;
use pocketmine\level\generator\noise\Noise;
use pocketmine\level\generator\normal\Normal;
use pocketmine\math\Vector3;
use pocketmine\utils\Random;
abstract class Generator{
private static $list = [];
public static function addGenerator($object, $name){
public static function addGenerator($object, $name) : bool{
if(is_subclass_of($object, Generator::class) and !isset(Generator::$list[$name = strtolower($name)])){
Generator::$list[$name] = $object;
@ -47,7 +48,7 @@ abstract class Generator{
/**
* @return string[]
*/
public static function getGeneratorList(){
public static function getGeneratorList() : array{
return array_keys(Generator::$list);
}
@ -76,17 +77,15 @@ abstract class Generator{
/**
* @param Noise $noise
* @param int $xSize
* @param int $samplingRate
* @param int $x
* @param int $y
* @param int $z
* @param int $xSize
* @param int $samplingRate
* @param int $x
* @param int $y
* @param int $z
*
* @return \SplFixedArray
*
* @throws \InvalidArgumentCountException
*/
public static function getFastNoise1D(Noise $noise, $xSize, $samplingRate, $x, $y, $z){
public static function getFastNoise1D(Noise $noise, int $xSize, int $samplingRate, int $x, int $y, int $z) : \SplFixedArray{
if($samplingRate === 0){
throw new \InvalidArgumentException("samplingRate cannot be 0");
}
@ -112,19 +111,16 @@ abstract class Generator{
/**
* @param Noise $noise
* @param int $xSize
* @param int $zSize
* @param int $samplingRate
* @param int $x
* @param int $y
* @param int $z
* @param int $xSize
* @param int $zSize
* @param int $samplingRate
* @param int $x
* @param int $y
* @param int $z
*
* @return \SplFixedArray
*
* @throws \InvalidArgumentException
* @throws \InvalidArgumentCountException
*/
public static function getFastNoise2D(Noise $noise, $xSize, $zSize, $samplingRate, $x, $y, $z){
public static function getFastNoise2D(Noise $noise, int $xSize, int $zSize, int $samplingRate, int $x, int $y, int $z) : \SplFixedArray{
assert($samplingRate !== 0, new \InvalidArgumentException("samplingRate cannot be 0"));
assert($xSize % $samplingRate === 0, new \InvalidArgumentCountException("xSize % samplingRate must return 0"));
@ -162,22 +158,19 @@ abstract class Generator{
/**
* @param Noise $noise
* @param int $xSize
* @param int $ySize
* @param int $zSize
* @param int $xSamplingRate
* @param int $ySamplingRate
* @param int $zSamplingRate
* @param int $x
* @param int $y
* @param int $z
* @param int $xSize
* @param int $ySize
* @param int $zSize
* @param int $xSamplingRate
* @param int $ySamplingRate
* @param int $zSamplingRate
* @param int $x
* @param int $y
* @param int $z
*
* @return \SplFixedArray
*
* @throws \InvalidArgumentException
* @throws \InvalidArgumentCountException
* @return array
*/
public static function getFastNoise3D(Noise $noise, $xSize, $ySize, $zSize, $xSamplingRate, $ySamplingRate, $zSamplingRate, $x, $y, $z){
public static function getFastNoise3D(Noise $noise, int $xSize, int $ySize, int $zSize, int $xSamplingRate, int $ySamplingRate, int $zSamplingRate, int $x, int $y, int $z) : array{
assert($xSamplingRate !== 0, new \InvalidArgumentException("xSamplingRate cannot be 0"));
assert($zSamplingRate !== 0, new \InvalidArgumentException("zSamplingRate cannot be 0"));
@ -239,13 +232,13 @@ abstract class Generator{
abstract public function init(ChunkManager $level, Random $random);
abstract public function generateChunk($chunkX, $chunkZ);
abstract public function generateChunk(int $chunkX, int $chunkZ);
abstract public function populateChunk($chunkX, $chunkZ);
abstract public function populateChunk(int $chunkX, int $chunkZ);
abstract public function getSettings();
abstract public function getSettings() : array;
abstract public function getName();
abstract public function getName() : string;
abstract public function getSpawn();
abstract public function getSpawn() : Vector3;
}

View File

@ -70,7 +70,9 @@ abstract class Biome{
/** @var Populator[] */
private $populators = [];
/** @var int */
private $minElevation;
/** @var int */
private $maxElevation;
private $groundCover = [];
@ -78,9 +80,9 @@ abstract class Biome{
protected $rainfall = 0.5;
protected $temperature = 0.5;
protected static function register($id, Biome $biome){
self::$biomes[(int) $id] = $biome;
$biome->setId((int) $id);
protected static function register(int $id, Biome $biome){
self::$biomes[$id] = $biome;
$biome->setId($id);
}
public static function init(){
@ -102,11 +104,11 @@ abstract class Biome{
}
/**
* @param $id
* @param int $id
*
* @return Biome
*/
public static function getBiome($id){
public static function getBiome(int $id) : Biome{
return self::$biomes[$id] ?? self::$biomes[self::OCEAN];
}
@ -118,38 +120,47 @@ abstract class Biome{
$this->populators[] = $populator;
}
public function populateChunk(ChunkManager $level, $chunkX, $chunkZ, Random $random){
/**
* @param ChunkManager $level
* @param int $chunkX
* @param int $chunkZ
* @param Random $random
*/
public function populateChunk(ChunkManager $level, int $chunkX, int $chunkZ, Random $random){
foreach($this->populators as $populator){
$populator->populate($level, $chunkX, $chunkZ, $random);
}
}
public function getPopulators(){
/**
* @return Populator[]
*/
public function getPopulators() : array{
return $this->populators;
}
public function setId($id){
public function setId(int $id){
if(!$this->registered){
$this->registered = true;
$this->id = $id;
}
}
public function getId(){
public function getId() : int{
return $this->id;
}
abstract public function getName();
abstract public function getName() : string;
public function getMinElevation(){
public function getMinElevation() : int{
return $this->minElevation;
}
public function getMaxElevation(){
public function getMaxElevation() : int{
return $this->maxElevation;
}
public function setElevation($min, $max){
public function setElevation(int $min, int $max){
$this->minElevation = $min;
$this->maxElevation = $max;
}
@ -157,7 +168,7 @@ abstract class Biome{
/**
* @return Block[]
*/
public function getGroundCover(){
public function getGroundCover() : array{
return $this->groundCover;
}
@ -168,11 +179,11 @@ abstract class Biome{
$this->groundCover = $covers;
}
public function getTemperature(){
public function getTemperature() : float{
return $this->temperature;
}
public function getRainfall(){
public function getRainfall() : float{
return $this->rainfall;
}
}

View File

@ -78,7 +78,7 @@ class BiomeSelector{
*
* @return Biome
*/
public function pickBiome($x, $z){
public function pickBiome($x, $z) : Biome{
$temperature = (int) ($this->getTemperature($x, $z) * 63);
$rainfall = (int) ($this->getRainfall($x, $z) * 63);

View File

@ -27,7 +27,7 @@ use pocketmine\level\generator\biome\Biome;
class HellBiome extends Biome{
public function getName(){
public function getName() : string{
return "Hell";
}
}

View File

@ -81,11 +81,11 @@ class Nether extends Generator{
}
}
public function getName(){
public function getName() : string{
return "nether";
}
public function getSettings(){
public function getSettings() : array{
return [];
}
@ -110,7 +110,7 @@ class Nether extends Generator{
$this->populators[] = $ores;*/
}
public function generateChunk($chunkX, $chunkZ){
public function generateChunk(int $chunkX, int $chunkZ){
$this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed());
$noise = Generator::getFastNoise3D($this->noiseBase, 16, 128, 16, 4, 8, 4, $chunkX * 16, 0, $chunkZ * 16);
@ -145,7 +145,7 @@ class Nether extends Generator{
}
}
public function populateChunk($chunkX, $chunkZ){
public function populateChunk(int $chunkX, int $chunkZ){
$this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed());
foreach($this->populators as $populator){
$populator->populate($this->level, $chunkX, $chunkZ, $this->random);
@ -156,7 +156,7 @@ class Nether extends Generator{
$biome->populateChunk($this->level, $chunkX, $chunkZ, $this->random);
}
public function getSpawn(){
public function getSpawn() : Vector3{
return new Vector3(127.5, 128, 127.5);
}

View File

@ -36,7 +36,7 @@ abstract class Noise{
protected $persistence;
protected $expansion;
public static function floor($x){
public static function floor($x) : int{
return $x >= 0 ? (int) $x : (int) ($x - 1);
}

View File

@ -90,15 +90,15 @@ class Normal extends Generator{
}
}
public function getName(){
public function getName() : string{
return "normal";
}
public function getSettings(){
public function getSettings() : array{
return [];
}
public function pickBiome($x, $z){
public function pickBiome(int $x, int $z){
$hash = $x * 2345803 ^ $z * 9236449 ^ $this->level->getSeed();
$hash *= $hash + 223;
$xNoise = $hash >> 20 & 3;
@ -189,7 +189,7 @@ class Normal extends Generator{
$this->populators[] = $ores;
}
public function generateChunk($chunkX, $chunkZ){
public function generateChunk(int $chunkX, int $chunkZ){
$this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed());
$noise = Generator::getFastNoise3D($this->noiseBase, 16, 128, 16, 4, 8, 4, $chunkX * 16, 0, $chunkZ * 16);
@ -256,7 +256,7 @@ class Normal extends Generator{
}
}
public function populateChunk($chunkX, $chunkZ){
public function populateChunk(int $chunkX, int $chunkZ){
$this->random->setSeed(0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed());
foreach($this->populators as $populator){
$populator->populate($this->level, $chunkX, $chunkZ, $this->random);
@ -267,7 +267,7 @@ class Normal extends Generator{
$biome->populateChunk($this->level, $chunkX, $chunkZ, $this->random);
}
public function getSpawn(){
public function getSpawn() : Vector3{
return new Vector3(127.5, 128, 127.5);
}

View File

@ -34,7 +34,7 @@ class DesertBiome extends SandyBiome{
$this->rainfall = 0;
}
public function getName(){
public function getName() : string{
return "Desert";
}
}

View File

@ -59,7 +59,7 @@ class ForestBiome extends GrassyBiome{
}
}
public function getName(){
public function getName() : string{
return $this->type === self::TYPE_BIRCH ? "Birch Forest" : "Forest";
}
}

View File

@ -41,7 +41,7 @@ class IcePlainsBiome extends SnowyBiome{
$this->rainfall = 0.8;
}
public function getName(){
public function getName() : string{
return "Ice Plains";
}
}

View File

@ -48,7 +48,7 @@ class MountainsBiome extends GrassyBiome{
$this->rainfall = 0.5;
}
public function getName(){
public function getName() : string{
return "Mountains";
}
}

View File

@ -41,7 +41,7 @@ class OceanBiome extends GrassyBiome{
$this->rainfall = 0.5;
}
public function getName(){
public function getName() : string{
return "Ocean";
}
}

View File

@ -41,7 +41,7 @@ class PlainBiome extends GrassyBiome{
$this->rainfall = 0.4;
}
public function getName(){
public function getName() : string{
return "Plains";
}
}

View File

@ -41,7 +41,7 @@ class RiverBiome extends GrassyBiome{
$this->rainfall = 0.7;
}
public function getName(){
public function getName() : string{
return "River";
}
}

View File

@ -32,7 +32,7 @@ class SmallMountainsBiome extends MountainsBiome{
$this->setElevation(63, 97);
}
public function getName(){
public function getName() : string{
return "Small Mountains";
}
}

View File

@ -34,7 +34,7 @@ class SwampBiome extends GrassyBiome{
$this->rainfall = 0.9;
}
public function getName(){
public function getName() : string{
return "Swamp";
}
}

View File

@ -47,7 +47,7 @@ class TaigaBiome extends SnowyBiome{
$this->rainfall = 0.8;
}
public function getName(){
public function getName() : string{
return "Taiga";
}
}

View File

@ -41,7 +41,7 @@ class BigTree extends Tree{
private $addLogVines = false;
private $addCocoaPlants = false;
public function canPlaceObject(ChunkManager $level, $x, $y, $z, Random $random){
public function canPlaceObject(ChunkManager $level, int $x, int $y, int $z, Random $random) : bool{
return false;
}

View File

@ -37,7 +37,7 @@ class Pond{
$this->random = $random;
}
public function canPlaceObject(ChunkManager $level, Vector3 $pos){
public function canPlaceObject(ChunkManager $level, Vector3 $pos) : bool{
return false;
}

View File

@ -75,7 +75,7 @@ abstract class Tree{
}
public function canPlaceObject(ChunkManager $level, $x, $y, $z, Random $random){
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){