From 11434f3a27946b7da4fcb8bec1a746e3fda90610 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 1 Nov 2020 14:59:22 +0000 Subject: [PATCH] World::setBiomeId() now bails when trying to modify a non-generated chunk (or chunk locked for generation) --- src/world/World.php | 13 ++++++++++++- tests/phpstan/configs/l8-baseline.neon | 5 ----- 2 files changed, 12 insertions(+), 6 deletions(-) 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