Skip to content

Commit

Permalink
Change logic of worldgen saved data
Browse files Browse the repository at this point in the history
  • Loading branch information
lukebemish committed Dec 8, 2023
1 parent a61862a commit 13923c4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,33 @@

public class OreGenMapSavedData extends SavedData {
public static final String DATA_KEY = ExcavatedVariants.MOD_ID + ":ore_replacement";
public final Object2IntMap<ChunkKey> edgeCount;
public final Set<ChunkKey> ranMap = Collections.synchronizedSet(new HashSet<>());
private final Object2IntMap<ChunkKey> edgeCount;
private final Set<ChunkKey> ranMap = Collections.synchronizedSet(new HashSet<>());

public OreGenMapSavedData() {
Object2IntMap<ChunkKey> edgeMap = new Object2IntOpenHashMap<>();
edgeMap.defaultReturnValue(0);
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 13923c4

Please sign in to comment.