mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-18 10:32:30 +00:00
Split biome config into many classes
This commit is contained in:
parent
65d50d7def
commit
d15feb2e07
@ -38,6 +38,9 @@ public class AbstractBiomeConfig extends TerraConfig {
|
||||
private List<String> structureConfigs;
|
||||
private BiomePaletteConfig palette;
|
||||
private BiomeFloraConfig flora;
|
||||
private BiomeCarverConfig carving;
|
||||
private BiomeTreeConfig trees;
|
||||
private BiomeOreConfig ores;
|
||||
|
||||
public AbstractBiomeConfig(File file, ConfigPack config) throws IOException, InvalidConfigurationException {
|
||||
super(file, config);
|
||||
@ -45,15 +48,15 @@ public class AbstractBiomeConfig extends TerraConfig {
|
||||
if(!contains("id")) throw new ConfigException("Abstract Biome ID unspecified!", "null");
|
||||
this.biomeID = getString("id");
|
||||
|
||||
if(contains("carving")) carvingData = getMapList("carving");
|
||||
if(contains("carving")) carving = new BiomeCarverConfig(this);
|
||||
|
||||
if(contains("palette")) palette = new BiomePaletteConfig(this);
|
||||
|
||||
if(contains("flora")) flora = new BiomeFloraConfig(this);
|
||||
|
||||
if(contains("trees")) treeData = Objects.requireNonNull(getConfigurationSection("trees")).getValues(false);
|
||||
if(contains("trees")) trees = new BiomeTreeConfig(this);
|
||||
|
||||
if(contains("ores")) oreData = Objects.requireNonNull(getConfigurationSection("ores")).getValues(false);
|
||||
if(contains("ores")) ores = new BiomeOreConfig(this);
|
||||
|
||||
floraChance = getInt("flora-chance", 0);
|
||||
floraAttempts = getInt("flora-attempts", 1);
|
||||
@ -141,20 +144,16 @@ public class AbstractBiomeConfig extends TerraConfig {
|
||||
return flora;
|
||||
}
|
||||
|
||||
public Map<String, Object> getFloraData() {
|
||||
return floraData;
|
||||
public BiomeCarverConfig getCarving() {
|
||||
return carving;
|
||||
}
|
||||
|
||||
public Map<String, Object> getOreData() {
|
||||
return oreData;
|
||||
public BiomeTreeConfig getTrees() {
|
||||
return trees;
|
||||
}
|
||||
|
||||
public Map<String, Object> getTreeData() {
|
||||
return treeData;
|
||||
}
|
||||
|
||||
public List<Map<?, ?>> getCarvingData() {
|
||||
return carvingData;
|
||||
public BiomeOreConfig getOres() {
|
||||
return ores;
|
||||
}
|
||||
|
||||
public int getSeaLevel() {
|
||||
|
@ -0,0 +1,48 @@
|
||||
package com.dfsek.terra.config.genconfig.biome;
|
||||
|
||||
import com.dfsek.terra.Debug;
|
||||
import com.dfsek.terra.config.TerraConfig;
|
||||
import com.dfsek.terra.config.TerraConfigSection;
|
||||
import com.dfsek.terra.config.exception.ConfigException;
|
||||
import com.dfsek.terra.config.exception.NotFoundException;
|
||||
import com.dfsek.terra.config.genconfig.CarverConfig;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.polydev.gaea.math.ProbabilityCollection;
|
||||
import org.polydev.gaea.world.palette.Palette;
|
||||
import org.polydev.gaea.world.palette.RandomPalette;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class BiomeCarverConfig extends TerraConfigSection {
|
||||
private final Map<CarverConfig, Integer> carvers = new HashMap<>();
|
||||
@SuppressWarnings("unchecked")
|
||||
public BiomeCarverConfig(TerraConfig parent) throws InvalidConfigurationException {
|
||||
super(parent);
|
||||
List<Map<?, ?>> cfg = parent.getMapList("carving");
|
||||
if(cfg.size() == 0) return;
|
||||
for(Map<?, ?> e : cfg) {
|
||||
for(Map.Entry<?, ?> entry : e.entrySet()) {
|
||||
try {
|
||||
CarverConfig c = parent.getConfig().getCarver((String) entry.getKey());
|
||||
if(c == null) throw new NotFoundException("Carver", (String) entry.getKey(), parent.getID());
|
||||
Debug.info("Got carver " + c + ". Adding with weight " + entry.getValue());
|
||||
carvers.put(c, (Integer) entry.getValue());
|
||||
} catch(ClassCastException ex) {
|
||||
throw new ConfigException("Unable to parse Carver configuration! Check YAML syntax.", parent.getID());
|
||||
} catch(NullPointerException ex) {
|
||||
throw new NotFoundException("carver", (String) entry.getKey(), parent.getID());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Map<CarverConfig, Integer> getCarvers() {
|
||||
return carvers;
|
||||
}
|
||||
}
|
@ -85,48 +85,9 @@ public class BiomeConfig extends TerraConfig {
|
||||
}
|
||||
}
|
||||
|
||||
TreeMap<Integer, Palette<BlockData>> paletteMap;
|
||||
// Check if biome is extending abstract biome, only use abstract biome's palette if palette is NOT defined for current biome.
|
||||
if(extending && abstractBiome.getPaletteData() != null && ! contains("palette")) {
|
||||
paletteMap = abstractBiome.getPaletteData().getPaletteMap();
|
||||
Debug.info("Using super palette");
|
||||
} else paletteMap = new BiomePaletteConfig(this).getPaletteMap();
|
||||
if(paletteMap == null) throw new ConfigException("No Palette specified in biome or super biome.", getID());
|
||||
|
||||
// Check if carving should be handled by super biome.
|
||||
List<Map<?, ?>> carvingData;
|
||||
try {
|
||||
if(extending && abstractBiome.getCarvingData() != null && ! contains("carving")) {
|
||||
carvingData = abstractBiome.getCarvingData();
|
||||
Debug.info("Using super carvers");
|
||||
} else carvingData = getMapList("carving");
|
||||
} catch(NullPointerException e) {
|
||||
carvingData = null;
|
||||
}
|
||||
|
||||
carvers = new HashMap<>();
|
||||
if(carvingData != null) {
|
||||
for(Map<?, ?> e : carvingData) {
|
||||
for(Map.Entry<?, ?> entry : e.entrySet()) {
|
||||
try {
|
||||
CarverConfig c = getConfig().getCarver((String) entry.getKey());
|
||||
if(c == null) throw new NotFoundException("Carver", (String) entry.getKey(), getID());
|
||||
Debug.info("Got carver " + c + ". Adding with weight " + entry.getValue());
|
||||
carvers.put(c, (Integer) entry.getValue());
|
||||
} catch(ClassCastException ex) {
|
||||
throw new ConfigException("Unable to parse Carver configuration! Check YAML syntax.", getID());
|
||||
} catch(NullPointerException ex) {
|
||||
throw new NotFoundException("carver", (String) entry.getKey(), getID());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int floraChance, treeChance, treeDensity;
|
||||
|
||||
// Get various simple values using getOrDefault config methods.
|
||||
float floraFreq;
|
||||
int floraSeed;
|
||||
int floraSeed, floraChance, treeChance, treeDensity;
|
||||
try {
|
||||
slabThreshold = getDouble("slabs.threshold", Objects.requireNonNull(abstractBiome).getSlabThreshold());
|
||||
floraChance = getInt("flora-chance", Objects.requireNonNull(abstractBiome).getFloraChance());
|
||||
@ -157,28 +118,45 @@ public class BiomeConfig extends TerraConfig {
|
||||
floraNoise.setFrequency(floraFreq);
|
||||
}
|
||||
|
||||
TreeMap<Integer, Palette<BlockData>> paletteMap;
|
||||
// Check if biome is extending abstract biome, only use abstract biome's palette if palette is NOT defined for current biome.
|
||||
if(extending && abstractBiome.getPaletteData() != null && ! contains("palette")) {
|
||||
paletteMap = abstractBiome.getPaletteData().getPaletteMap();
|
||||
Debug.info("Using super palette");
|
||||
} else paletteMap = new BiomePaletteConfig(this).getPaletteMap();
|
||||
|
||||
// Palette must not be null
|
||||
if(paletteMap == null) throw new ConfigException("No Palette specified in biome or super biome.", getID());
|
||||
|
||||
// Check if carving should be handled by super biome.
|
||||
if(extending && abstractBiome.getCarving() != null && ! contains("carving")) {
|
||||
carvers = abstractBiome.getCarving().getCarvers();
|
||||
Debug.info("Using super carvers");
|
||||
} else carvers = new BiomeCarverConfig(this).getCarvers();
|
||||
|
||||
// Check if flora should be handled by super biome.
|
||||
if(extending && abstractBiome.getFloraData() != null && ! contains("flora")) {
|
||||
if(extending && abstractBiome.getFlora() != null && ! contains("flora")) {
|
||||
flora = abstractBiome.getFlora();
|
||||
Debug.info("Using super flora (" + flora.getFlora().size() + " entries, " + floraChance + " % chance)");
|
||||
} else flora = new BiomeFloraConfig(this);
|
||||
|
||||
// Check if trees should be handled by super biome.
|
||||
Map<String, Object> treeData;
|
||||
ProbabilityCollection<Tree> trees = new ProbabilityCollection<>();
|
||||
try {
|
||||
if(extending && abstractBiome.getTreeData() != null && ! contains("trees")) {
|
||||
treeData = abstractBiome.getTreeData();
|
||||
Debug.info("Using super trees");
|
||||
} else treeData = Objects.requireNonNull(getConfigurationSection("trees")).getValues(false);
|
||||
} catch(NullPointerException e) {
|
||||
treeData = null;
|
||||
ProbabilityCollection<Tree> trees;
|
||||
if(extending && abstractBiome.getTrees() != null && ! contains("trees")) {
|
||||
trees = abstractBiome.getTrees().getTrees();
|
||||
Debug.info("Using super trees");
|
||||
} else trees = new BiomeTreeConfig(this).getTrees();
|
||||
|
||||
// Check if ores should be handled by super biome.
|
||||
if(extending && abstractBiome.getOres() != null && ! contains("ores")) {
|
||||
oreHeights = abstractBiome.getOres().getOreHeights();
|
||||
ores = abstractBiome.getOres().getOres();
|
||||
Debug.info("Using super ores");
|
||||
} else {
|
||||
BiomeOreConfig oreConfig = new BiomeOreConfig(this);
|
||||
oreHeights = oreConfig.getOreHeights();
|
||||
ores = oreConfig.getOres();
|
||||
}
|
||||
if(treeData != null) {
|
||||
for(Map.Entry<String, Object> e : treeData.entrySet()) {
|
||||
trees.add(TreeType.valueOf(e.getKey()), (Integer) e.getValue());
|
||||
}
|
||||
} else trees = new ProbabilityCollection<>();
|
||||
|
||||
//Make sure equation is non-null
|
||||
if(eq == null || eq.equals("")) throw new ConfigException("Could not find noise equation! Biomes must include a noise equation, or extend an abstract biome with one.", getID());
|
||||
@ -195,30 +173,6 @@ public class BiomeConfig extends TerraConfig {
|
||||
throw new ConfigException("Invalid Vanilla biome: \"" + getString("vanilla") + "\"", getID());
|
||||
}
|
||||
|
||||
// Check if ores should be handled by super biome.
|
||||
oreHeights = new HashMap<>();
|
||||
ores = new HashMap<>();
|
||||
Map<String, Object> oreData;
|
||||
try {
|
||||
if(extending && abstractBiome.getOreData() != null && ! contains("ores")) {
|
||||
oreData = abstractBiome.getOreData();
|
||||
Debug.info("Using super ores");
|
||||
} else oreData = Objects.requireNonNull(getConfigurationSection("ores")).getValues(false);
|
||||
} catch(NullPointerException e) {
|
||||
oreData = null;
|
||||
}
|
||||
if(oreData != null) {
|
||||
for(Map.Entry<String, Object> m : oreData.entrySet()) {
|
||||
OreConfig ore = config.getOre(m.getKey());
|
||||
if(ore == null) throw new NotFoundException("Ore", m.getKey(), getID());
|
||||
ores.put(ore, new Range(((ConfigurationSection) m.getValue()).getInt("min"), ((ConfigurationSection) m.getValue()).getInt("max")));
|
||||
oreHeights.put(ore, new Range(((ConfigurationSection) m.getValue()).getInt("min-height"), ((ConfigurationSection) m.getValue()).getInt("max-height")));
|
||||
}
|
||||
} else {
|
||||
ores = new HashMap<>();
|
||||
oreHeights = new HashMap<>();
|
||||
}
|
||||
|
||||
// Ocean stuff
|
||||
String oceanPalette;
|
||||
try {
|
||||
|
@ -0,0 +1,44 @@
|
||||
package com.dfsek.terra.config.genconfig.biome;
|
||||
|
||||
import com.dfsek.terra.config.TerraConfig;
|
||||
import com.dfsek.terra.config.TerraConfigSection;
|
||||
import com.dfsek.terra.config.base.ConfigUtil;
|
||||
import com.dfsek.terra.config.exception.ConfigException;
|
||||
import com.dfsek.terra.config.exception.NotFoundException;
|
||||
import com.dfsek.terra.config.genconfig.OreConfig;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.polydev.gaea.math.Range;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class BiomeOreConfig extends TerraConfigSection {
|
||||
private final Map<OreConfig, Range> ores = new HashMap<>();
|
||||
private final Map<OreConfig, Range> oreHeights = new HashMap<>();
|
||||
public BiomeOreConfig(TerraConfig parent) throws InvalidConfigurationException {
|
||||
super(parent);
|
||||
ConfigurationSection c = parent.getConfigurationSection("ores");
|
||||
if(c == null) return;
|
||||
Map<String, Object> cfg = c.getValues(false);
|
||||
try {
|
||||
for(Map.Entry<String, Object> m : cfg.entrySet()) {
|
||||
OreConfig ore = parent.getConfig().getOre(m.getKey());
|
||||
if(ore == null) throw new NotFoundException("Ore", m.getKey(), parent.getID());
|
||||
ores.put(ore, new Range(((ConfigurationSection) m.getValue()).getInt("min"), ((ConfigurationSection) m.getValue()).getInt("max")));
|
||||
oreHeights.put(ore, new Range(((ConfigurationSection) m.getValue()).getInt("min-height"), ((ConfigurationSection) m.getValue()).getInt("max-height")));
|
||||
}
|
||||
} catch(ClassCastException e) {
|
||||
if(ConfigUtil.debug) e.printStackTrace();
|
||||
throw new ConfigException("Unable to parse Flora configuration! Check YAML syntax.", parent.getID());
|
||||
}
|
||||
}
|
||||
|
||||
public Map<OreConfig, Range> getOres() {
|
||||
return ores;
|
||||
}
|
||||
|
||||
public Map<OreConfig, Range> getOreHeights() {
|
||||
return oreHeights;
|
||||
}
|
||||
}
|
@ -18,12 +18,13 @@ import java.util.Random;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class BiomePaletteConfig extends TerraConfigSection {
|
||||
private final TreeMap<Integer, Palette<BlockData>> paletteMap = new TreeMap<>();
|
||||
private TreeMap<Integer, Palette<BlockData>> paletteMap;
|
||||
@SuppressWarnings("unchecked")
|
||||
public BiomePaletteConfig(TerraConfig parent) throws InvalidConfigurationException {
|
||||
super(parent);
|
||||
List<Map<?, ?>> cfg = parent.getMapList("palette");
|
||||
if(cfg.size() == 0) throw new ConfigException("Palette unspecified.", parent.getID());
|
||||
if(cfg.size() == 0) return;
|
||||
paletteMap = new TreeMap<>();
|
||||
for(Map<?, ?> e : cfg) {
|
||||
for(Map.Entry<?, ?> entry : e.entrySet()) {
|
||||
try {
|
||||
|
@ -0,0 +1,36 @@
|
||||
package com.dfsek.terra.config.genconfig.biome;
|
||||
|
||||
import com.dfsek.terra.config.TerraConfig;
|
||||
import com.dfsek.terra.config.TerraConfigSection;
|
||||
import com.dfsek.terra.config.exception.ConfigException;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.polydev.gaea.math.ProbabilityCollection;
|
||||
import org.polydev.gaea.tree.Tree;
|
||||
import org.polydev.gaea.tree.TreeType;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class BiomeTreeConfig extends TerraConfigSection {
|
||||
private final ProbabilityCollection<Tree> trees = new ProbabilityCollection<>();
|
||||
public BiomeTreeConfig(TerraConfig parent) throws InvalidConfigurationException {
|
||||
super(parent);
|
||||
ConfigurationSection c = parent.getConfigurationSection("trees");
|
||||
if(c == null) return;
|
||||
Map<String, Object> cfg = c.getValues(false);
|
||||
if(cfg.size() == 0) return;
|
||||
for(Map.Entry<String, Object> e : cfg.entrySet()) {
|
||||
try {
|
||||
trees.add(TreeType.valueOf(e.getKey()), (Integer) e.getValue());
|
||||
} catch(ClassCastException ex) {
|
||||
throw new ConfigException("Unable to parse Tree configuration! Check YAML syntax.", parent.getID());
|
||||
} catch(IllegalArgumentException ex) {
|
||||
throw new ConfigException("Invalid tree type: \"" + e.getKey() + "\"", parent.getID());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ProbabilityCollection<Tree> getTrees() {
|
||||
return trees;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user