mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 08:44:01 +00:00
Modernize property declarations in src/world/*
This commit is contained in:
parent
159392e738
commit
b88a47929f
@ -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);
|
||||
});
|
||||
|
@ -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");
|
||||
}
|
||||
|
@ -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){
|
||||
|
@ -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<int, Vector3>
|
||||
*/
|
||||
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<int, Vector3>
|
||||
*/
|
||||
private $scheduledBlockUpdateQueue;
|
||||
/** @phpstan-var ReversePriorityQueue<int, Vector3> */
|
||||
private ReversePriorityQueue $scheduledBlockUpdateQueue;
|
||||
/** @var int[] */
|
||||
private $scheduledBlockUpdateQueueIndex = [];
|
||||
private array $scheduledBlockUpdateQueueIndex = [];
|
||||
|
||||
/**
|
||||
* @var \SplQueue
|
||||
* @phpstan-var \SplQueue<int>
|
||||
*/
|
||||
private $neighbourBlockUpdateQueue;
|
||||
/** @phpstan-var \SplQueue<int> */
|
||||
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<int, PromiseResolver<Chunk>>
|
||||
@ -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<int, \Closure() : void>
|
||||
*/
|
||||
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);
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -34,7 +34,7 @@ final class BiomeRegistry{
|
||||
* @var Biome[]|\SplFixedArray
|
||||
* @phpstan-var \SplFixedArray<Biome>
|
||||
*/
|
||||
private $biomes;
|
||||
private \SplFixedArray $biomes;
|
||||
|
||||
public function __construct(){
|
||||
$this->biomes = new \SplFixedArray(Biome::MAX_BIOMES);
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -30,8 +30,7 @@ use function sin;
|
||||
use const M_PI;
|
||||
|
||||
class Ore{
|
||||
/** @var Random */
|
||||
private $random;
|
||||
private Random $random;
|
||||
/** @var OreType */
|
||||
public $type;
|
||||
|
||||
|
@ -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){
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -30,22 +30,18 @@ use pocketmine\world\utils\SubChunkExplorerStatus;
|
||||
use function max;
|
||||
|
||||
class BlockLightUpdate extends LightUpdate{
|
||||
|
||||
/**
|
||||
* @var \SplFixedArray|int[]
|
||||
* @phpstan-var \SplFixedArray<int>
|
||||
*/
|
||||
private $lightEmitters;
|
||||
|
||||
/**
|
||||
* @param \SplFixedArray|int[] $lightFilters
|
||||
* @param \SplFixedArray|int[] $lightEmitters
|
||||
* @phpstan-param \SplFixedArray<int> $lightFilters
|
||||
* @phpstan-param \SplFixedArray<int> $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{
|
||||
|
@ -33,22 +33,18 @@ use pocketmine\world\World;
|
||||
use function max;
|
||||
|
||||
class SkyLightUpdate extends LightUpdate{
|
||||
|
||||
/**
|
||||
* @var \SplFixedArray|bool[]
|
||||
* @phpstan-var \SplFixedArray<bool>
|
||||
*/
|
||||
private $directSkyLightBlockers;
|
||||
|
||||
/**
|
||||
* @param \SplFixedArray|int[] $lightFilters
|
||||
* @param \SplFixedArray|bool[] $directSkyLightBlockers
|
||||
* @phpstan-param \SplFixedArray<int> $lightFilters
|
||||
* @phpstan-param \SplFixedArray<bool> $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{
|
||||
|
Loading…
x
Reference in New Issue
Block a user