Skip to content

Commit

Permalink
Hexmap chunk managment enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
paulevsGitch committed Feb 14, 2022
1 parent a5c3c97 commit 51e787c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 21 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ loader_version= 0.12.12
fabric_version = 0.46.2+1.18

# Mod Properties
mod_version = 1.3.1
mod_version = 1.3.2
maven_group = ru.bclib
archives_base_name = bclib

Expand Down
28 changes: 8 additions & 20 deletions src/main/java/ru/bclib/world/generator/map/hex/HexBiomeMap.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ru.bclib.world.generator.map.hex;

import net.minecraft.world.level.ChunkPos;
import ru.bclib.interfaces.BiomeChunk;
import ru.bclib.interfaces.BiomeMap;
import ru.bclib.interfaces.TriConsumer;
Expand All @@ -18,12 +19,10 @@ public class HexBiomeMap implements BiomeMap {
private static final float COEF_HALF = COEF * 0.5F;
private static final float SIN = (float) Math.sin(0.4);
private static final float COS = (float) Math.cos(0.4);
private static final Random RANDOM = new Random();
private static final float[] EDGE_CIRCLE_X;
private static final float[] EDGE_CIRCLE_Z;

private final HashMap<Point, HexBiomeChunk> chunks = new HashMap<>();
private final Point selector = new Point();
private final HashMap<ChunkPos, HexBiomeChunk> chunks = new HashMap<>();
private final BiomePicker picker;

private final OpenSimplexNoise[] noises = new OpenSimplexNoise[2];
Expand Down Expand Up @@ -75,26 +74,15 @@ public BCLBiome getBiome(double x, double y, double z) {

@Override
public BiomeChunk getChunk(int cx, int cz, boolean update) {
HexBiomeChunk chunk;

synchronized (selector) {
selector.setLocation(cx, cz);
chunk = chunks.get(selector);
}

if (chunk == null) {
synchronized (RANDOM) {
RANDOM.setSeed(MHelper.getSeed(seed, cx, cz));
chunk = new HexBiomeChunk(RANDOM, picker);
}
chunks.put(new Point(cx, cz), chunk);

ChunkPos pos = new ChunkPos(cx, cz);
return chunks.computeIfAbsent(pos, i -> {
Random random = new Random(MHelper.getSeed(seed, cx, cz));
HexBiomeChunk chunk = new HexBiomeChunk(random, picker);
if (update && processor != null) {
processor.accept(cx, cz, chunk.getSide());
}
}

return chunk;
return chunk;
});
}

@Override
Expand Down

0 comments on commit 51e787c

Please sign in to comment.