diff --git a/src/world/BlockTransaction.php b/src/world/BlockTransaction.php index 80bf8445f..b685d2443 100644 --- a/src/world/BlockTransaction.php +++ b/src/world/BlockTransaction.php @@ -28,20 +28,16 @@ use pocketmine\math\Vector3; use pocketmine\utils\Utils; class BlockTransaction{ - /** @var ChunkManager */ - private $world; - /** @var Block[][][] */ - private $blocks = []; + private array $blocks = []; /** * @var \Closure[] * @phpstan-var (\Closure(ChunkManager $world, int $x, int $y, int $z) : bool)[] */ - private $validators = []; + private array $validators = []; - public function __construct(ChunkManager $world){ - $this->world = $world; + public function __construct(private ChunkManager $world){ $this->addValidator(static function(ChunkManager $world, int $x, int $y, int $z) : bool{ return $world->isInWorld($x, $y, $z); }); diff --git a/src/world/Explosion.php b/src/world/Explosion.php index f67d9034f..bad73a4aa 100644 --- a/src/world/Explosion.php +++ b/src/world/Explosion.php @@ -46,8 +46,7 @@ use function mt_rand; use function sqrt; class Explosion{ - /** @var int */ - private $rays = 16; + private int $rays = 16; /** @var World */ public $world; /** @var Position */ @@ -59,16 +58,12 @@ class Explosion{ public $affectedBlocks = []; /** @var float */ public $stepLen = 0.3; - /** @var Entity|Block|null */ - private $what; - /** @var SubChunkExplorer */ - private $subChunkExplorer; + private Entity|Block|null $what; - /** - * @param Entity|Block|null $what - */ - public function __construct(Position $center, float $size, $what = null){ + private SubChunkExplorer $subChunkExplorer; + + public function __construct(Position $center, float $size, Entity|Block|null $what = null){ if(!$center->isValid()){ throw new \InvalidArgumentException("Position does not have a valid world"); } diff --git a/src/world/SimpleChunkManager.php b/src/world/SimpleChunkManager.php index 1b2605f33..a56095a17 100644 --- a/src/world/SimpleChunkManager.php +++ b/src/world/SimpleChunkManager.php @@ -34,15 +34,10 @@ class SimpleChunkManager implements ChunkManager{ /** @var Chunk[] */ protected $chunks = []; - /** @var int */ - private $minY; - /** @var int */ - private $maxY; - - public function __construct(int $minY, int $maxY){ - $this->minY = $minY; - $this->maxY = $maxY; - } + public function __construct( + private int $minY, + private int $maxY + ){} public function getBlockAt(int $x, int $y, int $z) : Block{ if($this->isInWorld($x, $y, $z) && ($chunk = $this->getChunk($x >> Chunk::COORD_BIT_SIZE, $z >> Chunk::COORD_BIT_SIZE)) !== null){ diff --git a/src/world/World.php b/src/world/World.php index 6c2a6a9e5..089b24bf4 100644 --- a/src/world/World.php +++ b/src/world/World.php @@ -131,8 +131,7 @@ use const PHP_INT_MIN; class World implements ChunkManager{ - /** @var int */ - private static $worldIdCounter = 1; + private static int $worldIdCounter = 1; public const Y_MAX = 256; public const Y_MIN = 0; @@ -154,15 +153,15 @@ class World implements ChunkManager{ public const DEFAULT_TICKED_BLOCKS_PER_SUBCHUNK_PER_TICK = 3; /** @var Player[] */ - private $players = []; + private array $players = []; /** @var Entity[] */ - private $entities = []; + private array $entities = []; /** * @var Vector3[] * @phpstan-var array */ - private $entityLastKnownPositions = []; + private array $entityLastKnownPositions = []; /** * @var Entity[][] @@ -173,88 +172,66 @@ class World implements ChunkManager{ /** @var Entity[] */ public $updateEntities = []; /** @var Block[][] */ - private $blockCache = []; + private array $blockCache = []; - /** @var int */ - private $sendTimeTicker = 0; + private int $sendTimeTicker = 0; - /** @var Server */ - private $server; + private int $worldId; - /** @var int */ - private $worldId; + private int $providerGarbageCollectionTicker = 0; - /** @var WritableWorldProvider */ - private $provider; - /** @var int */ - private $providerGarbageCollectionTicker = 0; - - /** @var int */ - private $minY; - /** @var int */ - private $maxY; + private int $minY; + private int $maxY; /** @var TickingChunkLoader[] */ - private $tickingLoaders = []; + private array $tickingLoaders = []; /** @var int[] */ - private $tickingLoaderCounter = []; + private array $tickingLoaderCounter = []; /** @var ChunkLoader[][] */ - private $chunkLoaders = []; + private array $chunkLoaders = []; /** @var ChunkListener[][] */ - private $chunkListeners = []; + private array $chunkListeners = []; /** @var Player[][] */ - private $playerChunkListeners = []; + private array $playerChunkListeners = []; /** @var ClientboundPacket[][] */ - private $packetBuffersByChunk = []; + private array $packetBuffersByChunk = []; /** @var float[] */ - private $unloadQueue = []; + private array $unloadQueue = []; - /** @var int */ - private $time; + private int $time; /** @var bool */ public $stopTime = false; - /** @var float */ - private $sunAnglePercentage = 0.0; - /** @var int */ - private $skyLightReduction = 0; + private float $sunAnglePercentage = 0.0; + private int $skyLightReduction = 0; - /** @var string */ - private $folderName; - /** @var string */ - private $displayName; + private string $folderName; + private string $displayName; /** @var Chunk[] */ - private $chunks = []; + private array $chunks = []; /** @var Vector3[][] */ - private $changedBlocks = []; + private array $changedBlocks = []; - /** - * @var ReversePriorityQueue - * @phpstan-var ReversePriorityQueue - */ - private $scheduledBlockUpdateQueue; + /** @phpstan-var ReversePriorityQueue */ + private ReversePriorityQueue $scheduledBlockUpdateQueue; /** @var int[] */ - private $scheduledBlockUpdateQueueIndex = []; + private array $scheduledBlockUpdateQueueIndex = []; - /** - * @var \SplQueue - * @phpstan-var \SplQueue - */ - private $neighbourBlockUpdateQueue; + /** @phpstan-var \SplQueue */ + private \SplQueue $neighbourBlockUpdateQueue; /** @var bool[] blockhash => dummy */ - private $neighbourBlockUpdateQueueIndex = []; + private array $neighbourBlockUpdateQueueIndex = []; /** @var bool[] */ - private $activeChunkPopulationTasks = []; + private array $activeChunkPopulationTasks = []; /** @var ChunkLockId[] */ - private $chunkLock = []; - /** @var int */ - private $maxConcurrentChunkPopulationTasks = 2; + private array $chunkLock = []; + private int $maxConcurrentChunkPopulationTasks = 2; /** * @var PromiseResolver[] chunkHash => promise * @phpstan-var array> @@ -272,22 +249,17 @@ class World implements ChunkManager{ private array $chunkPopulationRequestQueueIndex = []; /** @var bool[] */ - private $generatorRegisteredWorkers = []; + private array $generatorRegisteredWorkers = []; - /** @var bool */ - private $autoSave = true; + private bool $autoSave = true; - /** @var int */ - private $sleepTicks = 0; + private int $sleepTicks = 0; - /** @var int */ - private $chunkTickRadius; - /** @var int */ - private $chunksPerTick; - /** @var int */ - private $tickedBlocksPerSubchunkPerTick = self::DEFAULT_TICKED_BLOCKS_PER_SUBCHUNK_PER_TICK; + private int $chunkTickRadius; + private int $chunksPerTick; + private int $tickedBlocksPerSubchunkPerTick = self::DEFAULT_TICKED_BLOCKS_PER_SUBCHUNK_PER_TICK; /** @var bool[] */ - private $randomTickBlocks = []; + private array $randomTickBlocks = []; /** @var WorldTimings */ public $timings; @@ -295,33 +267,22 @@ class World implements ChunkManager{ /** @var float */ public $tickRateTime = 0; - /** @var bool */ - private $doingTick = false; + private bool $doingTick = false; - /** - * @var string - * @phpstan-var class-string<\pocketmine\world\generator\Generator> - */ - private $generator; + /** @phpstan-var class-string<\pocketmine\world\generator\Generator> */ + private string $generator; - /** @var bool */ - private $unloaded = false; + private bool $unloaded = false; /** * @var \Closure[] * @phpstan-var array */ - private $unloadCallbacks = []; + private array $unloadCallbacks = []; - /** @var BlockLightUpdate|null */ - private $blockLightUpdate = null; - /** @var SkyLightUpdate|null */ - private $skyLightUpdate = null; + private ?BlockLightUpdate $blockLightUpdate = null; + private ?SkyLightUpdate $skyLightUpdate = null; - /** @var \Logger */ - private $logger; - - /** @var AsyncPool */ - private $workerPool; + private \Logger $logger; public static function chunkHash(int $x, int $z) : int{ return morton2d_encode($x, $z); @@ -407,12 +368,14 @@ class World implements ChunkManager{ /** * Init the default world data */ - public function __construct(Server $server, string $name, WritableWorldProvider $provider, AsyncPool $workerPool){ + public function __construct( + private Server $server, + string $name, //TODO: this should be folderName (named arguments BC break) + private WritableWorldProvider $provider, + private AsyncPool $workerPool + ){ + $this->folderName = $name; $this->worldId = self::$worldIdCounter++; - $this->server = $server; - - $this->provider = $provider; - $this->workerPool = $workerPool; $this->displayName = $this->provider->getWorldData()->getName(); $this->logger = new \PrefixedLogger($server->getLogger(), "World: $this->displayName"); @@ -440,7 +403,6 @@ class World implements ChunkManager{ } }); - $this->folderName = $name; $this->scheduledBlockUpdateQueue = new ReversePriorityQueue(); $this->scheduledBlockUpdateQueue->setExtractFlags(\SplPriorityQueue::EXTR_BOTH); diff --git a/src/world/WorldManager.php b/src/world/WorldManager.php index fda2bdcb6..3cc01d8ff 100644 --- a/src/world/WorldManager.php +++ b/src/world/WorldManager.php @@ -55,33 +55,19 @@ use function strval; use function trim; class WorldManager{ - /** @var string */ - private $dataPath; - - /** @var WorldProviderManager */ - private $providerManager; - /** @var World[] */ - private $worlds = []; - /** @var World|null */ - private $defaultWorld; + private array $worlds = []; + private ?World $defaultWorld; - /** @var Server */ - private $server; + private bool $autoSave = true; + private int $autoSaveTicks = 6000; + private int $autoSaveTicker = 0; - /** @var bool */ - private $autoSave = true; - /** @var int */ - private $autoSaveTicks = 6000; - - /** @var int */ - private $autoSaveTicker = 0; - - public function __construct(Server $server, string $dataPath, WorldProviderManager $providerManager){ - $this->server = $server; - $this->dataPath = $dataPath; - $this->providerManager = $providerManager; - } + public function __construct( + private Server $server, + private string $dataPath, + private WorldProviderManager $providerManager + ){} public function getProviderManager() : WorldProviderManager{ return $this->providerManager; diff --git a/src/world/biome/Biome.php b/src/world/biome/Biome.php index ea79a048e..6115beabe 100644 --- a/src/world/biome/Biome.php +++ b/src/world/biome/Biome.php @@ -32,21 +32,17 @@ abstract class Biome{ public const MAX_BIOMES = 256; - /** @var int */ - private $id; - /** @var bool */ - private $registered = false; + private int $id; + private bool $registered = false; /** @var Populator[] */ - private $populators = []; + private array $populators = []; - /** @var int */ - private $minElevation; - /** @var int */ - private $maxElevation; + private int $minElevation; + private int $maxElevation; /** @var Block[] */ - private $groundCover = []; + private array $groundCover = []; /** @var float */ protected $rainfall = 0.5; diff --git a/src/world/biome/BiomeRegistry.php b/src/world/biome/BiomeRegistry.php index 9e7f3077b..809cd4b89 100644 --- a/src/world/biome/BiomeRegistry.php +++ b/src/world/biome/BiomeRegistry.php @@ -34,7 +34,7 @@ final class BiomeRegistry{ * @var Biome[]|\SplFixedArray * @phpstan-var \SplFixedArray */ - private $biomes; + private \SplFixedArray $biomes; public function __construct(){ $this->biomes = new \SplFixedArray(Biome::MAX_BIOMES); diff --git a/src/world/biome/ForestBiome.php b/src/world/biome/ForestBiome.php index b791416a5..d5a4dfba4 100644 --- a/src/world/biome/ForestBiome.php +++ b/src/world/biome/ForestBiome.php @@ -28,9 +28,7 @@ use pocketmine\world\generator\populator\TallGrass; use pocketmine\world\generator\populator\Tree; class ForestBiome extends GrassyBiome{ - - /** @var TreeType */ - private $type; + private TreeType $type; public function __construct(?TreeType $type = null){ parent::__construct(); diff --git a/src/world/generator/hell/Nether.php b/src/world/generator/hell/Nether.php index 5440c6d04..bffdc1389 100644 --- a/src/world/generator/hell/Nether.php +++ b/src/world/generator/hell/Nether.php @@ -38,21 +38,16 @@ use function abs; class Nether extends Generator{ - /** @var Populator[] */ - private $populators = []; - /** @var int */ - private $waterHeight = 32; - /** @var int */ - private $emptyHeight = 64; - /** @var int */ - private $emptyAmplitude = 1; - /** @var float */ - private $density = 0.5; + private int $waterHeight = 32; + private int $emptyHeight = 64; + private int $emptyAmplitude = 1; + private float $density = 0.5; /** @var Populator[] */ - private $generationPopulators = []; - /** @var Simplex */ - private $noiseBase; + private array $populators = []; + /** @var Populator[] */ + private array $generationPopulators = []; + private Simplex $noiseBase; /** * @throws InvalidGeneratorOptionsException diff --git a/src/world/generator/normal/Normal.php b/src/world/generator/normal/Normal.php index a1aebfc1b..607bec4c4 100644 --- a/src/world/generator/normal/Normal.php +++ b/src/world/generator/normal/Normal.php @@ -42,21 +42,14 @@ use pocketmine\world\World; class Normal extends Generator{ + private int $waterHeight = 62; /** @var Populator[] */ - private $populators = []; - /** @var int */ - private $waterHeight = 62; - + private array $populators = []; /** @var Populator[] */ - private $generationPopulators = []; - /** @var Simplex */ - private $noiseBase; - - /** @var BiomeSelector */ - private $selector; - - /** @var Gaussian */ - private $gaussian; + private array $generationPopulators = []; + private Simplex $noiseBase; + private BiomeSelector $selector; + private Gaussian $gaussian; /** * @throws InvalidGeneratorOptionsException diff --git a/src/world/generator/object/Ore.php b/src/world/generator/object/Ore.php index 5a3066030..e534545c0 100644 --- a/src/world/generator/object/Ore.php +++ b/src/world/generator/object/Ore.php @@ -30,8 +30,7 @@ use function sin; use const M_PI; class Ore{ - /** @var Random */ - private $random; + private Random $random; /** @var OreType */ public $type; diff --git a/src/world/generator/populator/Ore.php b/src/world/generator/populator/Ore.php index 7a0d6aff9..ab487db04 100644 --- a/src/world/generator/populator/Ore.php +++ b/src/world/generator/populator/Ore.php @@ -31,7 +31,7 @@ use pocketmine\world\generator\object\OreType; class Ore implements Populator{ /** @var OreType[] */ - private $oreTypes = []; + private array $oreTypes = []; public function populate(ChunkManager $world, int $chunkX, int $chunkZ, Random $random) : void{ foreach($this->oreTypes as $type){ diff --git a/src/world/generator/populator/TallGrass.php b/src/world/generator/populator/TallGrass.php index 10e3d53c5..de8d0b675 100644 --- a/src/world/generator/populator/TallGrass.php +++ b/src/world/generator/populator/TallGrass.php @@ -30,10 +30,8 @@ use pocketmine\world\ChunkManager; use pocketmine\world\format\Chunk; class TallGrass implements Populator{ - /** @var int */ - private $randomAmount = 1; - /** @var int */ - private $baseAmount = 0; + private int $randomAmount = 1; + private int $baseAmount = 0; public function setRandomAmount(int $amount) : void{ $this->randomAmount = $amount; diff --git a/src/world/generator/populator/Tree.php b/src/world/generator/populator/Tree.php index ba4e7d0ae..b0a2214b8 100644 --- a/src/world/generator/populator/Tree.php +++ b/src/world/generator/populator/Tree.php @@ -31,13 +31,9 @@ use pocketmine\world\format\Chunk; use pocketmine\world\generator\object\TreeFactory; class Tree implements Populator{ - /** @var int */ - private $randomAmount = 1; - /** @var int */ - private $baseAmount = 0; - - /** @var TreeType */ - private $type; + private int $randomAmount = 1; + private int $baseAmount = 0; + private TreeType $type; /** * @param TreeType|null $type default oak diff --git a/src/world/light/BlockLightUpdate.php b/src/world/light/BlockLightUpdate.php index 5036400d8..5f6d21faa 100644 --- a/src/world/light/BlockLightUpdate.php +++ b/src/world/light/BlockLightUpdate.php @@ -30,22 +30,18 @@ use pocketmine\world\utils\SubChunkExplorerStatus; use function max; class BlockLightUpdate extends LightUpdate{ - - /** - * @var \SplFixedArray|int[] - * @phpstan-var \SplFixedArray - */ - private $lightEmitters; - /** * @param \SplFixedArray|int[] $lightFilters * @param \SplFixedArray|int[] $lightEmitters * @phpstan-param \SplFixedArray $lightFilters * @phpstan-param \SplFixedArray $lightEmitters */ - public function __construct(SubChunkExplorer $subChunkExplorer, \SplFixedArray $lightFilters, \SplFixedArray $lightEmitters){ + public function __construct( + SubChunkExplorer $subChunkExplorer, + \SplFixedArray $lightFilters, + private \SplFixedArray $lightEmitters + ){ parent::__construct($subChunkExplorer, $lightFilters); - $this->lightEmitters = $lightEmitters; } protected function getCurrentLightArray() : LightArray{ diff --git a/src/world/light/SkyLightUpdate.php b/src/world/light/SkyLightUpdate.php index a505fde02..faf8d1a6c 100644 --- a/src/world/light/SkyLightUpdate.php +++ b/src/world/light/SkyLightUpdate.php @@ -33,22 +33,18 @@ use pocketmine\world\World; use function max; class SkyLightUpdate extends LightUpdate{ - - /** - * @var \SplFixedArray|bool[] - * @phpstan-var \SplFixedArray - */ - private $directSkyLightBlockers; - /** * @param \SplFixedArray|int[] $lightFilters * @param \SplFixedArray|bool[] $directSkyLightBlockers * @phpstan-param \SplFixedArray $lightFilters * @phpstan-param \SplFixedArray $directSkyLightBlockers */ - public function __construct(SubChunkExplorer $subChunkExplorer, \SplFixedArray $lightFilters, \SplFixedArray $directSkyLightBlockers){ + public function __construct( + SubChunkExplorer $subChunkExplorer, + \SplFixedArray $lightFilters, + private \SplFixedArray $directSkyLightBlockers + ){ parent::__construct($subChunkExplorer, $lightFilters); - $this->directSkyLightBlockers = $directSkyLightBlockers; } protected function getCurrentLightArray() : LightArray{