mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-09 09:16:34 +00:00
Implement fauna configuration
This commit is contained in:
@@ -13,23 +13,26 @@ public class BiomeZone {
|
||||
private final World w;
|
||||
private final FastNoise noise;
|
||||
private static final Map<World, BiomeZone> zones = new HashMap<>();
|
||||
private static final double[] normalMap = new double[] {-0.35662081837654114D, -0.30661869049072266D, -0.27095329761505127D, -0.24149227142333984D, -0.21537694334983826D, -0.19166918098926544D, -0.16956785321235657D, -0.14864568412303925D, -0.12845154106616974D, -0.10894706845283508D, -0.08996972441673279D, -0.0715663805603981D, -0.053535036742687225D, -0.03580872714519501D, -0.01817353256046772D, -7.577221258543432E-4D, 0.016616813838481903D, 0.03416096046566963D, 0.05187138542532921D, 0.06989025324583054D, 0.08827653527259827D, 0.10723070055246353D, 0.12675245106220245D, 0.14694781601428986D, 0.16793397068977356D, 0.18999846279621124D, 0.2138010412454605D, 0.24002985656261444D, 0.2696261405944824D, 0.30540621280670166D, 0.35551881790161133D, 0.653269350528717D};
|
||||
|
||||
|
||||
public BiomeZone(World w, float freq) {
|
||||
this.w = w;
|
||||
this.noise = new FastNoise((int) w.getSeed()+2);
|
||||
noise.setNoiseType(FastNoise.NoiseType.Value);
|
||||
noise.setNoiseType(FastNoise.NoiseType.SimplexFractal);
|
||||
noise.setFractalOctaves(5);
|
||||
noise.setFrequency(freq);
|
||||
setZones(WorldConfig.fromWorld(w).definedGrids);
|
||||
zones.put(w, this);
|
||||
}
|
||||
|
||||
public void setZones(BiomeGrid[] grids) {
|
||||
if(grids.length != 16) throw new IllegalArgumentException("Illegal number of grids!");
|
||||
if(grids.length != 32) throw new IllegalArgumentException("Illegal number of grids!");
|
||||
this.grids = grids;
|
||||
}
|
||||
|
||||
public BiomeGrid getGrid(int x, int z) {
|
||||
return grids[normalize(noise.getValue(x, z))];
|
||||
return grids[normalize(noise.getSimplexFractal(x, z))];
|
||||
}
|
||||
|
||||
public static BiomeZone fromWorld(World w) {
|
||||
@@ -38,14 +41,15 @@ public class BiomeZone {
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes a noise input and normalizes it to a value between 0 and 15 inclusive.
|
||||
* Takes a noise input and normalizes it to a value between 0 and 31 inclusive.
|
||||
*
|
||||
* @param i - The noise value to normalize.
|
||||
* @param d - The noise value to normalize.
|
||||
* @return int - The normalized value.
|
||||
*/
|
||||
private static int normalize(double i) {
|
||||
if(i > 0) i = Math.pow(i, 0.8125); // Redistribute
|
||||
else i = -Math.pow(-i, 0.8125); // Redistribute
|
||||
return Math.min((int) Math.floor((i+1)*8), 15);
|
||||
public static int normalize(double d) {
|
||||
for(int i = 0; i < normalMap.length; i++) {
|
||||
if(d < normalMap[i]) return i;
|
||||
}
|
||||
return normalMap.length-1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user