mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-03 00:15:35 +00:00
synchronize maps
This commit is contained in:
parent
d327909389
commit
764344b4ef
@ -5,11 +5,12 @@ import com.dfsek.terra.generation.config.NoiseBuilder;
|
||||
import com.dfsek.terra.generation.config.WorldGenerator;
|
||||
import parsii.eval.Scope;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class GeneratorBuilder {
|
||||
private final Map<Long, WorldGenerator> gens = new HashMap<>();
|
||||
private final Map<Long, WorldGenerator> gens = Collections.synchronizedMap(new HashMap<>());
|
||||
|
||||
private String noiseEquation;
|
||||
|
||||
@ -35,8 +36,10 @@ public class GeneratorBuilder {
|
||||
|
||||
|
||||
public WorldGenerator build(long seed) {
|
||||
synchronized(gens) {
|
||||
return gens.computeIfAbsent(seed, k -> new WorldGenerator(seed, noiseEquation, elevationEquation, varScope, noiseBuilderMap, palettes, slantPalettes, interpolateElevation, noise2d, base, biomeNoise.build((int) seed)));
|
||||
}
|
||||
}
|
||||
|
||||
public void setBiomeNoise(NoiseBuilder biomeNoise) {
|
||||
this.biomeNoise = biomeNoise;
|
||||
|
@ -10,6 +10,7 @@ import com.google.common.cache.LoadingCache;
|
||||
import net.jafama.FastMath;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@ -18,17 +19,21 @@ public class SamplerCache {
|
||||
private final TerraPlugin main;
|
||||
|
||||
public SamplerCache(TerraPlugin main) {
|
||||
containerMap = new HashMap<>();
|
||||
containerMap = Collections.synchronizedMap(new HashMap<>());
|
||||
this.main = main;
|
||||
}
|
||||
|
||||
public Sampler get(World world, int x, int z) {
|
||||
synchronized(containerMap) {
|
||||
return containerMap.computeIfAbsent(world.getSeed(), seed -> new Container(world)).get(x, z);
|
||||
}
|
||||
}
|
||||
|
||||
public Sampler getChunk(World world, int chunkX, int chunkZ) {
|
||||
synchronized(containerMap) {
|
||||
return containerMap.computeIfAbsent(world.getSeed(), seed -> new Container(world)).getChunk(chunkX, chunkZ);
|
||||
}
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
containerMap.clear();
|
||||
|
Loading…
x
Reference in New Issue
Block a user