World: add checks for tile position outside of world bounds, closes #4622

This commit is contained in:
Dylan K. Taylor 2021-12-07 16:41:52 +00:00
parent 5a351d3b17
commit 78ffad5ffc
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -2373,6 +2373,9 @@ class World implements ChunkManager{
if(!$pos->isValid() || $pos->getWorld() !== $this){
throw new \InvalidArgumentException("Invalid Tile world");
}
if(!$this->isInWorld($pos->getFloorX(), $pos->getFloorY(), $pos->getFloorZ())){
throw new \InvalidArgumentException("Tile position is outside the world bounds");
}
$chunkX = $pos->getFloorX() >> Chunk::COORD_BIT_SIZE;
$chunkZ = $pos->getFloorZ() >> Chunk::COORD_BIT_SIZE;
@ -2530,6 +2533,8 @@ class World implements ChunkManager{
$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)){
$logger->error("Found tile saved on wrong chunk - unable to fix due to correct chunk not loaded");
}elseif(!$this->isInWorld(($tilePosition = $tile->getPosition())->getFloorX(), $tilePosition->getFloorY(), $tilePosition->getFloorZ())){
$logger->error("Cannot add tile with position outside the world bounds: x=$tilePosition->x,y=$tilePosition->y,z=$tilePosition->z");
}elseif($this->getTile($tilePosition = $tile->getPosition()) !== null){
$logger->error("Cannot add tile at x=$tilePosition->x,y=$tilePosition->y,z=$tilePosition->z: Another tile is already at that position");
}else{