diff --git a/src/world/World.php b/src/world/World.php index eb5a6e39e..36f24273a 100644 --- a/src/world/World.php +++ b/src/world/World.php @@ -1869,7 +1869,18 @@ class World implements ChunkManager{ } public function setBiomeId(int $x, int $z, int $biomeId) : void{ - $this->getOrLoadChunk($x >> 4, $z >> 4, true)->setBiomeId($x & 0x0f, $z & 0x0f, $biomeId); + $chunkX = $x >> 4; + $chunkZ = $z >> 4; + if($this->isChunkLocked($chunkX, $chunkZ)){ + //the changes would be overwritten when the generation finishes + throw new WorldException("Chunk is currently locked for async generation/population"); + } + if(($chunk = $this->getOrLoadChunk($chunkX, $chunkZ, false)) !== null){ + $chunk->setBiomeId($x & 0x0f, $z & 0x0f, $biomeId); + }else{ + //if we allowed this, the modifications would be lost when the chunk is created + throw new WorldException("Cannot set biome in a non-generated chunk"); + } } /** diff --git a/tests/phpstan/configs/l8-baseline.neon b/tests/phpstan/configs/l8-baseline.neon index 47ebfdf52..ccba8426e 100644 --- a/tests/phpstan/configs/l8-baseline.neon +++ b/tests/phpstan/configs/l8-baseline.neon @@ -535,11 +535,6 @@ parameters: count: 3 path: ../../../src/world/World.php - - - message: "#^Cannot call method setBiomeId\\(\\) on pocketmine\\\\world\\\\format\\\\Chunk\\|null\\.$#" - count: 1 - path: ../../../src/world/World.php - - message: "#^Cannot call method isPopulated\\(\\) on pocketmine\\\\world\\\\format\\\\Chunk\\|null\\.$#" count: 1