mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 01:46:04 +00:00
and more typehints
This commit is contained in:
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
||||
|
@ -27,7 +27,7 @@ use pocketmine\level\generator\biome\Biome;
|
||||
|
||||
class HellBiome extends Biome{
|
||||
|
||||
public function getName(){
|
||||
public function getName() : string{
|
||||
return "Hell";
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ class DesertBiome extends SandyBiome{
|
||||
$this->rainfall = 0;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
public function getName() : string{
|
||||
return "Desert";
|
||||
}
|
||||
}
|
@ -59,7 +59,7 @@ class ForestBiome extends GrassyBiome{
|
||||
}
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
public function getName() : string{
|
||||
return $this->type === self::TYPE_BIRCH ? "Birch Forest" : "Forest";
|
||||
}
|
||||
}
|
@ -41,7 +41,7 @@ class IcePlainsBiome extends SnowyBiome{
|
||||
$this->rainfall = 0.8;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
public function getName() : string{
|
||||
return "Ice Plains";
|
||||
}
|
||||
}
|
@ -48,7 +48,7 @@ class MountainsBiome extends GrassyBiome{
|
||||
$this->rainfall = 0.5;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
public function getName() : string{
|
||||
return "Mountains";
|
||||
}
|
||||
}
|
@ -41,7 +41,7 @@ class OceanBiome extends GrassyBiome{
|
||||
$this->rainfall = 0.5;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
public function getName() : string{
|
||||
return "Ocean";
|
||||
}
|
||||
}
|
@ -41,7 +41,7 @@ class PlainBiome extends GrassyBiome{
|
||||
$this->rainfall = 0.4;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
public function getName() : string{
|
||||
return "Plains";
|
||||
}
|
||||
}
|
@ -41,7 +41,7 @@ class RiverBiome extends GrassyBiome{
|
||||
$this->rainfall = 0.7;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
public function getName() : string{
|
||||
return "River";
|
||||
}
|
||||
}
|
@ -32,7 +32,7 @@ class SmallMountainsBiome extends MountainsBiome{
|
||||
$this->setElevation(63, 97);
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
public function getName() : string{
|
||||
return "Small Mountains";
|
||||
}
|
||||
}
|
@ -34,7 +34,7 @@ class SwampBiome extends GrassyBiome{
|
||||
$this->rainfall = 0.9;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
public function getName() : string{
|
||||
return "Swamp";
|
||||
}
|
||||
}
|
@ -47,7 +47,7 @@ class TaigaBiome extends SnowyBiome{
|
||||
$this->rainfall = 0.8;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
public function getName() : string{
|
||||
return "Taiga";
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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){
|
||||
|
Reference in New Issue
Block a user