mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-18 06:10:16 +00:00
Implement BiomeConfig, BiomeGridConfig, and PaletteConfig.
This commit is contained in:
@@ -1,20 +1,17 @@
|
||||
package com.dfsek.terra.biome;
|
||||
|
||||
import com.dfsek.terra.Terra;
|
||||
import com.dfsek.terra.config.ConfigUtil;
|
||||
import com.dfsek.terra.config.WorldConfig;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.polydev.gaea.biome.BiomeGrid;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class TerraBiomeGrid extends BiomeGrid {
|
||||
private UserDefinedBiome[][] grid;
|
||||
|
||||
private static final Map<World, TerraBiomeGrid> grids = new HashMap<>();
|
||||
private final UserDefinedBiome[][] grid;
|
||||
private final World w;
|
||||
|
||||
public TerraBiomeGrid(World w) {
|
||||
@@ -22,15 +19,21 @@ public class TerraBiomeGrid extends BiomeGrid {
|
||||
this.w = w;
|
||||
grid = new UserDefinedBiome[16][16];
|
||||
load();
|
||||
grids.put(w, this);
|
||||
}
|
||||
|
||||
public void load() {
|
||||
for(int x = 0; x < 16; x++) {
|
||||
for(int z = 0; z < 16; z++) {
|
||||
WorldConfig.fromWorld(w);
|
||||
grid[x][z] = WorldConfig.getBiomes().get(WorldConfig.fromWorld(w).biomeGrid.get(x).get(z)).getBiome();
|
||||
}
|
||||
}
|
||||
super.setGrid(grid);
|
||||
super.setGrid(WorldConfig.fromWorld(w).biomeGrid.getBiomeGrid());
|
||||
}
|
||||
|
||||
public static TerraBiomeGrid fromWorld(World w) {
|
||||
if(grids.containsKey(w)) return grids.get(w);
|
||||
else return new TerraBiomeGrid(w);
|
||||
}
|
||||
public static void reloadAll() {
|
||||
for(Map.Entry<World, TerraBiomeGrid> e : grids.entrySet()) {
|
||||
e.getValue().load();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.dfsek.terra.biome;
|
||||
|
||||
import com.dfsek.terra.config.BiomeConfig;
|
||||
import com.dfsek.terra.config.ConfigUtil;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.polydev.gaea.biome.Biome;
|
||||
import org.polydev.gaea.biome.BiomeTerrain;
|
||||
@@ -11,12 +13,19 @@ import org.polydev.gaea.structures.features.Feature;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class UserDefinedBiome implements Biome {
|
||||
private final UserDefinedGenerator gen;
|
||||
public UserDefinedBiome(String noiseEq) throws ParseException {
|
||||
private final BiomeConfig config;
|
||||
public UserDefinedBiome(BiomeConfig config) throws ParseException {
|
||||
this.config = config;
|
||||
Scope s = Scope.create();
|
||||
gen = new UserDefinedGenerator(s, Parser.parse(noiseEq, s), Collections.emptyList());
|
||||
gen = new UserDefinedGenerator(s, Parser.parse(Objects.requireNonNull(config.getString("noise-equation")), s), Collections.emptyList(), ConfigUtil.getPalette(config.getString("palette")).getPalette());
|
||||
}
|
||||
|
||||
public BiomeConfig getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.dfsek.terra.biome;
|
||||
|
||||
import com.dfsek.terra.math.NoiseFunction2;
|
||||
import com.dfsek.terra.math.NoiseFunction3;
|
||||
import org.polydev.gaea.biome.BiomeTerrain;
|
||||
import org.polydev.gaea.math.FastNoise;
|
||||
import org.polydev.gaea.math.parsii.eval.Expression;
|
||||
@@ -15,18 +17,16 @@ public class UserDefinedGenerator extends BiomeTerrain {
|
||||
private final Variable xVar;
|
||||
private final Variable yVar;
|
||||
private final Variable zVar;
|
||||
private final Variable noise2D;
|
||||
private final Variable noise3D;
|
||||
private final BlockPalette p;
|
||||
|
||||
|
||||
public UserDefinedGenerator(Scope s, Expression e, List<Variable> v) {
|
||||
public UserDefinedGenerator(Scope s, Expression e, List<Variable> v, BlockPalette p) {
|
||||
this.noiseExp = e;
|
||||
this.vars = v;
|
||||
this.p = p;
|
||||
this.xVar = s.getVariable("x");
|
||||
this.yVar = s.getVariable("y");
|
||||
this.zVar = s.getVariable("z");
|
||||
this.noise2D = s.getVariable("w");
|
||||
this.noise3D = s.getVariable("t");
|
||||
}
|
||||
/**
|
||||
* Gets the 2D noise at a pair of coordinates using the provided FastNoise instance.
|
||||
@@ -41,8 +41,8 @@ public class UserDefinedGenerator extends BiomeTerrain {
|
||||
xVar.setValue(x);
|
||||
yVar.setValue(0);
|
||||
zVar.setValue(z);
|
||||
noise2D.setValue(gen.getSimplexFractal(x, z));
|
||||
noise3D.setValue(0);
|
||||
NoiseFunction2.setNoise(gen);
|
||||
NoiseFunction3.setNoise(gen);
|
||||
return noiseExp.evaluate();
|
||||
}
|
||||
|
||||
@@ -60,8 +60,8 @@ public class UserDefinedGenerator extends BiomeTerrain {
|
||||
xVar.setValue(x);
|
||||
yVar.setValue(y);
|
||||
zVar.setValue(z);
|
||||
noise2D.setValue(gen.getSimplexFractal(x, z));
|
||||
noise3D.setValue(gen.getSimplexFractal(x, y, z));
|
||||
NoiseFunction2.setNoise(gen);
|
||||
NoiseFunction3.setNoise(gen);
|
||||
return noiseExp.evaluate();
|
||||
}
|
||||
|
||||
@@ -72,6 +72,6 @@ public class UserDefinedGenerator extends BiomeTerrain {
|
||||
*/
|
||||
@Override
|
||||
public BlockPalette getPalette() {
|
||||
return null;
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user