From 8aa6f6a9c86981499b39f75012d68eca11aabc6c Mon Sep 17 00:00:00 2001 From: NichtStudioCode <51272202+NichtStudioCode@users.noreply.github.com> Date: Tue, 17 Sep 2024 22:50:06 +0200 Subject: [PATCH] Fix #454 If a chunk is loaded through ChunkSchedulingPatch, but no ChunkLoadEvent is called that enables the chunk before a world save, the region file could be unloaded again, leading to "Block chunk is not loaded" exceptions when world generation tries to place blocks. (Notably, this only interfered with world generation because WorldDataManager loads the chunk on ChunkLoadEvent) --- .../kotlin/xyz/xenondevs/nova/world/format/RegionFile.kt | 8 ++++---- .../xyz/xenondevs/nova/world/format/WorldDataStorage.kt | 2 +- .../xyz/xenondevs/nova/world/format/chunk/RegionChunk.kt | 5 +++++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/nova/src/main/kotlin/xyz/xenondevs/nova/world/format/RegionFile.kt b/nova/src/main/kotlin/xyz/xenondevs/nova/world/format/RegionFile.kt index 76f01e1243..753c187b16 100644 --- a/nova/src/main/kotlin/xyz/xenondevs/nova/world/format/RegionFile.kt +++ b/nova/src/main/kotlin/xyz/xenondevs/nova/world/format/RegionFile.kt @@ -15,12 +15,12 @@ internal class RegionFile( chunks: Array ) : RegionizedFile(MAGIC, VERSION, file, world, regionX, regionZ, chunks) { - fun isAnyChunkEnabled(): Boolean { + fun isInactive(): Boolean { for (chunk in chunks) { - if (chunk.isEnabled) - return true + if (chunk.isEnabled || !chunk.hasBeenEnabled) + return false } - return false + return true } companion object : RegionizedFileReader( diff --git a/nova/src/main/kotlin/xyz/xenondevs/nova/world/format/WorldDataStorage.kt b/nova/src/main/kotlin/xyz/xenondevs/nova/world/format/WorldDataStorage.kt index b62cf9dbd7..6a0003a429 100644 --- a/nova/src/main/kotlin/xyz/xenondevs/nova/world/format/WorldDataStorage.kt +++ b/nova/src/main/kotlin/xyz/xenondevs/nova/world/format/WorldDataStorage.kt @@ -113,7 +113,7 @@ internal class WorldDataStorage(val world: World) { regionFile.save() // unload unused region files - if (unload && !regionFile.isAnyChunkEnabled()) + if (unload && regionFile.isInactive()) blockRegionFiles -= rid } } diff --git a/nova/src/main/kotlin/xyz/xenondevs/nova/world/format/chunk/RegionChunk.kt b/nova/src/main/kotlin/xyz/xenondevs/nova/world/format/chunk/RegionChunk.kt index 9590ace876..73a18221a5 100644 --- a/nova/src/main/kotlin/xyz/xenondevs/nova/world/format/chunk/RegionChunk.kt +++ b/nova/src/main/kotlin/xyz/xenondevs/nova/world/format/chunk/RegionChunk.kt @@ -46,6 +46,10 @@ internal class RegionChunk( @Volatile var isEnabled = false private set + @Volatile + var hasBeenEnabled = false + private set + private var tickingAllowed = false private var isTicking = false @@ -353,6 +357,7 @@ internal class RegionChunk( } } + hasBeenEnabled = true isEnabled = true } }