mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 02:20:57 +00:00
add 2d biomes support
This commit is contained in:
@@ -21,4 +21,7 @@ public interface Generator {
|
||||
*/
|
||||
Palette<BlockData> getPalette(int y);
|
||||
|
||||
boolean is2d();
|
||||
|
||||
double get2dBase();
|
||||
}
|
||||
|
||||
@@ -27,9 +27,29 @@ public class GeneratorBuilder {
|
||||
|
||||
private boolean interpolateElevation;
|
||||
|
||||
private boolean noise2d;
|
||||
|
||||
private double base;
|
||||
|
||||
|
||||
public WorldGenerator build(long seed) {
|
||||
return gens.computeIfAbsent(seed, k -> new WorldGenerator(seed, noiseEquation, elevationEquation, varScope, noiseBuilderMap, palettes, slantPalettes, interpolateElevation));
|
||||
return gens.computeIfAbsent(seed, k -> new WorldGenerator(seed, noiseEquation, elevationEquation, varScope, noiseBuilderMap, palettes, slantPalettes, interpolateElevation, noise2d, base));
|
||||
}
|
||||
|
||||
public boolean isNoise2d() {
|
||||
return noise2d;
|
||||
}
|
||||
|
||||
public void setNoise2d(boolean noise2d) {
|
||||
this.noise2d = noise2d;
|
||||
}
|
||||
|
||||
public double getBase() {
|
||||
return base;
|
||||
}
|
||||
|
||||
public void setBase(double base) {
|
||||
this.base = base;
|
||||
}
|
||||
|
||||
public String getNoiseEquation() {
|
||||
|
||||
@@ -23,6 +23,8 @@ public class BiomeFactory implements TerraFactory<BiomeTemplate, UserDefinedBiom
|
||||
generatorBuilder.setSlantPalettes(template.getSlantPalette());
|
||||
generatorBuilder.setVarScope(pack.getVarScope());
|
||||
generatorBuilder.setInterpolateElevation(template.interpolateElevation());
|
||||
generatorBuilder.setNoise2d(template.isNoise2d());
|
||||
generatorBuilder.setBase(template.getNoise2dBase());
|
||||
|
||||
|
||||
return new UserDefinedBiome(template.getVanilla(), generatorBuilder, template, pack);
|
||||
|
||||
@@ -41,6 +41,16 @@ public class BiomeTemplate extends AbstractableTemplate implements ValidatedConf
|
||||
@Default
|
||||
private String extend = null;
|
||||
|
||||
@Value("noise-2d.enable")
|
||||
@Default
|
||||
@Abstractable
|
||||
private boolean noise2d = false;
|
||||
|
||||
@Value("noise-2d.base")
|
||||
@Default
|
||||
@Abstractable
|
||||
private double noise2dBase = 64;
|
||||
|
||||
@Value("palette")
|
||||
@Abstractable
|
||||
private PaletteHolder palette;
|
||||
@@ -217,6 +227,14 @@ public class BiomeTemplate extends AbstractableTemplate implements ValidatedConf
|
||||
return oreHolder;
|
||||
}
|
||||
|
||||
public boolean isNoise2d() {
|
||||
return noise2d;
|
||||
}
|
||||
|
||||
public double getNoise2dBase() {
|
||||
return noise2dBase;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validate() throws ValidationException {
|
||||
Parser tester = new Parser();
|
||||
|
||||
@@ -29,8 +29,17 @@ public class WorldGenerator implements Generator {
|
||||
private final Variable elevationXVar;
|
||||
private final Variable elevationZVar;
|
||||
private final boolean elevationInterpolation;
|
||||
private final boolean noise2d;
|
||||
private final double base;
|
||||
|
||||
public WorldGenerator(long seed, String equation, String elevateEquation, Scope vScope, Map<String, NoiseBuilder> noiseBuilders, PaletteHolder palettes, PaletteHolder slantPalettes, boolean elevationInterpolation, boolean noise2d, double base) {
|
||||
this.palettes = palettes;
|
||||
this.slantPalettes = slantPalettes;
|
||||
|
||||
this.elevationInterpolation = elevationInterpolation;
|
||||
this.noise2d = noise2d;
|
||||
this.base = base;
|
||||
|
||||
public WorldGenerator(long seed, String equation, String elevateEquation, Scope vScope, Map<String, NoiseBuilder> noiseBuilders, PaletteHolder palettes, PaletteHolder slantPalettes, boolean elevationInterpolation) {
|
||||
Parser p = new Parser();
|
||||
p.registerFunction("rand", new RandomFunction());
|
||||
Parser ep = new Parser();
|
||||
@@ -38,14 +47,11 @@ public class WorldGenerator implements Generator {
|
||||
|
||||
Scope s = new Scope().withParent(vScope);
|
||||
xVar = s.create("x");
|
||||
yVar = s.create("y");
|
||||
if(!noise2d) yVar = s.create("y");
|
||||
else yVar = null;
|
||||
zVar = s.create("z");
|
||||
s.create("seed").setValue(seed);
|
||||
|
||||
this.palettes = palettes;
|
||||
this.slantPalettes = slantPalettes;
|
||||
|
||||
this.elevationInterpolation = elevationInterpolation;
|
||||
|
||||
for(Map.Entry<String, NoiseBuilder> e : noiseBuilders.entrySet()) {
|
||||
switch(e.getValue().getDimensions()) {
|
||||
@@ -86,7 +92,7 @@ public class WorldGenerator implements Generator {
|
||||
@Override
|
||||
public synchronized double getNoise(int x, int y, int z) {
|
||||
xVar.setValue(x);
|
||||
yVar.setValue(y);
|
||||
if(!noise2d) yVar.setValue(y);
|
||||
zVar.setValue(z);
|
||||
return noiseExp.evaluate();
|
||||
}
|
||||
@@ -101,6 +107,16 @@ public class WorldGenerator implements Generator {
|
||||
return palettes.getPalette(y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean is2d() {
|
||||
return noise2d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double get2dBase() {
|
||||
return base;
|
||||
}
|
||||
|
||||
public Palette<BlockData> getSlantPalette(int y) {
|
||||
return slantPalettes.getPalette(y);
|
||||
}
|
||||
|
||||
@@ -2,15 +2,15 @@ package com.dfsek.terra.generation.math;
|
||||
|
||||
import com.dfsek.terra.api.platform.world.World;
|
||||
import com.dfsek.terra.biome.grid.master.TerraBiomeGrid;
|
||||
import com.dfsek.terra.generation.math.interpolation.ChunkInterpolator3;
|
||||
import com.dfsek.terra.generation.math.interpolation.ChunkInterpolator;
|
||||
import net.jafama.FastMath;
|
||||
|
||||
public class Sampler {
|
||||
private final ChunkInterpolator3 interpolator;
|
||||
private final ChunkInterpolator interpolator;
|
||||
private final ElevationInterpolator elevationInterpolator;
|
||||
|
||||
public Sampler(int x, int z, TerraBiomeGrid grid, World world, int elevationSmooth, int generationSmooth) {
|
||||
this.interpolator = new ChunkInterpolator3(world, x, z, grid, generationSmooth);
|
||||
this.interpolator = new ChunkInterpolator(world, x, z, grid, generationSmooth);
|
||||
this.elevationInterpolator = new ElevationInterpolator(world, x, z, grid, elevationSmooth);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import net.jafama.FastMath;
|
||||
* Class to abstract away the 16 Interpolators needed to generate a chunk.<br>
|
||||
* Contains method to get interpolated noise at a coordinate within the chunk.
|
||||
*/
|
||||
public class ChunkInterpolator3 {
|
||||
public class ChunkInterpolator {
|
||||
private final Interpolator3[][][] interpGrid = new Interpolator3[4][64][4];
|
||||
private final Generator[][] gens = new Generator[7][7];
|
||||
private final boolean[][] needsBiomeInterp = new boolean[5][5];
|
||||
@@ -24,7 +24,7 @@ public class ChunkInterpolator3 {
|
||||
* @param chunkZ Z coordinate of the chunk.
|
||||
* @param grid BiomeGrid to use for noise fetching.
|
||||
*/
|
||||
public ChunkInterpolator3(World w, int chunkX, int chunkZ, TerraBiomeGrid grid, int smooth) {
|
||||
public ChunkInterpolator(World w, int chunkX, int chunkZ, TerraBiomeGrid grid, int smooth) {
|
||||
int xOrigin = chunkX << 4;
|
||||
int zOrigin = chunkZ << 4;
|
||||
this.smooth = smooth;
|
||||
@@ -43,8 +43,16 @@ public class ChunkInterpolator3 {
|
||||
|
||||
for(byte x = -1; x < 6; x++) {
|
||||
for(byte z = -1; z < 6; z++) {
|
||||
for(int y = 0; y < 65; y++) {
|
||||
noiseStorage[x + 1][z + 1][y] = gens[x + 1][z + 1].getNoise((x * smooth) + xOrigin, y << 2, (z * smooth) + zOrigin);
|
||||
Generator generator = gens[x + 1][z + 1];
|
||||
if(generator.is2d()) {
|
||||
double n = generator.getNoise((x * smooth) + xOrigin, 0, (z * smooth) + zOrigin);
|
||||
for(int y = 0; y < 65; y++) {
|
||||
noiseStorage[x + 1][z + 1][y] = n + noise2dExtrude(y << 2, generator.get2dBase());
|
||||
}
|
||||
} else {
|
||||
for(int y = 0; y < 65; y++) {
|
||||
noiseStorage[x + 1][z + 1][y] = generator.getNoise((x * smooth) + xOrigin, y << 2, (z * smooth) + zOrigin);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -113,4 +121,8 @@ public class ChunkInterpolator3 {
|
||||
public double getNoise(double x, double y, double z) {
|
||||
return interpGrid[reRange(((int) x) / smooth, 3)][reRange(((int) y) / 4, 63)][reRange(((int) z) / smooth, 3)].trilerp((x % smooth) / smooth, (y % 4) / 4, (z % smooth) / smooth);
|
||||
}
|
||||
|
||||
private static double noise2dExtrude(double y, double base) {
|
||||
return ((-FastMath.pow2((y / base))) + 1);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user