World: discard tiles on load if they aren't the correct type or no tile is expected

in many instances, remnants of improperly removed blocks from PM3 have been causing problems, such as flower pot tiles where there are no flower pots.

this change might break some plugins which are using tiles for custom purposes, but this is a misuse that was never supported properly in the first place.
This commit is contained in:
Dylan K. Taylor 2023-09-27 14:57:06 +01:00
parent c3bca9e172
commit 8f804f6f34
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -2873,7 +2873,15 @@ class World implements ChunkManager{
}elseif($this->getTile($tilePosition) !== null){
$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);
$block = $this->getBlockAt($tilePosition->getFloorX(), $tilePosition->getFloorY(), $tilePosition->getFloorZ());
$expectedClass = $block->getIdInfo()->getTileClass();
if($expectedClass === null){
$logger->error("Cannot add tile at x=$tilePosition->x,y=$tilePosition->y,z=$tilePosition->z: Block at that position (" . $block->getName() . ") does not expect a tile");
}elseif(!($tile instanceof $expectedClass)){
$logger->error("Cannot add tile at x=$tilePosition->x,y=$tilePosition->y,z=$tilePosition->z: Tile is of wrong type (expected $expectedClass but have " . get_class($tile) . ")");
}else{
$this->addTile($tile);
}
}
}