World: avoid duplicated logger code in initChunk()

This commit is contained in:
Dylan K. Taylor 2021-10-31 14:02:25 +00:00
parent 1cabe4baf3
commit 3dc75644d9
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -2442,6 +2442,7 @@ class World implements ChunkManager{
}
private function initChunk(int $chunkX, int $chunkZ, ChunkData $chunkData) : void{
$logger = new \PrefixedLogger($this->logger, "Loading chunk $chunkX $chunkZ");
if(count($chunkData->getEntityNBT()) !== 0){
$this->timings->syncChunkLoadEntities->startTiming();
$entityFactory = EntityFactory::getInstance();
@ -2449,8 +2450,8 @@ class World implements ChunkManager{
try{
$entity = $entityFactory->createFromData($this, $nbt);
}catch(NbtDataException $e){
$this->getLogger()->error("Chunk $chunkX $chunkZ: Bad entity data at list position $k: " . $e->getMessage());
$this->getLogger()->logException($e);
$logger->error("Bad entity data at list position $k: " . $e->getMessage());
$logger->logException($e);
continue;
}
if($entity === null){
@ -2461,7 +2462,7 @@ class World implements ChunkManager{
}elseif($saveIdTag instanceof IntTag){ //legacy MCPE format
$saveId = "legacy(" . $saveIdTag->getValue() . ")";
}
$this->getLogger()->warning("Chunk $chunkX $chunkZ: Deleted unknown entity type $saveId");
$logger->warning("Deleted unknown entity type $saveId");
}
//TODO: we can't prevent entities getting added to unloaded chunks if they were saved in the wrong place
//here, because entities currently add themselves to the world
@ -2477,16 +2478,16 @@ class World implements ChunkManager{
try{
$tile = $tileFactory->createFromData($this, $nbt);
}catch(NbtDataException $e){
$this->getLogger()->error("Chunk $chunkX $chunkZ: Bad tile entity data at list position $k: " . $e->getMessage());
$this->getLogger()->logException($e);
$logger->error("Bad tile entity data at list position $k: " . $e->getMessage());
$logger->logException($e);
continue;
}
if($tile === null){
$this->getLogger()->warning("Chunk $chunkX $chunkZ: Deleted unknown tile entity type " . $nbt->getString("id", "<unknown>"));
$logger->warning("Deleted unknown tile entity type " . $nbt->getString("id", "<unknown>"));
}elseif(!$this->isChunkLoaded($tile->getPosition()->getFloorX() >> Chunk::COORD_BIT_SIZE, $tile->getPosition()->getFloorZ() >> Chunk::COORD_BIT_SIZE)){
$this->logger->error("Chunk $chunkX $chunkZ: Found tile saved on wrong chunk - unable to fix due to correct chunk not loaded");
$logger->error("Found tile saved on wrong chunk - unable to fix due to correct chunk not loaded");
}elseif($this->getTile($tilePosition = $tile->getPosition()) !== null){
$this->logger->error("Chunk $chunkX $chunkZ: Cannot add tile at x=$tilePosition->x,y=$tilePosition->y,z=$tilePosition->z: Another tile is already at that position");
$logger->error("Cannot add tile at x=$tilePosition->x,y=$tilePosition->y,z=$tilePosition->z: Another tile is already at that position");
}else{
$this->addTile($tile);
}