diff --git a/gradle.properties b/gradle.properties index 4657814e..0739db46 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ org.gradle.jvmargs=-Xmx3G org.gradle.daemon=false -forge_version=39.0.19 +forge_version=39.0.63 semver=0.0.0 diff --git a/src/main/java/li/cil/oc2/common/mixin/ChunkMapMixin.java b/src/main/java/li/cil/oc2/common/mixin/ChunkMapMixin.java index 0b4e7dcf..97241515 100644 --- a/src/main/java/li/cil/oc2/common/mixin/ChunkMapMixin.java +++ b/src/main/java/li/cil/oc2/common/mixin/ChunkMapMixin.java @@ -14,10 +14,8 @@ import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import java.nio.file.Path; -import java.util.concurrent.CompletableFuture; /** * Hooks into {@link ChunkMap} saving code-paths for "hard" save operations. @@ -51,46 +49,15 @@ public abstract class ChunkMapMixin extends ChunkStorage { super(path, dataFixer, sync); } - /** - * This is for the code-path taken when a chunk is being unloaded. - */ - @Inject(method = "lambda$scheduleUnload$11", at = {@At(value = "INVOKE", target = "Lnet/minecraft/server/level/ChunkMap;save(Lnet/minecraft/world/level/chunk/ChunkAccess;)Z")}) - private void beforeSaveOnUnload(final ChunkHolder chunkHolder, final CompletableFuture chunkToSave, final long chunkId, final ChunkAccess chunkAccess, final CallbackInfo ci) { - if (chunkAccess instanceof ChunkAccessExt ext) { - ext.applyAndClearLazyUnsaved(); - } - } - - /** - * This is for the code-path taken when saving all chunks upon server shutdown or when - * running a save command with the "flush" flag. - */ - @Inject(method = "lambda$saveAllChunks$8", at = {@At(value = "HEAD")}) - private static void beforeSyncSave(final ChunkAccess chunkAccess, final CallbackInfoReturnable cir) { - if (chunkAccess instanceof ChunkAccessExt ext) { - ext.applyAndClearLazyUnsaved(); - } - } - - /** - * This is for the code-path taken when saving chunk upon pausing the game or when - * running a save command without the "flush" flag. - */ @Inject(method = "saveAllChunks", at = {@At(value = "HEAD")}) - private void beforeAsyncSave(final boolean sync, final CallbackInfo ci) { - // The sync case is handled in beforeSyncSave. - if (!sync) { - // Need to iterate this ourselves, because I can't find the hook for the save call - // inside the foreach in the method. Slightly annoying, but only happens on explicit - // save requests, so not too much of a performance worry. - visibleChunkMap.values().forEach(holder -> { - if (holder.wasAccessibleSinceLastSave()) { - final ChunkAccess chunkToSave = holder.getChunkToSave().getNow(null); - if (chunkToSave instanceof ChunkAccessExt ext) { - ext.applyAndClearLazyUnsaved(); - } + private void beforeAsyncSave(final CallbackInfo ci) { + visibleChunkMap.values().forEach(holder -> { + if (holder.wasAccessibleSinceLastSave()) { + final ChunkAccess chunkToSave = holder.getChunkToSave().getNow(null); + if (chunkToSave instanceof ChunkAccessExt ext) { + ext.applyAndClearLazyUnsaved(); } - }); - } + } + }); } } diff --git a/src/main/java/li/cil/oc2/common/util/ChunkUtils.java b/src/main/java/li/cil/oc2/common/util/ChunkUtils.java index d87369d1..5868e150 100644 --- a/src/main/java/li/cil/oc2/common/util/ChunkUtils.java +++ b/src/main/java/li/cil/oc2/common/util/ChunkUtils.java @@ -1,10 +1,15 @@ package li.cil.oc2.common.util; +import li.cil.oc2.api.API; import net.minecraft.core.BlockPos; import net.minecraft.core.SectionPos; import net.minecraft.world.level.Level; import net.minecraft.world.level.chunk.ChunkAccess; +import net.minecraftforge.event.world.ChunkEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; +@Mod.EventBusSubscriber(modid = API.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE) public final class ChunkUtils { /** * This will mark a chunk unsaved lazily, right before an attempt to save it would be made due @@ -60,4 +65,11 @@ public final class ChunkUtils { setLazyUnsaved(level.getChunk(chunkX, chunkZ)); } } + + @SubscribeEvent + public static void handleChunkUnload(final ChunkEvent.Unload event) { + if (event.getChunk() instanceof ChunkAccessExt ext) { + ext.applyAndClearLazyUnsaved(); + } + } } diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index b227795a..32bbd12d 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -17,7 +17,7 @@ This mod uses the Terminus Font under the Open Font License. The full license ca [[dependencies.oc2]] modId = "forge" mandatory = true -versionRange = "[39.0.19,)" +versionRange = "[39.0.63,)" ordering = "NONE" side = "BOTH" [[dependencies.oc2]]