From 13923c4b23689ea89ed02a04625032aa342b19ed Mon Sep 17 00:00:00 2001 From: Luke Bemish Date: Fri, 8 Dec 2023 16:42:07 +0000 Subject: [PATCH] Change logic of worldgen saved data --- .../impl/worldgen/OreGenMapSavedData.java | 22 +++++++++++++++++-- .../impl/worldgen/OreReplacer.java | 12 +++++----- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/common/src/main/java/dev/lukebemish/excavatedvariants/impl/worldgen/OreGenMapSavedData.java b/common/src/main/java/dev/lukebemish/excavatedvariants/impl/worldgen/OreGenMapSavedData.java index 029e39f..0d25313 100644 --- a/common/src/main/java/dev/lukebemish/excavatedvariants/impl/worldgen/OreGenMapSavedData.java +++ b/common/src/main/java/dev/lukebemish/excavatedvariants/impl/worldgen/OreGenMapSavedData.java @@ -21,8 +21,8 @@ public class OreGenMapSavedData extends SavedData { public static final String DATA_KEY = ExcavatedVariants.MOD_ID + ":ore_replacement"; - public final Object2IntMap edgeCount; - public final Set ranMap = Collections.synchronizedSet(new HashSet<>()); + private final Object2IntMap edgeCount; + private final Set ranMap = Collections.synchronizedSet(new HashSet<>()); public OreGenMapSavedData() { Object2IntMap edgeMap = new Object2IntOpenHashMap<>(); @@ -30,6 +30,24 @@ public OreGenMapSavedData() { this.edgeCount = Object2IntMaps.synchronize(edgeMap); } + public int getEdgeCount(ChunkKey chunkPos) { + return edgeCount.getInt(chunkPos); + } + + public void setEdgeCount(ChunkKey chunkPos, int count) { + edgeCount.put(chunkPos, count); + this.setDirty(); + } + + public void chunkRan(ChunkKey chunkPos) { + ranMap.add(chunkPos); + this.setDirty(); + } + + public boolean didChunkRun(ChunkKey chunkPos) { + return ranMap.contains(chunkPos); + } + public record ChunkKey(int x, int z) {} private static OreGenMapSavedData load(CompoundTag tag) { diff --git a/common/src/main/java/dev/lukebemish/excavatedvariants/impl/worldgen/OreReplacer.java b/common/src/main/java/dev/lukebemish/excavatedvariants/impl/worldgen/OreReplacer.java index 3d2aea1..aa67d76 100644 --- a/common/src/main/java/dev/lukebemish/excavatedvariants/impl/worldgen/OreReplacer.java +++ b/common/src/main/java/dev/lukebemish/excavatedvariants/impl/worldgen/OreReplacer.java @@ -48,19 +48,19 @@ public boolean modifyUnmodifiedNeighboringChunks(WorldGenLevel level, BlockPos p newPos.setX(pos.getX() + xs[i] * 16); newPos.setZ(pos.getZ() + zs[i] * 16); OreGenMapSavedData.ChunkKey chunkPos = new OreGenMapSavedData.ChunkKey(newPos.getX(), newPos.getZ()); - data.edgeCount.put(chunkPos, data.edgeCount.getInt(chunkPos) + 1); - if (data.edgeCount.getInt(chunkPos) == 8 && data.ranMap.contains(chunkPos)) { + data.setEdgeCount(chunkPos, data.getEdgeCount(chunkPos) + 1); + if (data.getEdgeCount(chunkPos) == 8 && data.didChunkRun(chunkPos)) { ChunkAccess chunkAccess = level.getChunk(newPos); modifyChunk(chunkAccess, minY, maxY); - data.edgeCount.put(chunkPos, 9); + data.setEdgeCount(chunkPos, 9); } } OreGenMapSavedData.ChunkKey chunkPos = new OreGenMapSavedData.ChunkKey(pos.getX(), pos.getZ()); - data.ranMap.add(chunkPos); - if (data.edgeCount.getInt(chunkPos) == 8) { + data.chunkRan(chunkPos); + if (data.getEdgeCount(chunkPos) == 8) { ChunkAccess chunkAccess = level.getChunk(pos); modifyChunk(chunkAccess, minY, maxY); - data.edgeCount.put(chunkPos, 9); + data.setEdgeCount(chunkPos, 9); } return true; }