diff --git a/src/world/Position.php b/src/world/Position.php index 0f83b6fd0..82df931e0 100644 --- a/src/world/Position.php +++ b/src/world/Position.php @@ -39,7 +39,7 @@ class Position extends Vector3{ */ public function __construct($x, $y, $z, ?World $world){ parent::__construct($x, $y, $z); - if($world !== null and $world->isClosed()){ + if($world !== null and !$world->isLoaded()){ throw new \InvalidArgumentException("Specified world has been unloaded and cannot be used"); } @@ -66,7 +66,7 @@ class Position extends Vector3{ * @throws AssumptionFailedError */ public function getWorld() : World{ - if($this->world === null || $this->world->isClosed()){ + if($this->world === null || !$this->world->isLoaded()){ throw new AssumptionFailedError("Position world is null or has been unloaded"); } @@ -77,7 +77,7 @@ class Position extends Vector3{ * Checks if this object has a valid reference to a loaded world */ public function isValid() : bool{ - if($this->world !== null and $this->world->isClosed()){ + if($this->world !== null and !$this->world->isLoaded()){ $this->world = null; return false; diff --git a/src/world/World.php b/src/world/World.php index acaf2866b..7c7a4c271 100644 --- a/src/world/World.php +++ b/src/world/World.php @@ -285,7 +285,7 @@ class World implements ChunkManager{ private $generator; /** @var bool */ - private $closed = false; + private $unloaded = false; /** * @var \Closure[] * @phpstan-var array @@ -493,15 +493,15 @@ class World implements ChunkManager{ return $this->worldId; } - public function isClosed() : bool{ - return $this->closed; + public function isLoaded() : bool{ + return !$this->unloaded; } /** * @internal */ - public function close() : void{ - if($this->closed){ + public function onUnload() : void{ + if($this->unloaded){ throw new \InvalidStateException("Tried to close a world which is already closed"); } @@ -523,7 +523,7 @@ class World implements ChunkManager{ $this->provider = null; $this->blockCache = []; - $this->closed = true; + $this->unloaded = true; } /** @phpstan-param \Closure() : void $callback */ @@ -747,7 +747,7 @@ class World implements ChunkManager{ * @internal */ public function doTick(int $currentTick) : void{ - if($this->closed){ + if($this->unloaded){ throw new \InvalidStateException("Attempted to tick a world which has been closed"); } @@ -1046,7 +1046,7 @@ class World implements ChunkManager{ * @phpstan-var array $skyLight * @phpstan-var array $heightMap */ - if($this->closed || ($chunk = $this->getChunk($chunkX, $chunkZ)) === null || $chunk->isLightPopulated() === true){ + if($this->unloaded || ($chunk = $this->getChunk($chunkX, $chunkZ)) === null || $chunk->isLightPopulated() === true){ return; } //TODO: calculated light information might not be valid if the terrain changed during light calculation diff --git a/src/world/WorldManager.php b/src/world/WorldManager.php index 573a95ab8..9bca16ad2 100644 --- a/src/world/WorldManager.php +++ b/src/world/WorldManager.php @@ -168,7 +168,7 @@ class WorldManager{ } unset($this->worlds[$world->getId()]); - $world->close(); + $world->onUnload(); return true; } @@ -321,7 +321,7 @@ class WorldManager{ */ public function findEntity(int $entityId) : ?Entity{ foreach($this->worlds as $world){ - assert(!$world->isClosed()); + assert($world->isLoaded()); if(($entity = $world->getEntity($entityId)) instanceof Entity){ return $entity; } diff --git a/src/world/generator/PopulationTask.php b/src/world/generator/PopulationTask.php index 13c0126d2..5291a957a 100644 --- a/src/world/generator/PopulationTask.php +++ b/src/world/generator/PopulationTask.php @@ -136,7 +136,7 @@ class PopulationTask extends AsyncTask{ public function onCompletion() : void{ /** @var World $world */ $world = $this->fetchLocal(self::TLS_KEY_WORLD); - if(!$world->isClosed()){ + if($world->isLoaded()){ $chunk = $this->chunk !== null ? FastChunkSerializer::deserialize($this->chunk) : null; for($i = 0; $i < 9; ++$i){