mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-20 07:10:24 +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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,18 +10,30 @@ import org.polydev.gaea.math.parsii.eval.Parser;
|
||||
import org.polydev.gaea.math.parsii.eval.Scope;
|
||||
import org.polydev.gaea.math.parsii.tokenizer.ParseException;
|
||||
import org.polydev.gaea.structures.features.Feature;
|
||||
import org.polydev.gaea.world.BlockPalette;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class UserDefinedBiome implements Biome {
|
||||
private final UserDefinedGenerator gen;
|
||||
private final BiomeConfig config;
|
||||
private final UserDefinedDecorator decorator;
|
||||
public UserDefinedBiome(BiomeConfig config) throws ParseException {
|
||||
this.config = config;
|
||||
Scope s = Scope.create();
|
||||
gen = new UserDefinedGenerator(s, Parser.parse(Objects.requireNonNull(config.getString("noise-equation")), s), Collections.emptyList(), ConfigUtil.getPalette(config.getString("palette")).getPalette());
|
||||
TreeMap<Integer, BlockPalette> paletteMap = new TreeMap<>();
|
||||
for(Map.Entry<String, Object> e : config.getConfigurationSection("palette").getValues(false).entrySet()) {
|
||||
paletteMap.put((Integer) e.getValue(), ConfigUtil.getPalette(e.getKey()).getPalette());
|
||||
}
|
||||
|
||||
|
||||
this.decorator = new UserDefinedDecorator(config);
|
||||
|
||||
gen = new UserDefinedGenerator(s, Parser.parse(Objects.requireNonNull(config.getString("noise-equation")), s), Collections.emptyList(), paletteMap);
|
||||
}
|
||||
|
||||
public BiomeConfig getConfig() {
|
||||
@@ -35,7 +47,7 @@ public class UserDefinedBiome implements Biome {
|
||||
*/
|
||||
@Override
|
||||
public org.bukkit.block.Biome getVanillaBiome() {
|
||||
return org.bukkit.block.Biome.PLAINS;
|
||||
return config.getVanillaBiome();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,6 +77,6 @@ public class UserDefinedBiome implements Biome {
|
||||
*/
|
||||
@Override
|
||||
public Decorator getDecorator() {
|
||||
return null;
|
||||
return decorator;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.dfsek.terra.biome;
|
||||
|
||||
import com.dfsek.terra.config.BiomeConfig;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.polydev.gaea.biome.Decorator;
|
||||
import org.polydev.gaea.math.ProbabilityCollection;
|
||||
import org.polydev.gaea.tree.Tree;
|
||||
import org.polydev.gaea.world.Fauna;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class UserDefinedDecorator extends Decorator {
|
||||
|
||||
private final ProbabilityCollection<Fauna> fauna = new ProbabilityCollection<>();
|
||||
private int faunaChance;
|
||||
|
||||
public UserDefinedDecorator(BiomeConfig config) {
|
||||
if(config.contains("fauna")) {
|
||||
for(Map.Entry<String, Object> e : config.getConfigurationSection("fauna").getValues(false).entrySet()) {
|
||||
fauna.add(Fauna.valueOf(e.getKey()), (Integer) e.getValue());
|
||||
}
|
||||
}
|
||||
faunaChance = config.getInt("fauna-chance", 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProbabilityCollection<Tree> getTrees() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTreeDensity() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean overrideStructureChance() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldGenerateSnow() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Biome getVanillaBiome() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProbabilityCollection<Fauna> getFauna() {
|
||||
return fauna;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFaunaChance() {
|
||||
return faunaChance;
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,8 @@ import org.polydev.gaea.math.parsii.eval.Variable;
|
||||
import org.polydev.gaea.world.BlockPalette;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class UserDefinedGenerator extends BiomeTerrain {
|
||||
private final Expression noiseExp;
|
||||
@@ -17,13 +19,13 @@ public class UserDefinedGenerator extends BiomeTerrain {
|
||||
private final Variable xVar;
|
||||
private final Variable yVar;
|
||||
private final Variable zVar;
|
||||
private final BlockPalette p;
|
||||
private final TreeMap<Integer, BlockPalette> paletteMap;
|
||||
|
||||
|
||||
public UserDefinedGenerator(Scope s, Expression e, List<Variable> v, BlockPalette p) {
|
||||
public UserDefinedGenerator(Scope s, Expression e, List<Variable> v, TreeMap<Integer, BlockPalette> p) {
|
||||
this.noiseExp = e;
|
||||
this.vars = v;
|
||||
this.p = p;
|
||||
this.paletteMap = p;
|
||||
this.xVar = s.getVariable("x");
|
||||
this.yVar = s.getVariable("y");
|
||||
this.zVar = s.getVariable("z");
|
||||
@@ -72,6 +74,33 @@ public class UserDefinedGenerator extends BiomeTerrain {
|
||||
*/
|
||||
@Override
|
||||
public BlockPalette getPalette(int y) {
|
||||
return p;
|
||||
for(Map.Entry<Integer, BlockPalette> e : paletteMap.entrySet()) {
|
||||
if(e.getKey() >= y ) return e.getValue();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static class Range {
|
||||
private final int min;
|
||||
private final int max;
|
||||
|
||||
/**
|
||||
* Instantiates a Range object with a minimum value (inclusive) and a maximum value (exclusive).
|
||||
* @param min The minimum value (inclusive).
|
||||
* @param max The maximum value (exclusive).
|
||||
*/
|
||||
public Range(int min, int max) {
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if a value is within range.
|
||||
* @param val The value to test.
|
||||
* @return boolean - Whether the value is within range.
|
||||
*/
|
||||
public boolean isInRange(int val) {
|
||||
return val >= min && val < max;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,4 +9,8 @@ public class UserDefinedGrid extends BiomeGrid {
|
||||
super(w, freq1, freq2);
|
||||
super.setGrid(config.getBiomeGrid());
|
||||
}
|
||||
public UserDefinedGrid(World w, float freq1, float freq2, UserDefinedBiome[][] b) {
|
||||
super(w, freq1, freq2);
|
||||
super.setGrid(b);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user