mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 10:30:42 +00:00
Fix carving issues
This commit is contained in:
@@ -19,13 +19,19 @@ import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
public class CarverCache {
|
||||
|
||||
private final World w;
|
||||
private final Map<Long, List<Worm.WormPoint>> carvers = new HashMap<>();
|
||||
|
||||
public List<Worm.WormPoint> getPoints(int chunkX, int chunkZ, World w, UserDefinedCarver carver) {
|
||||
public CarverCache(World w) {
|
||||
this.w = w;
|
||||
}
|
||||
|
||||
public List<Worm.WormPoint> getPoints(int chunkX, int chunkZ, UserDefinedCarver carver) {
|
||||
if(carvers.size() > PluginConfig.getCacheSize() * 2) carvers.clear();
|
||||
return carvers.computeIfAbsent((((long) chunkX) << 32) | (chunkZ & 0xffffffffL) ^ w.getSeed(), key -> {
|
||||
return carvers.computeIfAbsent((((long) chunkX) << 32) | (chunkZ & 0xffffffffL), key -> {
|
||||
TerraBiomeGrid grid = TerraWorld.getWorld(w).getGrid();
|
||||
if(carver.isChunkCarved(w, chunkX, chunkZ, new FastRandom(MathUtil.hashToLong(carver.getClass().getName() + "_" + chunkX + "&" + chunkZ)))) {
|
||||
if(carver.isChunkCarved(w, chunkX, chunkZ, new FastRandom(MathUtil.getCarverChunkSeed(chunkX, chunkZ, w.getSeed() + carver.hashCode())))) {
|
||||
long seed = MathUtil.getCarverChunkSeed(chunkX, chunkZ, w.getSeed());
|
||||
carver.getSeedVar().setValue(seed);
|
||||
Random r = new FastRandom(seed);
|
||||
|
||||
@@ -9,7 +9,6 @@ import net.jafama.FastMath;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.polydev.gaea.generation.GenerationPhase;
|
||||
import org.polydev.gaea.math.MathUtil;
|
||||
import org.polydev.gaea.math.Range;
|
||||
import org.polydev.gaea.util.FastRandom;
|
||||
import org.polydev.gaea.world.carving.Carver;
|
||||
@@ -20,7 +19,9 @@ import parsii.eval.Scope;
|
||||
import parsii.eval.Variable;
|
||||
import parsii.tokenizer.ParseException;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
@@ -28,12 +29,9 @@ public class UserDefinedCarver extends Carver {
|
||||
private final double[] start; // 0, 1, 2 = x, y, z.
|
||||
private final double[] mutate; // 0, 1, 2 = x, y, z. 3 = radius.
|
||||
private final Range length;
|
||||
private final int hash;
|
||||
private final long hash;
|
||||
private final int topCut;
|
||||
private final int bottomCut;
|
||||
private double step = 2;
|
||||
private Range recalc = new Range(8, 10);
|
||||
private double recalcMagnitude = 3;
|
||||
private final CarverTemplate config;
|
||||
private final Expression xRad;
|
||||
private final Expression yRad;
|
||||
@@ -41,14 +39,14 @@ public class UserDefinedCarver extends Carver {
|
||||
private final Variable lengthVar;
|
||||
private final Variable position;
|
||||
private final Variable seedVar;
|
||||
private final Range height;
|
||||
private final double sixtyFourSq = FastMath.pow(64, 2);
|
||||
private final CarverCache cache = new CarverCache();
|
||||
private final Map<World, CarverCache> cacheMap = new HashMap<>();
|
||||
private double step = 2;
|
||||
private Range recalc = new Range(8, 10);
|
||||
private double recalcMagnitude = 3;
|
||||
|
||||
public UserDefinedCarver(Range height, Range length, double[] start, double[] mutate, List<String> radii, Scope parent, int hash, int topCut, int bottomCut, CarverTemplate config) throws ParseException {
|
||||
public UserDefinedCarver(Range height, Range length, double[] start, double[] mutate, List<String> radii, Scope parent, long hash, int topCut, int bottomCut, CarverTemplate config) throws ParseException {
|
||||
super(height.getMin(), height.getMax());
|
||||
this.length = length;
|
||||
this.height = height;
|
||||
this.start = start;
|
||||
this.mutate = mutate;
|
||||
this.hash = hash;
|
||||
@@ -102,17 +100,16 @@ public class UserDefinedCarver extends Carver {
|
||||
|
||||
@Override
|
||||
public void carve(int chunkX, int chunkZ, World w, BiConsumer<Vector, CarvingType> consumer) {
|
||||
CarverCache cache = cacheMap.computeIfAbsent(w, CarverCache::new);
|
||||
int carvingRadius = getCarvingRadius();
|
||||
for(int x = chunkX - carvingRadius; x <= chunkX + carvingRadius; x++) {
|
||||
for(int z = chunkZ - carvingRadius; z <= chunkZ + carvingRadius; z++) {
|
||||
if(isChunkCarved(w, x, z, new FastRandom(MathUtil.hashToLong(this.getClass().getName() + "_" + x + "&" + z)))) {
|
||||
cache.getPoints(x, z, w, this).forEach(point -> {
|
||||
Vector origin = point.getOrigin();
|
||||
if(FastMath.floorDiv(origin.getBlockX(), 16) != chunkX && FastMath.floorDiv(origin.getBlockZ(), 16) != chunkZ)
|
||||
return;
|
||||
point.carve(chunkX, chunkZ, consumer);
|
||||
});
|
||||
}
|
||||
cache.getPoints(x, z, this).forEach(point -> {
|
||||
Vector origin = point.getOrigin();
|
||||
if(FastMath.floorDiv(origin.getBlockX(), 16) != chunkX && FastMath.floorDiv(origin.getBlockZ(), 16) != chunkZ)
|
||||
return;
|
||||
point.carve(chunkX, chunkZ, consumer);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -123,7 +120,7 @@ public class UserDefinedCarver extends Carver {
|
||||
|
||||
@Override
|
||||
public boolean isChunkCarved(World w, int chunkX, int chunkZ, Random random) {
|
||||
BiomeTemplate conf = ((UserDefinedBiome) TerraWorld.getWorld(w).getGrid().getBiome(chunkX << 4, chunkZ << 4, GenerationPhase.POPULATE)).getConfig();
|
||||
BiomeTemplate conf = ((UserDefinedBiome) TerraWorld.getWorld(w).getGrid().getBiome((chunkX << 4) + 8, (chunkZ << 4) + 8, GenerationPhase.POPULATE)).getConfig();
|
||||
if(conf.getCarvers().get(this) != null) {
|
||||
return new FastRandom(random.nextLong() + hash).nextInt(100) < conf.getCarvers().get(this);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.terra.carving.UserDefinedCarver;
|
||||
import com.dfsek.terra.config.base.ConfigPack;
|
||||
import com.dfsek.terra.config.templates.CarverTemplate;
|
||||
import org.polydev.gaea.math.MathUtil;
|
||||
import parsii.tokenizer.ParseException;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -21,7 +22,7 @@ public class CarverFactory implements TerraFactory<CarverTemplate, UserDefinedCa
|
||||
double[] start = new double[] {config.getStartX(), config.getStartY(), config.getStartZ()};
|
||||
double[] mutate = new double[] {config.getMutateX(), config.getMutateY(), config.getMutateZ()};
|
||||
List<String> radius = Arrays.asList(config.getRadMX(), config.getRadMY(), config.getRadMZ());
|
||||
int hash = config.getID().hashCode();
|
||||
long hash = MathUtil.hashToLong(config.getID());
|
||||
UserDefinedCarver carver;
|
||||
try {
|
||||
carver = new UserDefinedCarver(config.getHeight(), config.getLength(), start, mutate, radius, pack.getVarScope(), hash, config.getCutTop(), config.getCutBottom(), config);
|
||||
|
||||
Reference in New Issue
Block a user