World: trigger readStateFromWorld on tile blocks immediately on load

this ensures that the state IDs reflect the actual PM block type, which would probably
be important for a bunch of different async things.
This commit is contained in:
Dylan K. Taylor 2025-08-24 17:01:59 +01:00
parent 17ecf11a1b
commit be90c6c399
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -2978,7 +2978,7 @@ class World implements ChunkManager{
unset($this->blockCache[$chunkHash]);
unset($this->blockCollisionBoxCache[$chunkHash]);
$this->initChunk($x, $z, $chunkData);
$this->initChunk($x, $z, $chunkData, $chunk);
if(ChunkLoadEvent::hasHandlers()){
(new ChunkLoadEvent($this, $x, $z, $this->chunks[$chunkHash], false))->call();
@ -2998,7 +2998,7 @@ class World implements ChunkManager{
return $this->chunks[$chunkHash];
}
private function initChunk(int $chunkX, int $chunkZ, ChunkData $chunkData) : void{
private function initChunk(int $chunkX, int $chunkZ, ChunkData $chunkData, Chunk $chunk) : void{
$logger = new \PrefixedLogger($this->logger, "Loading chunk $chunkX $chunkZ");
if(count($chunkData->getEntityNBT()) !== 0){
@ -3063,6 +3063,16 @@ class World implements ChunkManager{
}else{
$this->addTile($tile);
}
$expectedStateId = $chunk->getBlockStateId($tilePosition->getFloorX() & Chunk::COORD_MASK, $tilePosition->getFloorY(), $tilePosition->getFloorZ() & Chunk::COORD_MASK);
$actualStateId = $this->getBlock($tilePosition)->getStateId();
if($expectedStateId !== $actualStateId){
//state ID was updated by readStateFromWorld - typically because the block pulled some data from the tile
//make sure this is synced to the chunk
//TODO: in the future we should pull tile reading logic out of readStateFromWorld() and do it only
//when the tile is loaded - this would be cleaner and faster
$chunk->setBlockStateId($tilePosition->getFloorX() & Chunk::COORD_MASK, $tilePosition->getFloorY(), $tilePosition->getFloorZ() & Chunk::COORD_MASK, $actualStateId);
$this->logger->debug("Tile " . $tile::class . " at x=$tilePosition->x,y=$tilePosition->y,z=$tilePosition->z updated block state ID from $expectedStateId to $actualStateId");
}
}
foreach(Utils::promoteKeys($deletedTiles) as $saveId => $count){