Improve PHPDocs in world package

This commit is contained in:
Dylan K. Taylor 2025-01-06 22:46:16 +00:00
parent c5a1c15389
commit b6bd3ef30c
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
6 changed files with 24 additions and 10 deletions

View File

@ -1562,6 +1562,7 @@ class World implements ChunkManager{
* Larger AABBs (>= 2 blocks on any axis) are not accounted for. * Larger AABBs (>= 2 blocks on any axis) are not accounted for.
* *
* @return AxisAlignedBB[] * @return AxisAlignedBB[]
* @phpstan-return list<AxisAlignedBB>
*/ */
private function getBlockCollisionBoxesForCell(int $x, int $y, int $z) : array{ private function getBlockCollisionBoxesForCell(int $x, int $y, int $z) : array{
$block = $this->getBlockAt($x, $y, $z); $block = $this->getBlockAt($x, $y, $z);
@ -2040,7 +2041,6 @@ class World implements ChunkManager{
* @phpstan-return list<ExperienceOrb> * @phpstan-return list<ExperienceOrb>
*/ */
public function dropExperience(Vector3 $pos, int $amount) : array{ public function dropExperience(Vector3 $pos, int $amount) : array{
/** @var ExperienceOrb[] $orbs */
$orbs = []; $orbs = [];
foreach(ExperienceOrb::splitIntoOrbSizes($amount) as $split){ foreach(ExperienceOrb::splitIntoOrbSizes($amount) as $split){
@ -3083,6 +3083,7 @@ class World implements ChunkManager{
* @phpstan-return Promise<Position> * @phpstan-return Promise<Position>
*/ */
public function requestSafeSpawn(?Vector3 $spawn = null) : Promise{ public function requestSafeSpawn(?Vector3 $spawn = null) : Promise{
/** @phpstan-var PromiseResolver<Position> $resolver */
$resolver = new PromiseResolver(); $resolver = new PromiseResolver();
$spawn ??= $this->getSpawnLocation(); $spawn ??= $this->getSpawnLocation();
/* /*
@ -3254,6 +3255,7 @@ class World implements ChunkManager{
private function enqueuePopulationRequest(int $chunkX, int $chunkZ, ?ChunkLoader $associatedChunkLoader) : Promise{ private function enqueuePopulationRequest(int $chunkX, int $chunkZ, ?ChunkLoader $associatedChunkLoader) : Promise{
$chunkHash = World::chunkHash($chunkX, $chunkZ); $chunkHash = World::chunkHash($chunkX, $chunkZ);
$this->addChunkHashToPopulationRequestQueue($chunkHash); $this->addChunkHashToPopulationRequestQueue($chunkHash);
/** @phpstan-var PromiseResolver<Chunk> $resolver */
$resolver = $this->chunkPopulationRequestMap[$chunkHash] = new PromiseResolver(); $resolver = $this->chunkPopulationRequestMap[$chunkHash] = new PromiseResolver();
if($associatedChunkLoader === null){ if($associatedChunkLoader === null){
$temporaryLoader = new class implements ChunkLoader{}; $temporaryLoader = new class implements ChunkLoader{};

View File

@ -57,7 +57,10 @@ class Chunk{
*/ */
protected \SplFixedArray $subChunks; protected \SplFixedArray $subChunks;
/** @var Tile[] */ /**
* @var Tile[]
* @phpstan-var array<int, Tile>
*/
protected array $tiles = []; protected array $tiles = [];
protected HeightArray $heightMap; protected HeightArray $heightMap;
@ -210,6 +213,7 @@ class Chunk{
/** /**
* @return Tile[] * @return Tile[]
* @phpstan-return array<int, Tile>
*/ */
public function getTiles() : array{ public function getTiles() : array{
return $this->tiles; return $this->tiles;
@ -237,6 +241,7 @@ class Chunk{
/** /**
* @return int[] * @return int[]
* @phpstan-return non-empty-list<int>
*/ */
public function getHeightMapArray() : array{ public function getHeightMapArray() : array{
return $this->heightMap->getValues(); return $this->heightMap->getValues();
@ -244,6 +249,7 @@ class Chunk{
/** /**
* @param int[] $values * @param int[] $values
* @phpstan-param non-empty-list<int> $values
*/ */
public function setHeightMapArray(array $values) : void{ public function setHeightMapArray(array $values) : void{
$this->heightMap = new HeightArray($values); $this->heightMap = new HeightArray($values);

View File

@ -36,7 +36,7 @@ final class HeightArray{
/** /**
* @param int[] $values ZZZZXXXX key bit order * @param int[] $values ZZZZXXXX key bit order
* @phpstan-param list<int> $values * @phpstan-param non-empty-list<int> $values
*/ */
public function __construct(array $values){ public function __construct(array $values){
if(count($values) !== 256){ if(count($values) !== 256){
@ -66,7 +66,7 @@ final class HeightArray{
/** /**
* @return int[] ZZZZXXXX key bit order * @return int[] ZZZZXXXX key bit order
* @phpstan-return list<int> * @phpstan-return non-empty-list<int>
*/ */
public function getValues() : array{ public function getValues() : array{
return $this->array->toArray(); return $this->array->toArray();

View File

@ -112,7 +112,6 @@ final class FastChunkSerializer{
$y = Binary::signByte($stream->getByte()); $y = Binary::signByte($stream->getByte());
$airBlockId = $stream->getInt(); $airBlockId = $stream->getInt();
/** @var PalettedBlockArray[] $layers */
$layers = []; $layers = [];
for($i = 0, $layerCount = $stream->getByte(); $i < $layerCount; ++$i){ for($i = 0, $layerCount = $stream->getByte(); $i < $layerCount; ++$i){
$layers[] = self::deserializePalettedArray($stream); $layers[] = self::deserializePalettedArray($stream);

View File

@ -93,10 +93,12 @@ abstract class RegionWorldProvider extends BaseWorldProvider{
} }
/** /**
* @param int $regionX reference parameter * @param int|null $regionX reference parameter
* @param int $regionZ reference parameter * @param int|null $regionZ reference parameter
* @phpstan-param-out int $regionX * @phpstan-param-out int $regionX
* @phpstan-param-out int $regionZ * @phpstan-param-out int $regionZ
*
* TODO: make this private
*/ */
public static function getRegionIndex(int $chunkX, int $chunkZ, &$regionX, &$regionZ) : void{ public static function getRegionIndex(int $chunkX, int $chunkZ, &$regionX, &$regionZ) : void{
$regionX = $chunkX >> 5; $regionX = $chunkX >> 5;
@ -154,6 +156,8 @@ abstract class RegionWorldProvider extends BaseWorldProvider{
/** /**
* @return CompoundTag[] * @return CompoundTag[]
* @phpstan-return list<CompoundTag>
*
* @throws CorruptedChunkException * @throws CorruptedChunkException
*/ */
protected static function getCompoundList(string $context, ListTag $list) : array{ protected static function getCompoundList(string $context, ListTag $list) : array{

View File

@ -44,7 +44,7 @@ class LightPopulationTask extends AsyncTask{
private string $resultBlockLightArrays; private string $resultBlockLightArrays;
/** /**
* @phpstan-param \Closure(array<int, LightArray> $blockLight, array<int, LightArray> $skyLight, array<int, int> $heightMap) : void $onCompletion * @phpstan-param \Closure(array<int, LightArray> $blockLight, array<int, LightArray> $skyLight, non-empty-list<int> $heightMap) : void $onCompletion
*/ */
public function __construct(Chunk $chunk, \Closure $onCompletion){ public function __construct(Chunk $chunk, \Closure $onCompletion){
$this->chunk = FastChunkSerializer::serializeTerrain($chunk); $this->chunk = FastChunkSerializer::serializeTerrain($chunk);
@ -80,7 +80,10 @@ class LightPopulationTask extends AsyncTask{
} }
public function onCompletion() : void{ public function onCompletion() : void{
/** @var int[] $heightMapArray */ /**
* @var int[] $heightMapArray
* @phpstan-var non-empty-list<int> $heightMapArray
*/
$heightMapArray = igbinary_unserialize($this->resultHeightMap); $heightMapArray = igbinary_unserialize($this->resultHeightMap);
/** @var LightArray[] $skyLightArrays */ /** @var LightArray[] $skyLightArrays */
@ -90,7 +93,7 @@ class LightPopulationTask extends AsyncTask{
/** /**
* @var \Closure * @var \Closure
* @phpstan-var \Closure(array<int, LightArray> $blockLight, array<int, LightArray> $skyLight, array<int, int> $heightMap) : void * @phpstan-var \Closure(array<int, LightArray> $blockLight, array<int, LightArray> $skyLight, non-empty-list<int> $heightMap) : void
*/ */
$callback = $this->fetchLocal(self::TLS_KEY_COMPLETION_CALLBACK); $callback = $this->fetchLocal(self::TLS_KEY_COMPLETION_CALLBACK);
$callback($blockLightArrays, $skyLightArrays, $heightMapArray); $callback($blockLightArrays, $skyLightArrays, $heightMapArray);