Skip to content

Commit 5112922

Browse files
committed
Merge branch 'ver/1.16.5' into ver/1.17
# Conflicts: # src/main/java/org/yatopiamc/c2me/mixin/threading/chunkio/MixinThreadedAnvilChunkStorage.java
2 parents 274f81c + f608e6b commit 5112922

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/main/java/org/yatopiamc/c2me/mixin/threading/chunkio/MixinThreadedAnvilChunkStorage.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.yatopiamc.c2me.mixin.threading.chunkio;
22

3+
import com.google.common.collect.Sets;
34
import com.ibm.asyncutil.locks.AsyncNamedLock;
45
import com.mojang.datafixers.DataFixer;
56
import com.mojang.datafixers.util.Either;
@@ -42,7 +43,11 @@
4243
import org.yatopiamc.c2me.common.util.SneakyThrow;
4344

4445
import java.io.File;
46+
import java.util.HashMap;
47+
import java.util.HashSet;
48+
import java.util.Set;
4549
import java.util.concurrent.CompletableFuture;
50+
import java.util.concurrent.ConcurrentHashMap;
4651
import java.util.concurrent.ConcurrentLinkedQueue;
4752
import java.util.function.Supplier;
4853

@@ -93,16 +98,23 @@ private void onInit(CallbackInfo info) {
9398
chunkLock = AsyncNamedLock.createFair();
9499
}
95100

101+
private Set<ChunkPos> scheduledChunks = new HashSet<>();
102+
96103
/**
97104
* @author ishland
98105
* @reason async io and deserialization
99106
*/
100107
@Overwrite
101108
private CompletableFuture<Either<Chunk, ChunkHolder.Unloaded>> loadChunk(ChunkPos pos) {
109+
if (scheduledChunks == null) scheduledChunks = new HashSet<>();
110+
synchronized (scheduledChunks) {
111+
if (scheduledChunks.contains(pos)) throw new IllegalArgumentException("Already scheduled");
112+
scheduledChunks.add(pos);
113+
}
102114

103115
final CompletableFuture<NbtCompound> poiData = ((C2MECachedRegionStorage) this.pointOfInterestStorage.worker).getNbtAtAsync(pos);
104116

105-
return getUpdatedChunkNbtAtAsync(pos).thenApplyAsync(compoundTag -> {
117+
final CompletableFuture<Either<Chunk, ChunkHolder.Unloaded>> future = getUpdatedChunkNbtAtAsync(pos).thenApplyAsync(compoundTag -> {
106118
if (compoundTag != null) {
107119
try {
108120
if (compoundTag.contains("Level", 10) && compoundTag.getCompound("Level").contains("Status", 8)) {
@@ -126,6 +138,12 @@ private CompletableFuture<Either<Chunk, ChunkHolder.Unloaded>> loadChunk(ChunkPo
126138
return Either.left(new ProtoChunk(pos, UpgradeData.NO_UPGRADE_DATA, this.world));
127139
}
128140
}, this.mainThreadExecutor);
141+
future.exceptionally(throwable -> null).thenRun(() -> {
142+
synchronized (scheduledChunks) {
143+
scheduledChunks.remove(pos);
144+
}
145+
});
146+
return future;
129147

130148
// [VanillaCopy] - for reference
131149
/*

0 commit comments

Comments
 (0)