Skip to content

Commit

Permalink
NeoForge: Call ChunkEvent.Unload on shutdown
Browse files Browse the repository at this point in the history
This brings behavior in line with vanilla NeoForge.
  • Loading branch information
jpenilla committed Aug 29, 2024
1 parent 0075519 commit 83cc32b
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import net.minecraft.util.SortedArraySet;
import net.minecraft.util.Unit;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.chunk.LevelChunk;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
Expand Down Expand Up @@ -279,6 +280,16 @@ public void saveAllChunks(final boolean flush, final boolean shutdown, final boo
int savedEntity = 0;
int savedPoi = 0;

if (shutdown) {
// Normal unload process does not occur during shutdown: fire event manually
// for mods that expect ChunkEvent.Unload to fire on shutdown (before LevelEvent.Unload)
for (int i = 0, len = holders.size(); i < len; ++i) {
final NewChunkHolder holder = holders.get(i);
if (holder.getCurrentChunk() instanceof LevelChunk levelChunk) {
PlatformHooks.get().chunkUnloadFromWorld(levelChunk);
}
}
}
for (int i = 0, len = holders.size(); i < len; ++i) {
final NewChunkHolder holder = holders.get(i);
try {
Expand Down

0 comments on commit 83cc32b

Please sign in to comment.