From f56339c30649f426e7e2d49256b3319f39a2bc0f Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 26 Jan 2023 14:48:43 +0000 Subject: [PATCH] Fix build --- src/block/Block.php | 7 ++- src/world/Explosion.php | 7 ++- src/world/generator/hell/Nether.php | 4 +- src/world/generator/normal/Normal.php | 3 +- src/world/generator/populator/GroundCover.php | 2 +- tests/phpstan/configs/actual-problems.neon | 53 ++----------------- 6 files changed, 22 insertions(+), 54 deletions(-) diff --git a/src/block/Block.php b/src/block/Block.php index 5bbddb0c0..1481284a8 100644 --- a/src/block/Block.php +++ b/src/block/Block.php @@ -42,6 +42,7 @@ use pocketmine\math\RayTraceResult; use pocketmine\math\Vector3; use pocketmine\nbt\tag\CompoundTag; use pocketmine\player\Player; +use pocketmine\utils\AssumptionFailedError; use pocketmine\world\BlockTransaction; use pocketmine\world\format\Chunk; use pocketmine\world\Position; @@ -216,7 +217,11 @@ class Block{ */ public function writeStateToWorld() : void{ $world = $this->position->getWorld(); - $world->getOrLoadChunkAtPosition($this->position)->setBlockStateId($this->position->x & Chunk::COORD_MASK, $this->position->y, $this->position->z & Chunk::COORD_MASK, $this->getStateId()); + $chunk = $world->getOrLoadChunkAtPosition($this->position); + if($chunk === null){ + throw new AssumptionFailedError("World::setBlock() should have loaded the chunk before calling this method"); + } + $chunk->setBlockStateId($this->position->x & Chunk::COORD_MASK, $this->position->y, $this->position->z & Chunk::COORD_MASK, $this->getStateId()); $tileType = $this->idInfo->getTileClass(); $oldTile = $world->getTile($this->position); diff --git a/src/world/Explosion.php b/src/world/Explosion.php index acc806f99..601f9109e 100644 --- a/src/world/Explosion.php +++ b/src/world/Explosion.php @@ -35,6 +35,7 @@ use pocketmine\event\entity\EntityExplodeEvent; use pocketmine\item\VanillaItems; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Vector3; +use pocketmine\utils\AssumptionFailedError; use pocketmine\world\format\SubChunk; use pocketmine\world\particle\HugeExplodeSeedParticle; use pocketmine\world\sound\ExplodeSound; @@ -111,8 +112,12 @@ class Explosion{ if($this->subChunkExplorer->moveTo($vBlockX, $vBlockY, $vBlockZ) === SubChunkExplorerStatus::INVALID){ continue; } + $subChunk = $this->subChunkExplorer->currentSubChunk; + if($subChunk === null){ + throw new AssumptionFailedError("SubChunkExplorer subchunk should not be null here"); + } - $state = $this->subChunkExplorer->currentSubChunk->getBlockStateId($vBlockX & SubChunk::COORD_MASK, $vBlockY & SubChunk::COORD_MASK, $vBlockZ & SubChunk::COORD_MASK); + $state = $subChunk->getBlockStateId($vBlockX & SubChunk::COORD_MASK, $vBlockY & SubChunk::COORD_MASK, $vBlockZ & SubChunk::COORD_MASK); $blastResistance = $blockFactory->blastResistance[$state] ?? 0; if($blastResistance >= 0){ diff --git a/src/world/generator/hell/Nether.php b/src/world/generator/hell/Nether.php index 665d9452e..f58360820 100644 --- a/src/world/generator/hell/Nether.php +++ b/src/world/generator/hell/Nether.php @@ -25,6 +25,7 @@ namespace pocketmine\world\generator\hell; use pocketmine\block\VanillaBlocks; use pocketmine\data\bedrock\BiomeIds; +use pocketmine\utils\AssumptionFailedError; use pocketmine\world\biome\BiomeRegistry; use pocketmine\world\ChunkManager; use pocketmine\world\format\Chunk; @@ -71,7 +72,8 @@ class Nether extends Generator{ $noise = $this->noiseBase->getFastNoise3D(Chunk::EDGE_LENGTH, 128, Chunk::EDGE_LENGTH, 4, 8, 4, $chunkX * Chunk::EDGE_LENGTH, 0, $chunkZ * Chunk::EDGE_LENGTH); - $chunk = $world->getChunk($chunkX, $chunkZ); + //TODO: why don't we just create and set the chunk here directly? + $chunk = $world->getChunk($chunkX, $chunkZ) ?? throw new \InvalidArgumentException("Chunk $chunkX $chunkZ does not yet exist"); $bedrock = VanillaBlocks::BEDROCK()->getStateId(); $netherrack = VanillaBlocks::NETHERRACK()->getStateId(); diff --git a/src/world/generator/normal/Normal.php b/src/world/generator/normal/Normal.php index a750fc894..1d4805e16 100644 --- a/src/world/generator/normal/Normal.php +++ b/src/world/generator/normal/Normal.php @@ -141,7 +141,8 @@ class Normal extends Generator{ $noise = $this->noiseBase->getFastNoise3D(Chunk::EDGE_LENGTH, 128, Chunk::EDGE_LENGTH, 4, 8, 4, $chunkX * Chunk::EDGE_LENGTH, 0, $chunkZ * Chunk::EDGE_LENGTH); - $chunk = $world->getChunk($chunkX, $chunkZ); + //TODO: why don't we just create and set the chunk here directly? + $chunk = $world->getChunk($chunkX, $chunkZ) ?? throw new \InvalidArgumentException("Chunk $chunkX $chunkZ does not yet exist"); $biomeCache = []; diff --git a/src/world/generator/populator/GroundCover.php b/src/world/generator/populator/GroundCover.php index 1ce0c9fca..6af3e657c 100644 --- a/src/world/generator/populator/GroundCover.php +++ b/src/world/generator/populator/GroundCover.php @@ -36,7 +36,7 @@ use function min; class GroundCover implements Populator{ public function populate(ChunkManager $world, int $chunkX, int $chunkZ, Random $random) : void{ - $chunk = $world->getChunk($chunkX, $chunkZ); + $chunk = $world->getChunk($chunkX, $chunkZ) ?? throw new \InvalidArgumentException("Chunk $chunkX $chunkZ does not yet exist"); $factory = RuntimeBlockStateRegistry::getInstance(); $biomeRegistry = BiomeRegistry::getInstance(); for($x = 0; $x < Chunk::EDGE_LENGTH; ++$x){ diff --git a/tests/phpstan/configs/actual-problems.neon b/tests/phpstan/configs/actual-problems.neon index 6698add08..5f01c2d18 100644 --- a/tests/phpstan/configs/actual-problems.neon +++ b/tests/phpstan/configs/actual-problems.neon @@ -61,7 +61,7 @@ parameters: path: ../../../src/VersionInfo.php - - message: "#^Cannot call method setFullBlock\\(\\) on pocketmine\\\\world\\\\format\\\\Chunk\\|null\\.$#" + message: "#^Parameter \\#2 \\$y of method pocketmine\\\\world\\\\format\\\\Chunk\\:\\:setBlockStateId\\(\\) expects int, float\\|int given\\.$#" count: 1 path: ../../../src/block/Block.php @@ -910,11 +910,6 @@ parameters: count: 1 path: ../../../src/utils/Utils.php - - - message: "#^Cannot call method getFullBlock\\(\\) on pocketmine\\\\world\\\\format\\\\SubChunk\\|null\\.$#" - count: 1 - path: ../../../src/world/Explosion.php - - message: "#^Parameter \\#1 \\$x of method pocketmine\\\\world\\\\World\\:\\:getTileAt\\(\\) expects int, float\\|int given\\.$#" count: 1 @@ -1150,31 +1145,11 @@ parameters: count: 1 path: ../../../src/world/generator/hell/Nether.php - - - message: "#^Cannot call method setBiomeId\\(\\) on pocketmine\\\\world\\\\format\\\\Chunk\\|null\\.$#" - count: 1 - path: ../../../src/world/generator/hell/Nether.php - - - - message: "#^Cannot call method setFullBlock\\(\\) on pocketmine\\\\world\\\\format\\\\Chunk\\|null\\.$#" - count: 3 - path: ../../../src/world/generator/hell/Nether.php - - message: "#^Cannot call method getBiomeId\\(\\) on pocketmine\\\\world\\\\format\\\\Chunk\\|null\\.$#" count: 1 path: ../../../src/world/generator/normal/Normal.php - - - message: "#^Cannot call method setBiomeId\\(\\) on pocketmine\\\\world\\\\format\\\\Chunk\\|null\\.$#" - count: 1 - path: ../../../src/world/generator/normal/Normal.php - - - - message: "#^Cannot call method setFullBlock\\(\\) on pocketmine\\\\world\\\\format\\\\Chunk\\|null\\.$#" - count: 3 - path: ../../../src/world/generator/normal/Normal.php - - message: "#^Parameter \\#1 \\$start of method pocketmine\\\\utils\\\\Random\\:\\:nextRange\\(\\) expects int, float\\|int given\\.$#" count: 2 @@ -1195,28 +1170,13 @@ parameters: count: 1 path: ../../../src/world/generator/object/TallGrass.php - - - message: "#^Cannot call method getBiomeId\\(\\) on pocketmine\\\\world\\\\format\\\\Chunk\\|null\\.$#" - count: 1 - path: ../../../src/world/generator/populator/GroundCover.php - - - - message: "#^Cannot call method getFullBlock\\(\\) on pocketmine\\\\world\\\\format\\\\Chunk\\|null\\.$#" - count: 2 - path: ../../../src/world/generator/populator/GroundCover.php - - - - message: "#^Cannot call method setFullBlock\\(\\) on pocketmine\\\\world\\\\format\\\\Chunk\\|null\\.$#" - count: 1 - path: ../../../src/world/generator/populator/GroundCover.php - - message: "#^Cannot call method getBlockLightArray\\(\\) on pocketmine\\\\world\\\\format\\\\SubChunk\\|null\\.$#" count: 1 path: ../../../src/world/light/BlockLightUpdate.php - - message: "#^Cannot call method getFullBlock\\(\\) on pocketmine\\\\world\\\\format\\\\SubChunk\\|null\\.$#" + message: "#^Cannot call method getBlockStateId\\(\\) on pocketmine\\\\world\\\\format\\\\SubChunk\\|null\\.$#" count: 1 path: ../../../src/world/light/BlockLightUpdate.php @@ -1241,7 +1201,7 @@ parameters: path: ../../../src/world/light/LightPopulationTask.php - - message: "#^Cannot call method getFullBlock\\(\\) on pocketmine\\\\world\\\\format\\\\SubChunk\\|null\\.$#" + message: "#^Cannot call method getBlockStateId\\(\\) on pocketmine\\\\world\\\\format\\\\SubChunk\\|null\\.$#" count: 1 path: ../../../src/world/light/LightUpdate.php @@ -1251,7 +1211,7 @@ parameters: path: ../../../src/world/light/SkyLightUpdate.php - - message: "#^Cannot call method getFullBlock\\(\\) on pocketmine\\\\world\\\\format\\\\SubChunk\\|null\\.$#" + message: "#^Cannot call method getBlockStateId\\(\\) on pocketmine\\\\world\\\\format\\\\SubChunk\\|null\\.$#" count: 1 path: ../../../src/world/light/SkyLightUpdate.php @@ -1280,11 +1240,6 @@ parameters: count: 1 path: ../../../src/world/light/SkyLightUpdate.php - - - message: "#^Only numeric types are allowed in \\+, int\\|false given on the left side\\.$#" - count: 1 - path: ../../../src/world/light/SkyLightUpdate.php - - message: "#^Parameter \\#1 \\$chunk of static method pocketmine\\\\world\\\\light\\\\SkyLightUpdate\\:\\:recalculateHeightMap\\(\\) expects pocketmine\\\\world\\\\format\\\\Chunk, pocketmine\\\\world\\\\format\\\\Chunk\\|null given\\.$#" count: 1