From 0a23de6413ccaa14218975d979817197301603bd Mon Sep 17 00:00:00 2001 From: Luke Bemish Date: Mon, 13 May 2024 09:23:52 -0500 Subject: [PATCH] Actually fix rare CME --- .../impl/worldgen/OreGenMapSavedData.java | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/main/java/dev/lukebemish/excavatedvariants/impl/worldgen/OreGenMapSavedData.java b/src/main/java/dev/lukebemish/excavatedvariants/impl/worldgen/OreGenMapSavedData.java index 8341bff..166c4a0 100644 --- a/src/main/java/dev/lukebemish/excavatedvariants/impl/worldgen/OreGenMapSavedData.java +++ b/src/main/java/dev/lukebemish/excavatedvariants/impl/worldgen/OreGenMapSavedData.java @@ -2,7 +2,6 @@ import dev.lukebemish.excavatedvariants.impl.ExcavatedVariants; import it.unimi.dsi.fastutil.objects.Object2IntMap; -import it.unimi.dsi.fastutil.objects.Object2IntMaps; import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import net.minecraft.core.HolderLookup; import net.minecraft.nbt.CompoundTag; @@ -11,44 +10,44 @@ import org.jspecify.annotations.NonNull; import java.util.ArrayList; -import java.util.Collections; import java.util.HashSet; import java.util.Set; public class OreGenMapSavedData extends SavedData { private static final String DATA_KEY = ExcavatedVariants.MOD_ID + "_ore_replacement"; private final Object2IntMap edgeCount; - private final Set ran = Collections.synchronizedSet(new HashSet<>()); + private final Set ran = new HashSet<>(); public OreGenMapSavedData() { Object2IntMap edgeMap = new Object2IntOpenHashMap<>(); edgeMap.defaultReturnValue(0); - this.edgeCount = Object2IntMaps.synchronize(edgeMap); + this.edgeCount = edgeMap; } - public int getEdgeCount(ChunkKey chunkPos) { + public synchronized int getEdgeCount(ChunkKey chunkPos) { return edgeCount.getInt(chunkPos); } - public void incrEdgeCount(ChunkKey chunkPos) { + public synchronized void incrEdgeCount(ChunkKey chunkPos) { edgeCount.put(chunkPos, edgeCount.getInt(chunkPos) + 1); this.setDirty(); } - public void setEdgeCount(ChunkKey chunkPos, int count) { + public synchronized void setEdgeCount(ChunkKey chunkPos, int count) { if (count == 9) { edgeCount.removeInt(chunkPos); + } else { + edgeCount.put(chunkPos, count); + this.setDirty(); } - edgeCount.put(chunkPos, count); - this.setDirty(); } - public void chunkRan(ChunkKey chunkPos) { + public synchronized void chunkRan(ChunkKey chunkPos) { ran.add(chunkPos); this.setDirty(); } - public boolean didChunkRun(ChunkKey chunkPos) { + public synchronized boolean didChunkRun(ChunkKey chunkPos) { return ran.contains(chunkPos); } @@ -86,7 +85,7 @@ public static OreGenMapSavedData getOrCreate(ServerLevelAccessor world) { } @Override - public CompoundTag save(@NonNull CompoundTag tag, HolderLookup.Provider provider) { + public synchronized CompoundTag save(@NonNull CompoundTag tag, HolderLookup.Provider provider) { ArrayList edge1 = new ArrayList<>(); ArrayList edge2 = new ArrayList<>(); ArrayList edge3 = new ArrayList<>();