World::getChunk() behaviour now matches that of a regular ChunkManager

Various bugs existed for a while with stuff using chunk managers instead of worlds when interacting with terrain due to a behavioural inconsistency between World::getChunk() (return from cache or load from disk), and SimpleChunkManager::getChunk() (return from cache only). This change brings the two in line.
World::getOrLoadChunk() has been added as a replacement, which has the same behaviour as the old getChunk() and also makes it more obvious that there is an issue with code using it during refactoring.
This commit is contained in:
Dylan K. Taylor
2020-09-20 13:29:09 +01:00
parent c9d2edcb4d
commit 5096741b29
5 changed files with 32 additions and 24 deletions

View File

@ -733,7 +733,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
$world = $world ?? $this->getWorld();
$index = World::chunkHash($x, $z);
if(isset($this->usedChunks[$index])){
foreach($world->getChunk($x, $z)->getEntities() as $entity){
foreach($world->getOrLoadChunk($x, $z)->getEntities() as $entity){
if($entity !== $this){
$entity->despawnFrom($this);
}
@ -747,7 +747,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
}
protected function spawnEntitiesOnChunk(int $chunkX, int $chunkZ) : void{
foreach($this->getWorld()->getChunk($chunkX, $chunkZ)->getEntities() as $entity){
foreach($this->getWorld()->getOrLoadChunk($chunkX, $chunkZ)->getEntities() as $entity){
if($entity !== $this and !$entity->isFlaggedForDespawn()){
$entity->spawnTo($this);
}