Split off more config sections

This commit is contained in:
dfsek 2020-10-03 03:13:09 -07:00
parent d15feb2e07
commit 188cf612fb
4 changed files with 119 additions and 108 deletions

View File

@ -23,8 +23,7 @@ public class AbstractBiomeConfig extends TerraConfig {
private final String equation; private final String equation;
private final int floraAttempts; private final int floraAttempts;
private double slabThreshold; private double slabThreshold;
private Map<Material, Palette<BlockData>> slabs; private BiomeSlabConfig slabs;
private Map<Material, Palette<BlockData>> stairs;
private boolean useStairs; private boolean useStairs;
private final boolean floraSimplex; private final boolean floraSimplex;
private final int floraSeed; private final int floraSeed;
@ -48,16 +47,6 @@ public class AbstractBiomeConfig extends TerraConfig {
if(!contains("id")) throw new ConfigException("Abstract Biome ID unspecified!", "null"); if(!contains("id")) throw new ConfigException("Abstract Biome ID unspecified!", "null");
this.biomeID = getString("id"); this.biomeID = getString("id");
if(contains("carving")) carving = new BiomeCarverConfig(this);
if(contains("palette")) palette = new BiomePaletteConfig(this);
if(contains("flora")) flora = new BiomeFloraConfig(this);
if(contains("trees")) trees = new BiomeTreeConfig(this);
if(contains("ores")) ores = new BiomeOreConfig(this);
floraChance = getInt("flora-chance", 0); floraChance = getInt("flora-chance", 0);
floraAttempts = getInt("flora-attempts", 1); floraAttempts = getInt("flora-attempts", 1);
treeChance = getInt("tree-chance", 0); treeChance = getInt("tree-chance", 0);
@ -68,17 +57,19 @@ public class AbstractBiomeConfig extends TerraConfig {
floraSeed = getInt("flora-simplex.seed", 0); floraSeed = getInt("flora-simplex.seed", 0);
seaLevel = getInt("ocean.level", 62); seaLevel = getInt("ocean.level", 62);
oceanPalette = getString("ocean.palette"); oceanPalette = getString("ocean.palette");
useStairs = getBoolean("slabs.use-stairs-if-available", false);
// Get slab stuff if(contains("carving")) carving = new BiomeCarverConfig(this);
useStairs = false;
if(contains("slabs") && getBoolean("slabs.enable", false)) { if(contains("palette")) palette = new BiomePaletteConfig(this);
slabThreshold = getDouble("slabs.threshold", 0.1D);
slabs = BiomeConfigUtil.getSlabPalettes(getMapList("slabs.palettes"), this); if(contains("flora")) flora = new BiomeFloraConfig(this);
if(contains("slabs.stair-palettes") && getBoolean("slabs.use-stairs-if-available", false)) {
stairs = BiomeConfigUtil.getSlabPalettes(getMapList("slabs.stair-palettes"), this); if(contains("trees")) trees = new BiomeTreeConfig(this);
useStairs = true;
} if(contains("ores")) ores = new BiomeOreConfig(this);
}
if(contains("slabs") && getBoolean("slabs.enable", false)) slabs = new BiomeSlabConfig(this);
if(contains("structures")) structureConfigs = getStringList("structures"); if(contains("structures")) structureConfigs = getStringList("structures");
} }
@ -108,22 +99,10 @@ public class AbstractBiomeConfig extends TerraConfig {
return equation; return equation;
} }
public Map<Material, Palette<BlockData>> getSlabs() {
return slabs;
}
public double getSlabThreshold() { public double getSlabThreshold() {
return slabThreshold; return slabThreshold;
} }
public Map<Material, Palette<BlockData>> getStairs() {
return stairs;
}
public boolean shouldUseStairs() {
return useStairs;
}
public float getFloraFreq() { public float getFloraFreq() {
return floraFreq; return floraFreq;
} }
@ -156,6 +135,10 @@ public class AbstractBiomeConfig extends TerraConfig {
return ores; return ores;
} }
public BiomeSlabConfig getSlabs() {
return slabs;
}
public int getSeaLevel() { public int getSeaLevel() {
return seaLevel; return seaLevel;
} }

View File

@ -1,32 +1,25 @@
package com.dfsek.terra.config.genconfig.biome; package com.dfsek.terra.config.genconfig.biome;
import com.dfsek.terra.Debug; import com.dfsek.terra.Debug;
import com.dfsek.terra.biome.UserDefinedBiome;
import com.dfsek.terra.carving.UserDefinedCarver;
import com.dfsek.terra.config.ConfigPack; import com.dfsek.terra.config.ConfigPack;
import com.dfsek.terra.config.TerraConfig;
import com.dfsek.terra.config.exception.ConfigException; import com.dfsek.terra.config.exception.ConfigException;
import com.dfsek.terra.config.exception.NotFoundException; import com.dfsek.terra.config.exception.NotFoundException;
import com.dfsek.terra.config.genconfig.CarverConfig;
import com.dfsek.terra.config.genconfig.OreConfig; import com.dfsek.terra.config.genconfig.OreConfig;
import com.dfsek.terra.config.genconfig.StructureConfig; import com.dfsek.terra.config.genconfig.StructureConfig;
import org.polydev.gaea.math.Range;
import com.dfsek.terra.biome.UserDefinedBiome;
import com.dfsek.terra.generation.UserDefinedDecorator; import com.dfsek.terra.generation.UserDefinedDecorator;
import com.dfsek.terra.generation.UserDefinedGenerator; import com.dfsek.terra.generation.UserDefinedGenerator;
import com.dfsek.terra.carving.UserDefinedCarver;
import com.dfsek.terra.config.base.ConfigUtil;
import com.dfsek.terra.config.TerraConfig;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.data.BlockData; import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.type.Stairs;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.InvalidConfigurationException;
import org.polydev.gaea.math.FastNoise; import org.polydev.gaea.math.FastNoise;
import org.polydev.gaea.math.ProbabilityCollection; import org.polydev.gaea.math.ProbabilityCollection;
import org.polydev.gaea.math.Range;
import org.polydev.gaea.math.parsii.tokenizer.ParseException; import org.polydev.gaea.math.parsii.tokenizer.ParseException;
import org.polydev.gaea.tree.Tree;
import org.polydev.gaea.tree.TreeType;
import org.polydev.gaea.world.Flora; import org.polydev.gaea.world.Flora;
import org.polydev.gaea.world.FloraType;
import org.polydev.gaea.world.palette.Palette; import org.polydev.gaea.world.palette.Palette;
import org.polydev.gaea.world.palette.RandomPalette; import org.polydev.gaea.world.palette.RandomPalette;
@ -34,26 +27,21 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Random; import java.util.Random;
import java.util.TreeMap;
public class BiomeConfig extends TerraConfig { public class BiomeConfig extends TerraConfig {
private static final Palette<BlockData> oceanDefault = new RandomPalette<BlockData>(new Random(0)).add(Material.WATER.createBlockData(), 1); private static final Palette<BlockData> oceanDefault = new RandomPalette<BlockData>(new Random(0)).add(Material.WATER.createBlockData(), 1);
private final UserDefinedBiome biome; private final UserDefinedBiome biome;
private final String biomeID; private final String biomeID;
private Map<OreConfig, Range> ores; private final BiomeOreConfig ore;
private Map<OreConfig, Range> oreHeights; private final BiomeCarverConfig carver;
private final Map<CarverConfig, Integer> carvers;
private final BiomeFloraConfig flora; private final BiomeFloraConfig flora;
private String eq; private String eq;
private int floraAttempts; private int floraAttempts;
private Map<Material, Palette<BlockData>> slabs; private final BiomeSlabConfig slab;
private Map<Material, Palette<BlockData>> stairs;
private double slabThreshold; private double slabThreshold;
private boolean floraSimplex; private boolean floraSimplex;
private FastNoise floraNoise; private FastNoise floraNoise;
@ -62,7 +50,6 @@ public class BiomeConfig extends TerraConfig {
private final List<StructureConfig> structures; private final List<StructureConfig> structures;
private final ConfigPack config; private final ConfigPack config;
@SuppressWarnings("unchecked, rawtypes")
public BiomeConfig(File file, ConfigPack config) throws InvalidConfigurationException, IOException { public BiomeConfig(File file, ConfigPack config) throws InvalidConfigurationException, IOException {
super(file, config); super(file, config);
load(file); load(file);
@ -118,21 +105,21 @@ public class BiomeConfig extends TerraConfig {
floraNoise.setFrequency(floraFreq); floraNoise.setFrequency(floraFreq);
} }
TreeMap<Integer, Palette<BlockData>> paletteMap; BiomePaletteConfig palette;
// Check if biome is extending abstract biome, only use abstract biome's palette if palette is NOT defined for current biome. // 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")) { if(extending && abstractBiome.getPaletteData() != null && ! contains("palette")) {
paletteMap = abstractBiome.getPaletteData().getPaletteMap(); palette = abstractBiome.getPaletteData();
Debug.info("Using super palette"); Debug.info("Using super palette");
} else paletteMap = new BiomePaletteConfig(this).getPaletteMap(); } else palette = new BiomePaletteConfig(this);
// Palette must not be null // Palette must not be null
if(paletteMap == null) throw new ConfigException("No Palette specified in biome or super biome.", getID()); if(palette.getPaletteMap() == null) throw new ConfigException("No Palette specified in biome or super biome.", getID());
// Check if carving should be handled by super biome. // Check if carving should be handled by super biome.
if(extending && abstractBiome.getCarving() != null && ! contains("carving")) { if(extending && abstractBiome.getCarving() != null && ! contains("carving")) {
carvers = abstractBiome.getCarving().getCarvers(); carver = abstractBiome.getCarving();
Debug.info("Using super carvers"); Debug.info("Using super carvers");
} else carvers = new BiomeCarverConfig(this).getCarvers(); } else carver = new BiomeCarverConfig(this);
// Check if flora should be handled by super biome. // Check if flora should be handled by super biome.
if(extending && abstractBiome.getFlora() != null && ! contains("flora")) { if(extending && abstractBiome.getFlora() != null && ! contains("flora")) {
@ -141,28 +128,29 @@ public class BiomeConfig extends TerraConfig {
} else flora = new BiomeFloraConfig(this); } else flora = new BiomeFloraConfig(this);
// Check if trees should be handled by super biome. // Check if trees should be handled by super biome.
ProbabilityCollection<Tree> trees; BiomeTreeConfig tree;
if(extending && abstractBiome.getTrees() != null && ! contains("trees")) { if(extending && abstractBiome.getTrees() != null && ! contains("trees")) {
trees = abstractBiome.getTrees().getTrees(); tree = abstractBiome.getTrees();
Debug.info("Using super trees"); Debug.info("Using super trees");
} else trees = new BiomeTreeConfig(this).getTrees(); } else tree = new BiomeTreeConfig(this);
// Check if ores should be handled by super biome. // Check if ores should be handled by super biome.
if(extending && abstractBiome.getOres() != null && ! contains("ores")) { if(extending && abstractBiome.getOres() != null && ! contains("ores")) {
oreHeights = abstractBiome.getOres().getOreHeights(); ore = abstractBiome.getOres();
ores = abstractBiome.getOres().getOres();
Debug.info("Using super ores"); Debug.info("Using super ores");
} else { } else ore = new BiomeOreConfig(this);
BiomeOreConfig oreConfig = new BiomeOreConfig(this);
oreHeights = oreConfig.getOreHeights(); // Get slab stuff
ores = oreConfig.getOres(); if(extending && abstractBiome.getSlabs() != null && !contains("slabs")) {
} slab = abstractBiome.getSlabs();
Debug.info("Using super slabs");
} else slab = new BiomeSlabConfig(this);
//Make sure equation is non-null //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()); 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());
// Create decorator for this config. // Create decorator for this config.
UserDefinedDecorator dec = new UserDefinedDecorator(flora.getFlora(), trees, floraChance, treeChance, treeDensity); UserDefinedDecorator dec = new UserDefinedDecorator(flora.getFlora(), tree.getTrees(), floraChance, treeChance, treeDensity);
// Get Vanilla biome, throw exception if it is invalid/unspecified. // Get Vanilla biome, throw exception if it is invalid/unspecified.
org.bukkit.block.Biome vanillaBiome; org.bukkit.block.Biome vanillaBiome;
@ -197,37 +185,7 @@ public class BiomeConfig extends TerraConfig {
} else ocean = oceanDefault; } else ocean = oceanDefault;
// Get slab stuff
if(contains("slabs") && getBoolean("slabs.enable", false)) {
if(extending && abstractBiome.getSlabs() != null) {
slabs = abstractBiome.getSlabs();
if(abstractBiome.shouldUseStairs()) {
stairs = abstractBiome.getStairs();
}
Debug.info("Using super slabs");
} else {
slabs = BiomeConfigUtil.getSlabPalettes(getMapList("slabs.palettes"), this);
if(contains("slabs.stair-palettes") && getBoolean("slabs.use-stairs-if-available", false)) {
stairs = BiomeConfigUtil.getSlabPalettes(getMapList("slabs.stair-palettes"), this);
} else stairs = new HashMap<>();
}
for(Map.Entry<Material, Palette<BlockData>> p : stairs.entrySet()) {
try {
for(Palette.PaletteLayer l : p.getValue().getLayers()) {
Iterator i = l.getCollection().iterator();
while(i.hasNext()) {
Stairs s = (Stairs) ((ProbabilityCollection.ProbabilitySetElement<BlockData>) i.next()).getObject();
Debug.info("Stair added: " + s.getAsString());
}
}
} catch(ClassCastException e) {
if(ConfigUtil.debug) e.printStackTrace();
throw new ConfigException("Materials in stair config must be stairs.", getID());
}
}
Debug.info("[Terra] Slabs: " + slabs.size());
}
// Structure stuff // Structure stuff
structures = new ArrayList<>(); structures = new ArrayList<>();
@ -244,7 +202,7 @@ public class BiomeConfig extends TerraConfig {
try { try {
// Get UserDefinedBiome instance representing this config. // Get UserDefinedBiome instance representing this config.
this.biome = new UserDefinedBiome(vanillaBiome, dec, new UserDefinedGenerator(eq, Collections.emptyList(), paletteMap), biomeID); this.biome = new UserDefinedBiome(vanillaBiome, dec, new UserDefinedGenerator(eq, Collections.emptyList(), palette.getPaletteMap()), biomeID);
} catch(ParseException e) { } catch(ParseException e) {
e.printStackTrace(); e.printStackTrace();
throw new ConfigException("Unable to parse noise equation!", getID()); throw new ConfigException("Unable to parse noise equation!", getID());
@ -252,7 +210,7 @@ public class BiomeConfig extends TerraConfig {
} }
public Range getOreHeight(OreConfig c) { public Range getOreHeight(OreConfig c) {
return oreHeights.get(c); return ore.getOreHeights().get(c);
} }
public UserDefinedBiome getBiome() { public UserDefinedBiome getBiome() {
@ -268,7 +226,7 @@ public class BiomeConfig extends TerraConfig {
} }
public Map<OreConfig, Range> getOres() { public Map<OreConfig, Range> getOres() {
return ores; return ore.getOres();
} }
public Range getFloraHeights(Flora f) { public Range getFloraHeights(Flora f) {
@ -281,7 +239,7 @@ public class BiomeConfig extends TerraConfig {
} }
public int getCarverChance(UserDefinedCarver c) { public int getCarverChance(UserDefinedCarver c) {
return carvers.getOrDefault(config.getCarver(c), 0); return carver.getCarvers().getOrDefault(config.getCarver(c), 0);
} }
public double getSlabThreshold() { public double getSlabThreshold() {
@ -289,11 +247,11 @@ public class BiomeConfig extends TerraConfig {
} }
public Map<Material, Palette<BlockData>> getStairs() { public Map<Material, Palette<BlockData>> getStairs() {
return stairs; return slab.getStairs();
} }
public Map<Material, Palette<BlockData>> getSlabs() { public Map<Material, Palette<BlockData>> getSlabs() {
return slabs; return slab.getSlabs();
} }
public boolean isFloraSimplex() { public boolean isFloraSimplex() {

View File

@ -0,0 +1,70 @@
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 org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.data.BlockData;
import org.bukkit.configuration.InvalidConfigurationException;
import org.jetbrains.annotations.NotNull;
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;
public class BiomeSlabConfig extends TerraConfigSection {
private final Map<Material, Palette<BlockData>> slabs;
private final Map<Material, Palette<BlockData>> stairs;
public BiomeSlabConfig(@NotNull TerraConfig parent) throws InvalidConfigurationException {
super(parent);
slabs = BiomeConfigUtil.getSlabPalettes(parent.getMapList("slabs.palettes"), parent);
if(parent.contains("slabs.stair-palettes") && parent.getBoolean("slabs.use-stairs-if-available", false)) {
stairs = BiomeConfigUtil.getSlabPalettes(parent.getMapList("slabs.stair-palettes"), parent);
} else stairs = new HashMap<>();
}
protected Map<Material, Palette<BlockData>> getSlabPalettes(List<Map<?, ?>> paletteConfigSection) throws InvalidConfigurationException {
Map<Material, Palette<BlockData>> paletteMap = new HashMap<>();
for(Map<?, ?> e : paletteConfigSection) {
for(Map.Entry<?, ?> entry : e.entrySet()) {
try {
if(((String) entry.getValue()).startsWith("BLOCK:")) {
try {
Debug.info("Adding slab palette with single material " + entry.getKey());
paletteMap.put(Bukkit.createBlockData((String) entry.getKey()).getMaterial(), new RandomPalette<BlockData>(new Random(0)).add(new ProbabilityCollection<BlockData>().add(Bukkit.createBlockData(((String) entry.getValue()).substring(6)), 1), 1));
} catch(IllegalArgumentException ex) {
throw new ConfigException("Invalid BlockData in slab configuration: " + ex.getMessage(), getParent().getConfig().getID());
}
} else {
try {
Palette<BlockData> p = getParent().getConfig().getPalette((String) entry.getValue()).getPalette();
if(p.getSize() != 1) throw new InvalidConfigurationException("Slab palette must hold only one layer. Palette " + entry.getValue() + " is too large/small");
paletteMap.put(Bukkit.createBlockData((String) entry.getKey()).getMaterial(), p);
} catch(NullPointerException ex) {
throw new NotFoundException("Slab Palette", (String) entry.getValue(), getParent().getConfig().getID());
}
}
} catch(ClassCastException ex) {
throw new ConfigException("Unable to parse Slab Palette configuration! Check YAML syntax.", getParent().getConfig().getID());
}
}
}
Debug.info("Adding " + paletteMap.size() + " slab palettes...");
return paletteMap;
}
public Map<Material, Palette<BlockData>> getStairs() {
return stairs;
}
public Map<Material, Palette<BlockData>> getSlabs() {
return slabs;
}
}

View File

@ -75,7 +75,7 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
if(super.getInterpolatedNoise(x, y, z) > 0) { if(super.getInterpolatedNoise(x, y, z) > 0) {
BlockData data = b.getGenerator().getPalette(y).get(paletteLevel, cx, cz); BlockData data = b.getGenerator().getPalette(y).get(paletteLevel, cx, cz);
chunk.setBlock(x, y, z, data); chunk.setBlock(x, y, z, data);
if(paletteLevel == 0 && c.getSlabs() != null) { if(paletteLevel == 0 && c.getSlabs() != null && y < 255) {
prepareBlockPart(data, chunk.getBlockData(x, y+1, z), chunk, new Vector(x, y+1, z), c.getSlabs(), c.getStairs(), c.getSlabThreshold()); prepareBlockPart(data, chunk.getBlockData(x, y+1, z), chunk, new Vector(x, y+1, z), c.getSlabs(), c.getStairs(), c.getSlabThreshold());
} }
paletteLevel++; paletteLevel++;