mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-22 16:18:32 +00:00
Fix carving issues
This commit is contained in:
@@ -19,13 +19,19 @@ import java.util.Map;
|
|||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class CarverCache {
|
public class CarverCache {
|
||||||
|
|
||||||
|
private final World w;
|
||||||
private final Map<Long, List<Worm.WormPoint>> carvers = new HashMap<>();
|
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();
|
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();
|
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());
|
long seed = MathUtil.getCarverChunkSeed(chunkX, chunkZ, w.getSeed());
|
||||||
carver.getSeedVar().setValue(seed);
|
carver.getSeedVar().setValue(seed);
|
||||||
Random r = new FastRandom(seed);
|
Random r = new FastRandom(seed);
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import net.jafama.FastMath;
|
|||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
import org.polydev.gaea.generation.GenerationPhase;
|
import org.polydev.gaea.generation.GenerationPhase;
|
||||||
import org.polydev.gaea.math.MathUtil;
|
|
||||||
import org.polydev.gaea.math.Range;
|
import org.polydev.gaea.math.Range;
|
||||||
import org.polydev.gaea.util.FastRandom;
|
import org.polydev.gaea.util.FastRandom;
|
||||||
import org.polydev.gaea.world.carving.Carver;
|
import org.polydev.gaea.world.carving.Carver;
|
||||||
@@ -20,7 +19,9 @@ import parsii.eval.Scope;
|
|||||||
import parsii.eval.Variable;
|
import parsii.eval.Variable;
|
||||||
import parsii.tokenizer.ParseException;
|
import parsii.tokenizer.ParseException;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.function.BiConsumer;
|
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[] start; // 0, 1, 2 = x, y, z.
|
||||||
private final double[] mutate; // 0, 1, 2 = x, y, z. 3 = radius.
|
private final double[] mutate; // 0, 1, 2 = x, y, z. 3 = radius.
|
||||||
private final Range length;
|
private final Range length;
|
||||||
private final int hash;
|
private final long hash;
|
||||||
private final int topCut;
|
private final int topCut;
|
||||||
private final int bottomCut;
|
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 CarverTemplate config;
|
||||||
private final Expression xRad;
|
private final Expression xRad;
|
||||||
private final Expression yRad;
|
private final Expression yRad;
|
||||||
@@ -41,14 +39,14 @@ public class UserDefinedCarver extends Carver {
|
|||||||
private final Variable lengthVar;
|
private final Variable lengthVar;
|
||||||
private final Variable position;
|
private final Variable position;
|
||||||
private final Variable seedVar;
|
private final Variable seedVar;
|
||||||
private final Range height;
|
private final Map<World, CarverCache> cacheMap = new HashMap<>();
|
||||||
private final double sixtyFourSq = FastMath.pow(64, 2);
|
private double step = 2;
|
||||||
private final CarverCache cache = new CarverCache();
|
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());
|
super(height.getMin(), height.getMax());
|
||||||
this.length = length;
|
this.length = length;
|
||||||
this.height = height;
|
|
||||||
this.start = start;
|
this.start = start;
|
||||||
this.mutate = mutate;
|
this.mutate = mutate;
|
||||||
this.hash = hash;
|
this.hash = hash;
|
||||||
@@ -102,17 +100,16 @@ public class UserDefinedCarver extends Carver {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void carve(int chunkX, int chunkZ, World w, BiConsumer<Vector, CarvingType> consumer) {
|
public void carve(int chunkX, int chunkZ, World w, BiConsumer<Vector, CarvingType> consumer) {
|
||||||
|
CarverCache cache = cacheMap.computeIfAbsent(w, CarverCache::new);
|
||||||
int carvingRadius = getCarvingRadius();
|
int carvingRadius = getCarvingRadius();
|
||||||
for(int x = chunkX - carvingRadius; x <= chunkX + carvingRadius; x++) {
|
for(int x = chunkX - carvingRadius; x <= chunkX + carvingRadius; x++) {
|
||||||
for(int z = chunkZ - carvingRadius; z <= chunkZ + carvingRadius; z++) {
|
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, this).forEach(point -> {
|
||||||
cache.getPoints(x, z, w, this).forEach(point -> {
|
Vector origin = point.getOrigin();
|
||||||
Vector origin = point.getOrigin();
|
if(FastMath.floorDiv(origin.getBlockX(), 16) != chunkX && FastMath.floorDiv(origin.getBlockZ(), 16) != chunkZ)
|
||||||
if(FastMath.floorDiv(origin.getBlockX(), 16) != chunkX && FastMath.floorDiv(origin.getBlockZ(), 16) != chunkZ)
|
return;
|
||||||
return;
|
point.carve(chunkX, chunkZ, consumer);
|
||||||
point.carve(chunkX, chunkZ, consumer);
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -123,7 +120,7 @@ public class UserDefinedCarver extends Carver {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isChunkCarved(World w, int chunkX, int chunkZ, Random random) {
|
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) {
|
if(conf.getCarvers().get(this) != null) {
|
||||||
return new FastRandom(random.nextLong() + hash).nextInt(100) < conf.getCarvers().get(this);
|
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.carving.UserDefinedCarver;
|
||||||
import com.dfsek.terra.config.base.ConfigPack;
|
import com.dfsek.terra.config.base.ConfigPack;
|
||||||
import com.dfsek.terra.config.templates.CarverTemplate;
|
import com.dfsek.terra.config.templates.CarverTemplate;
|
||||||
|
import org.polydev.gaea.math.MathUtil;
|
||||||
import parsii.tokenizer.ParseException;
|
import parsii.tokenizer.ParseException;
|
||||||
|
|
||||||
import java.util.Arrays;
|
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[] start = new double[] {config.getStartX(), config.getStartY(), config.getStartZ()};
|
||||||
double[] mutate = new double[] {config.getMutateX(), config.getMutateY(), config.getMutateZ()};
|
double[] mutate = new double[] {config.getMutateX(), config.getMutateY(), config.getMutateZ()};
|
||||||
List<String> radius = Arrays.asList(config.getRadMX(), config.getRadMY(), config.getRadMZ());
|
List<String> radius = Arrays.asList(config.getRadMX(), config.getRadMY(), config.getRadMZ());
|
||||||
int hash = config.getID().hashCode();
|
long hash = MathUtil.hashToLong(config.getID());
|
||||||
UserDefinedCarver carver;
|
UserDefinedCarver carver;
|
||||||
try {
|
try {
|
||||||
carver = new UserDefinedCarver(config.getHeight(), config.getLength(), start, mutate, radius, pack.getVarScope(), hash, config.getCutTop(), config.getCutBottom(), config);
|
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