refactor API

This commit is contained in:
dfsek
2021-01-24 01:46:01 -07:00
parent 3318161c44
commit da5d3fe0ce
77 changed files with 142 additions and 970 deletions
@@ -14,10 +14,8 @@ import com.dfsek.terra.api.world.flora.Flora;
import com.dfsek.terra.api.world.palette.Palette;
import com.dfsek.terra.api.world.tree.Tree;
import com.dfsek.terra.biome.BiomeProvider;
import com.dfsek.terra.carving.UserDefinedCarver;
import com.dfsek.terra.config.exception.FileMissingException;
import com.dfsek.terra.config.factories.BiomeFactory;
import com.dfsek.terra.config.factories.CarverFactory;
import com.dfsek.terra.config.factories.FloraFactory;
import com.dfsek.terra.config.factories.OreFactory;
import com.dfsek.terra.config.factories.PaletteFactory;
@@ -31,7 +29,6 @@ import com.dfsek.terra.config.lang.LangUtil;
import com.dfsek.terra.config.loaders.config.biome.BiomeProviderBuilderLoader;
import com.dfsek.terra.config.templates.AbstractableTemplate;
import com.dfsek.terra.config.templates.BiomeTemplate;
import com.dfsek.terra.config.templates.CarverTemplate;
import com.dfsek.terra.config.templates.FloraTemplate;
import com.dfsek.terra.config.templates.OreTemplate;
import com.dfsek.terra.config.templates.PaletteTemplate;
@@ -41,7 +38,6 @@ import com.dfsek.terra.generation.math.SamplerCache;
import com.dfsek.terra.population.items.TerraStructure;
import com.dfsek.terra.population.items.ores.Ore;
import com.dfsek.terra.registry.BiomeRegistry;
import com.dfsek.terra.registry.CarverRegistry;
import com.dfsek.terra.registry.FloraRegistry;
import com.dfsek.terra.registry.LootRegistry;
import com.dfsek.terra.registry.OreRegistry;
@@ -60,7 +56,6 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.Enumeration;
import java.util.List;
import java.util.Map;
@@ -78,7 +73,6 @@ public class ConfigPack implements LoaderRegistrar {
private final BiomeRegistry biomeRegistry = new BiomeRegistry();
private final StructureRegistry structureRegistry = new StructureRegistry();
private final CarverRegistry carverRegistry = new CarverRegistry();
private final PaletteRegistry paletteRegistry;
private final FloraRegistry floraRegistry;
private final OreRegistry oreRegistry = new OreRegistry();
@@ -156,6 +150,7 @@ public class ConfigPack implements LoaderRegistrar {
}
private void load(long start, TerraPlugin main) throws ConfigException {
main.packPreLoadCallback(this);
for(Map.Entry<String, Double> var : template.getVariables().entrySet()) {
varScope.create(var.getKey()).setValue(var.getValue());
}
@@ -188,10 +183,10 @@ public class ConfigPack implements LoaderRegistrar {
.open("structures/trees", ".yml").then(streams -> buildAll(new TreeFactory(), treeRegistry, abstractConfigLoader.load(streams, TreeTemplate::new), main)).close()
.open("structures/structures", ".yml").then(streams -> buildAll(new StructureFactory(), structureRegistry, abstractConfigLoader.load(streams, StructureTemplate::new), main)).close()
.open("flora", ".yml").then(streams -> buildAll(new FloraFactory(), floraRegistry, abstractConfigLoader.load(streams, FloraTemplate::new), main)).close()
.open("carving", ".yml").then(streams -> buildAll(new CarverFactory(this), carverRegistry, abstractConfigLoader.load(streams, CarverTemplate::new), main)).close()
.open("biomes", ".yml").then(streams -> buildAll(new BiomeFactory(this), biomeRegistry, abstractConfigLoader.load(streams, () -> new BiomeTemplate(this, main)), main)).close();
main.packPostLoadCallback(this);
LangUtil.log("config-pack.loaded", Level.INFO, template.getID(), String.valueOf((System.nanoTime() - start) / 1000000D), template.getAuthor(), template.getVersion());
}
@@ -215,14 +210,6 @@ public class ConfigPack implements LoaderRegistrar {
return structureRegistry.entries();
}
public Collection<UserDefinedCarver> getCarvers() {
return carverRegistry.entries();
}
public UserDefinedCarver getCarver(String id) {
return carverRegistry.get(id);
}
public List<String> getStructureIDs() {
return structureRegistry.entries().stream().map(terraStructure -> terraStructure.getTemplate().getID()).collect(Collectors.toList());
}
@@ -245,7 +232,6 @@ public class ConfigPack implements LoaderRegistrar {
registry
.registerLoader(Palette.class, paletteRegistry)
.registerLoader(TerraBiome.class, biomeRegistry)
.registerLoader(UserDefinedCarver.class, carverRegistry)
.registerLoader(Flora.class, floraRegistry)
.registerLoader(Ore.class, oreRegistry)
.registerLoader(Tree.class, treeRegistry)
@@ -1,37 +0,0 @@
package com.dfsek.terra.config.factories;
import com.dfsek.tectonic.exception.LoadException;
import com.dfsek.terra.api.math.MathUtil;
import com.dfsek.terra.api.platform.TerraPlugin;
import com.dfsek.terra.carving.UserDefinedCarver;
import com.dfsek.terra.config.base.ConfigPack;
import com.dfsek.terra.config.templates.CarverTemplate;
import parsii.tokenizer.ParseException;
import java.util.Arrays;
import java.util.List;
public class CarverFactory implements TerraFactory<CarverTemplate, UserDefinedCarver> {
private final ConfigPack pack;
public CarverFactory(ConfigPack pack) {
this.pack = pack;
}
@Override
public UserDefinedCarver build(CarverTemplate config, TerraPlugin main) throws LoadException {
double[] start = new double[] {config.getStartX(), config.getStartY(), config.getStartZ()};
double[] mutate = new double[] {config.getMutateX(), config.getMutateY(), config.getMutateZ()};
List<String> radius = Arrays.asList(config.getRadMX(), config.getRadMY(), config.getRadMZ());
long hash = MathUtil.hashToLong(config.getID());
UserDefinedCarver carver;
try {
carver = new UserDefinedCarver(config.getHeight(), config.getLength(), start, mutate, radius, pack.getVarScope(), hash, config.getCutTop(), config.getCutBottom(), config, main);
} catch(ParseException e) {
throw new LoadException("Unable to parse radius equations", e);
}
carver.setRecalc(config.getRecalc());
carver.setRecalcMagnitude(config.getRecaclulateMagnitude());
return carver;
}
}
@@ -1,33 +0,0 @@
package com.dfsek.terra.config.loaders.palette;
import com.dfsek.tectonic.config.Configuration;
import com.dfsek.tectonic.exception.LoadException;
import com.dfsek.tectonic.loading.ConfigLoader;
import com.dfsek.tectonic.loading.TypeLoader;
import com.dfsek.terra.api.math.ProbabilityCollection;
import com.dfsek.terra.api.platform.block.BlockData;
import com.dfsek.terra.carving.CarverPalette;
import com.dfsek.terra.config.loaders.Types;
import com.dfsek.terra.util.MaterialSet;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;
@SuppressWarnings("unchecked")
public class CarverPaletteLoader implements TypeLoader<CarverPalette> {
@Override
public CarverPalette load(Type type, Object o, ConfigLoader configLoader) throws LoadException {
Configuration configuration = new Configuration((Map<String, Object>) o);
CarverPalette palette = new CarverPalette((MaterialSet) configLoader.loadType(MaterialSet.class, configuration.get("replace")), (Boolean) configuration.get("replace-blacklist"));
for(Map<String, Object> map : (List<Map<String, Object>>) configuration.get("layers")) {
ProbabilityCollection<BlockData> layer = (ProbabilityCollection<BlockData>) configLoader.loadType(Types.BLOCK_DATA_PROBABILITY_COLLECTION_TYPE, map.get("materials"));
palette.add(layer, (Integer) map.get("y"));
}
palette.build();
return palette;
}
}
@@ -16,7 +16,6 @@ import com.dfsek.terra.api.util.GlueList;
import com.dfsek.terra.api.world.palette.Palette;
import com.dfsek.terra.biome.palette.PaletteHolder;
import com.dfsek.terra.biome.palette.SinglePalette;
import com.dfsek.terra.carving.UserDefinedCarver;
import com.dfsek.terra.config.base.ConfigPack;
import com.dfsek.terra.generation.config.NoiseBuilder;
import com.dfsek.terra.population.items.TerraStructure;
@@ -27,7 +26,6 @@ import parsii.eval.Parser;
import parsii.eval.Scope;
import parsii.tokenizer.ParseException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -57,10 +55,12 @@ public class BiomeTemplate extends AbstractableTemplate implements ValidatedConf
@Value("palette")
@Abstractable
private PaletteHolder palette;
@Value("slant.palette")
@Abstractable
@Default
private PaletteHolder slantPalette = null;
@Value("vanilla")
@Abstractable
private ProbabilityCollection<Biome> vanilla;
@@ -89,25 +89,26 @@ public class BiomeTemplate extends AbstractableTemplate implements ValidatedConf
@Abstractable
@Default
private String erode = null;
@Value("structures")
@Abstractable
@Default
private List<TerraStructure> structures = new GlueList<>();
@Value("carving")
@Abstractable
@Default
private Map<UserDefinedCarver, Integer> carvers = new HashMap<>();
@Value("noise-equation")
@Abstractable
private String noiseEquation;
@Value("ores")
@Abstractable
@Default
private OreHolder oreHolder = new OreHolder();
@Value("ocean.level")
@Abstractable
@Default
private int seaLevel = 62;
@Value("ocean.palette")
@Abstractable
@Default
@@ -274,10 +275,6 @@ public class BiomeTemplate extends AbstractableTemplate implements ValidatedConf
return structures;
}
public Map<UserDefinedCarver, Integer> getCarvers() {
return carvers;
}
public String getNoiseEquation() {
return noiseEquation;
}
@@ -1,205 +0,0 @@
package com.dfsek.terra.config.templates;
import com.dfsek.tectonic.annotations.Abstractable;
import com.dfsek.tectonic.annotations.Default;
import com.dfsek.tectonic.annotations.Value;
import com.dfsek.terra.api.math.Range;
import com.dfsek.terra.api.platform.block.MaterialData;
import com.dfsek.terra.carving.CarverPalette;
import com.dfsek.terra.util.MaterialSet;
import java.util.HashMap;
import java.util.Map;
@SuppressWarnings({"unused", "FieldMayBeFinal"})
public class CarverTemplate extends AbstractableTemplate {
@Value("id")
private String id;
@Value("step")
@Abstractable
@Default
private int step = 2;
@Value("recalculate-magnitude")
@Default
@Abstractable
private double recaclulateMagnitude = 4;
@Value("recalculate-direction")
@Abstractable
@Default
private Range recalc = new Range(8, 10);
@Value("length")
@Abstractable
private Range length;
@Value("start.x")
@Abstractable
private double startX;
@Value("start.y")
@Abstractable
private double startY;
@Value("start.z")
@Abstractable
private double startZ;
@Value("start.radius.x")
@Abstractable
private String radMX;
@Value("start.radius.y")
@Abstractable
private String radMY;
@Value("start.radius.z")
@Abstractable
private String radMZ;
@Value("start.height")
@Abstractable
private Range height;
@Value("cut.bottom")
@Abstractable
@Default
private int cutBottom = 0;
@Value("cut.top")
@Abstractable
@Default
private int cutTop = 0;
@Value("mutate.x")
@Abstractable
private double mutateX;
@Value("mutate.y")
@Abstractable
private double mutateY;
@Value("mutate.z")
@Abstractable
private double mutateZ;
@Value("palette.top")
@Abstractable
private CarverPalette top;
@Value("palette.bottom")
@Abstractable
private CarverPalette bottom;
@Value("palette.outer")
@Abstractable
private CarverPalette outer;
@Value("palette.inner")
@Abstractable
private CarverPalette inner;
@Value("shift")
@Abstractable
@Default
private Map<MaterialData, MaterialSet> shift = new HashMap<>();
@Value("update")
@Abstractable
@Default
private MaterialSet update = new MaterialSet();
public String getID() {
return id;
}
public int getStep() {
return step;
}
public Range getLength() {
return length;
}
public double getStartX() {
return startX;
}
public double getStartY() {
return startY;
}
public double getStartZ() {
return startZ;
}
public String getRadMX() {
return radMX;
}
public String getRadMY() {
return radMY;
}
public String getRadMZ() {
return radMZ;
}
public Range getHeight() {
return height;
}
public int getCutBottom() {
return cutBottom;
}
public int getCutTop() {
return cutTop;
}
public double getMutateX() {
return mutateX;
}
public double getMutateY() {
return mutateY;
}
public double getMutateZ() {
return mutateZ;
}
public CarverPalette getTop() {
return top;
}
public CarverPalette getBottom() {
return bottom;
}
public CarverPalette getOuter() {
return outer;
}
public CarverPalette getInner() {
return inner;
}
public Map<MaterialData, MaterialSet> getShift() {
return shift;
}
public MaterialSet getUpdate() {
return update;
}
public Range getRecalc() {
return recalc;
}
public double getRecaclulateMagnitude() {
return recaclulateMagnitude;
}
}