Skip to content

Commit

Permalink
Fix #454
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
NichtStudioCode committed Sep 17, 2024
1 parent edb6cd8 commit 8aa6f6a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ internal class RegionFile(
chunks: Array<RegionChunk>
) : RegionizedFile<RegionChunk>(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<RegionChunk, RegionFile>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -353,6 +357,7 @@ internal class RegionChunk(
}
}

hasBeenEnabled = true
isEnabled = true
}
}
Expand Down

0 comments on commit 8aa6f6a

Please sign in to comment.