Skip to content

Commit f8899d3

Browse files
committed
Update Forge and simplify mixin stuff.
1 parent 7be40b0 commit f8899d3

File tree

4 files changed

+22
-43
lines changed

4 files changed

+22
-43
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
org.gradle.jvmargs=-Xmx3G
44
org.gradle.daemon=false
55

6-
forge_version=39.0.19
6+
forge_version=39.0.63
77

88
semver=0.0.0
99

src/main/java/li/cil/oc2/common/mixin/ChunkMapMixin.java

Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@
1414
import org.spongepowered.asm.mixin.injection.At;
1515
import org.spongepowered.asm.mixin.injection.Inject;
1616
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
17-
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
1817

1918
import java.nio.file.Path;
20-
import java.util.concurrent.CompletableFuture;
2119

2220
/**
2321
* Hooks into {@link ChunkMap} saving code-paths for "hard" save operations.
@@ -51,46 +49,15 @@ public ChunkMapMixin(final Path path, final DataFixer dataFixer, final boolean s
5149
super(path, dataFixer, sync);
5250
}
5351

54-
/**
55-
* This is for the code-path taken when a chunk is being unloaded.
56-
*/
57-
@Inject(method = "lambda$scheduleUnload$11", at = {@At(value = "INVOKE", target = "Lnet/minecraft/server/level/ChunkMap;save(Lnet/minecraft/world/level/chunk/ChunkAccess;)Z")})
58-
private void beforeSaveOnUnload(final ChunkHolder chunkHolder, final CompletableFuture<?> chunkToSave, final long chunkId, final ChunkAccess chunkAccess, final CallbackInfo ci) {
59-
if (chunkAccess instanceof ChunkAccessExt ext) {
60-
ext.applyAndClearLazyUnsaved();
61-
}
62-
}
63-
64-
/**
65-
* This is for the code-path taken when saving all chunks upon server shutdown or when
66-
* running a save command with the "flush" flag.
67-
*/
68-
@Inject(method = "lambda$saveAllChunks$8", at = {@At(value = "HEAD")})
69-
private static void beforeSyncSave(final ChunkAccess chunkAccess, final CallbackInfoReturnable<Boolean> cir) {
70-
if (chunkAccess instanceof ChunkAccessExt ext) {
71-
ext.applyAndClearLazyUnsaved();
72-
}
73-
}
74-
75-
/**
76-
* This is for the code-path taken when saving chunk upon pausing the game or when
77-
* running a save command without the "flush" flag.
78-
*/
7952
@Inject(method = "saveAllChunks", at = {@At(value = "HEAD")})
80-
private void beforeAsyncSave(final boolean sync, final CallbackInfo ci) {
81-
// The sync case is handled in beforeSyncSave.
82-
if (!sync) {
83-
// Need to iterate this ourselves, because I can't find the hook for the save call
84-
// inside the foreach in the method. Slightly annoying, but only happens on explicit
85-
// save requests, so not too much of a performance worry.
86-
visibleChunkMap.values().forEach(holder -> {
87-
if (holder.wasAccessibleSinceLastSave()) {
88-
final ChunkAccess chunkToSave = holder.getChunkToSave().getNow(null);
89-
if (chunkToSave instanceof ChunkAccessExt ext) {
90-
ext.applyAndClearLazyUnsaved();
91-
}
53+
private void beforeAsyncSave(final CallbackInfo ci) {
54+
visibleChunkMap.values().forEach(holder -> {
55+
if (holder.wasAccessibleSinceLastSave()) {
56+
final ChunkAccess chunkToSave = holder.getChunkToSave().getNow(null);
57+
if (chunkToSave instanceof ChunkAccessExt ext) {
58+
ext.applyAndClearLazyUnsaved();
9259
}
93-
});
94-
}
60+
}
61+
});
9562
}
9663
}

src/main/java/li/cil/oc2/common/util/ChunkUtils.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
package li.cil.oc2.common.util;
22

3+
import li.cil.oc2.api.API;
34
import net.minecraft.core.BlockPos;
45
import net.minecraft.core.SectionPos;
56
import net.minecraft.world.level.Level;
67
import net.minecraft.world.level.chunk.ChunkAccess;
8+
import net.minecraftforge.event.world.ChunkEvent;
9+
import net.minecraftforge.eventbus.api.SubscribeEvent;
10+
import net.minecraftforge.fml.common.Mod;
711

12+
@Mod.EventBusSubscriber(modid = API.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE)
813
public final class ChunkUtils {
914
/**
1015
* This will mark a chunk unsaved lazily, right before an attempt to save it would be made due
@@ -60,4 +65,11 @@ public static void setLazyUnsaved(final Level level, final BlockPos blockPos) {
6065
setLazyUnsaved(level.getChunk(chunkX, chunkZ));
6166
}
6267
}
68+
69+
@SubscribeEvent
70+
public static void handleChunkUnload(final ChunkEvent.Unload event) {
71+
if (event.getChunk() instanceof ChunkAccessExt ext) {
72+
ext.applyAndClearLazyUnsaved();
73+
}
74+
}
6375
}

src/main/resources/META-INF/mods.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ This mod uses the Terminus Font under the Open Font License. The full license ca
1717
[[dependencies.oc2]]
1818
modId = "forge"
1919
mandatory = true
20-
versionRange = "[39.0.19,)"
20+
versionRange = "[39.0.63,)"
2121
ordering = "NONE"
2222
side = "BOTH"
2323
[[dependencies.oc2]]

0 commit comments

Comments
 (0)