Simplify chunk unload logic & fix events not being fired when INACCESSIBLE chunks are unloaded

This commit is contained in:
embeddedt 2026-03-14 14:59:45 -04:00
parent f79eae8b83
commit e34a99b38c
No known key found for this signature in database
GPG Key ID: A69433EC199B5613
2 changed files with 12 additions and 32 deletions

View File

@ -10,8 +10,6 @@ import net.minecraft.server.level.ChunkHolder;
import net.minecraft.server.level.ChunkLevel;
import net.minecraft.server.level.ChunkMap;
import net.minecraft.server.level.FullChunkStatus;
import net.minecraft.server.level.ThreadedLevelLightEngine;
import net.minecraft.server.level.progress.ChunkProgressListener;
import net.minecraft.util.thread.BlockableEventLoop;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.chunk.ChunkAccess;
@ -27,7 +25,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.Executor;
import java.util.function.BooleanSupplier;
@ -37,20 +34,16 @@ public abstract class ChunkMapMixin implements ISuspendedHolderTrackingChunkMap
@Final
public Long2ObjectLinkedOpenHashMap<ChunkHolder> updatingChunkMap;
@Shadow
protected abstract boolean save(ChunkAccess chunk);
@Shadow
@Final
private ChunkProgressListener progressListener;
@Shadow
@Final
private ThreadedLevelLightEngine lightEngine;
@Shadow
@Final
private BlockableEventLoop<Runnable> mainThreadExecutor;
@Shadow
protected abstract void lambda$scheduleUnload$14(ChunkHolder holder, CompletableFuture<ChunkAccess> chunkToSaveFuture, long chunkPos, ChunkAccess chunk);
@Shadow
@Final
public Long2ObjectLinkedOpenHashMap<ChunkHolder> pendingUnloads;
private final LongOpenHashSet mfix$protoChunksToDrop = new LongOpenHashSet();
/**
@ -85,16 +78,15 @@ public abstract class ChunkMapMixin implements ISuspendedHolderTrackingChunkMap
// All generation work done, so we can suspend and remove from set
dropIterator.remove();
ChunkAccess chunk = holder.getChunkToSave().getNow(null);
if (chunk != null) {
this.save(chunk); // flush protochunk to disk
}
var chunkToSaveFuture = holder.getChunkToSave();
// Execute the logic inside scheduleUnload() inline, without delegating to a queue
// When this returns it is safe to release any data the ChunkHolder holds
this.pendingUnloads.put(pos, holder);
this.lambda$scheduleUnload$14(holder, chunkToSaveFuture, pos, chunkToSaveFuture.getNow(null));
((IClearableChunkHolder)holder).mfix$resetProtoChunkFutures();
this.progressListener.onStatusChange(holder.getPos(), null);
((ThreadedLevelLightEngineAccessor)this.lightEngine).mfix$invokeUpdateChunkStatus(holder.getPos());
this.lightEngine.tryScheduleUpdate();
suspended++;
}
}

View File

@ -1,12 +0,0 @@
package org.embeddedt.modernfix.common.mixin.perf.release_protochunks;
import net.minecraft.server.level.ThreadedLevelLightEngine;
import net.minecraft.world.level.ChunkPos;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;
@Mixin(ThreadedLevelLightEngine.class)
public interface ThreadedLevelLightEngineAccessor {
@Invoker("updateChunkStatus")
void mfix$invokeUpdateChunkStatus(ChunkPos pos);
}