diff --git a/nova/src/main/kotlin/xyz/xenondevs/nova/data/world/RegionFile.kt b/nova/src/main/kotlin/xyz/xenondevs/nova/data/world/RegionFile.kt index ff7151d891..9eb48a510a 100644 --- a/nova/src/main/kotlin/xyz/xenondevs/nova/data/world/RegionFile.kt +++ b/nova/src/main/kotlin/xyz/xenondevs/nova/data/world/RegionFile.kt @@ -63,8 +63,12 @@ internal class RegionFile(val world: World, val file: File, val regionX: Int, va } fun init() { - if (file.length() != 0L) { - readFile(DataInputStream(file.inputStream())) + try { + if (file.length() != 0L) { + readFile(DataInputStream(file.inputStream())) + } + } catch (e: Exception) { + throw IllegalStateException("Could not initialize region file $file", e) } } diff --git a/nova/src/main/kotlin/xyz/xenondevs/nova/data/world/WorldDataStorage.kt b/nova/src/main/kotlin/xyz/xenondevs/nova/data/world/WorldDataStorage.kt index 398c3732a1..eeebdd53e7 100644 --- a/nova/src/main/kotlin/xyz/xenondevs/nova/data/world/WorldDataStorage.kt +++ b/nova/src/main/kotlin/xyz/xenondevs/nova/data/world/WorldDataStorage.kt @@ -16,13 +16,17 @@ internal class WorldDataStorage(val world: World) { } fun getRegion(pos: ChunkPos): RegionFile { - val rx = pos.x shr 5 - val rz = pos.z shr 5 - val rid = (rx.toLong() shl 32) or (rz.toLong() and 0xFFFFFFFF) - - return regionFiles.getOrPut(rid) { - val file = File(regionsFolder, "r.$rx.$rz.nvr") - return@getOrPut RegionFile(this.world, file, rx, rz).apply(RegionFile::init) + try { + val rx = pos.x shr 5 + val rz = pos.z shr 5 + val rid = (rx.toLong() shl 32) or (rz.toLong() and 0xFFFFFFFF) + + return regionFiles.getOrPut(rid) { + val file = File(regionsFolder, "r.$rx.$rz.nvr") + return@getOrPut RegionFile(this.world, file, rx, rz).apply(RegionFile::init) + } + } catch (e: Exception) { + throw IllegalStateException("Could not retrieve RegionFile for $pos", e) } } @@ -30,7 +34,7 @@ internal class WorldDataStorage(val world: World) { val rx = pos.x shr 5 val rz = pos.z shr 5 val rid = (rx.toLong() shl 32) or (rz.toLong() and 0xFFFFFFFF) - + return regionFiles[rid] }