mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-18 10:32:30 +00:00
Finally implement user defined variables
This commit is contained in:
parent
08d1ca02f9
commit
b3dac9f37e
@ -7,7 +7,7 @@ import org.polydev.gaea.world.palette.Palette;
|
||||
import org.polydev.gaea.world.palette.RandomPalette;
|
||||
import parsii.tokenizer.ParseException;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
import java.util.TreeMap;
|
||||
|
||||
@ -19,6 +19,6 @@ public final class FailoverGenerator extends UserDefinedGenerator {
|
||||
}
|
||||
|
||||
public FailoverGenerator() throws ParseException {
|
||||
super("0", null, Collections.emptyList(), palette, new TreeMap<>(), false);
|
||||
super("0", null, new HashMap<>(), palette, new TreeMap<>(), false);
|
||||
}
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Collectors;
|
||||
@ -63,7 +64,7 @@ public class ConfigPack extends YamlConfiguration {
|
||||
public final boolean vanillaMobs;
|
||||
public final boolean preventSaplingOverride;
|
||||
|
||||
public final Map<StructureTypeEnum, StructureConfig> locatable = new HashMap<>();
|
||||
private final Map<StructureTypeEnum, StructureConfig> locatable = new HashMap<>();
|
||||
private final Map<String, OreConfig> ores;
|
||||
private final Map<String, PaletteConfig> palettes;
|
||||
private final Map<String, CarverConfig> carvers;
|
||||
@ -74,6 +75,7 @@ public class ConfigPack extends YamlConfiguration {
|
||||
private final TreeRegistry treeRegistry = new TreeRegistry();
|
||||
private final FloraRegistry floraRegistry = new FloraRegistry();
|
||||
private final Set<StructureConfig> allStructures = new HashSet<>();
|
||||
private final Map<String, Double> definedVariables = new HashMap<>();
|
||||
private final File dataFolder;
|
||||
private final String id;
|
||||
|
||||
@ -106,6 +108,20 @@ public class ConfigPack extends YamlConfiguration {
|
||||
Debug.info("Overriding Vanilla tree: " + entry.getKey());
|
||||
}
|
||||
|
||||
if(contains("variables")) {
|
||||
Map<String, Object> vars = Objects.requireNonNull(getConfigurationSection("variables")).getValues(false);
|
||||
for(Map.Entry<String, Object> entry : vars.entrySet()) {
|
||||
try {
|
||||
definedVariables.put(entry.getKey(), Double.valueOf(entry.getValue().toString()));
|
||||
Debug.info("Registered variable " + entry.getKey() + " with value " + entry.getValue());
|
||||
} catch(ClassCastException | NumberFormatException e) {
|
||||
Debug.stack(e);
|
||||
throw new ConfigException("Variable value " + entry.getValue().toString() + " could not be parsed to a double.", getID());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
abstractBiomes = ConfigLoader.load(new File(file, "abstract" + File.separator + "biomes").toPath(), this, AbstractBiomeConfig.class);
|
||||
|
||||
biomes = ConfigLoader.load(new File(file, "biomes").toPath(), this, BiomeConfig.class);
|
||||
@ -178,6 +194,10 @@ public class ConfigPack extends YamlConfiguration {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Map<String, Double> getDefinedVariables() {
|
||||
return definedVariables;
|
||||
}
|
||||
|
||||
public Map<String, BiomeConfig> getBiomes() {
|
||||
return biomes;
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ import parsii.tokenizer.ParseException;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.TreeMap;
|
||||
@ -172,7 +171,7 @@ public class BiomeConfig extends TerraConfig {
|
||||
|
||||
try {
|
||||
// Get UserDefinedBiome instance representing this config.
|
||||
UserDefinedGenerator gen = new UserDefinedGenerator(eq, elevation, Collections.emptyList(), palette.getPaletteMap(), slant, getBoolean("prevent-smooth", false));
|
||||
UserDefinedGenerator gen = new UserDefinedGenerator(eq, elevation, config.getDefinedVariables(), palette.getPaletteMap(), slant, getBoolean("prevent-smooth", false));
|
||||
gen.setElevationInterpolation(doElevationInterpolation);
|
||||
this.biome = new UserDefinedBiome(vanillaBiome, dec, gen, getBoolean("erodible", false), biomeID);
|
||||
} catch(ParseException e) {
|
||||
|
@ -17,7 +17,6 @@ import parsii.eval.Scope;
|
||||
import parsii.eval.Variable;
|
||||
import parsii.tokenizer.ParseException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@ -39,8 +38,11 @@ public class UserDefinedGenerator extends Generator {
|
||||
private boolean elevationInterpolation;
|
||||
|
||||
|
||||
public UserDefinedGenerator(String equation, @Nullable String elevateEquation, List<Variable> userVariables, Map<Integer, Palette<BlockData>> paletteMap, Map<Integer, Palette<BlockData>> slantPaletteMap, boolean preventSmooth)
|
||||
public UserDefinedGenerator(String equation, @Nullable String elevateEquation, Map<String, Double> userVariables, Map<Integer, Palette<BlockData>> paletteMap, Map<Integer, Palette<BlockData>> slantPaletteMap, boolean preventSmooth)
|
||||
throws ParseException {
|
||||
for(Map.Entry<String, Double> entry : userVariables.entrySet()) {
|
||||
s.getVariable(entry.getKey()).setValue(entry.getValue()); // Define all user variables.
|
||||
}
|
||||
Parser p = new Parser();
|
||||
p.registerFunction("noise2", n2);
|
||||
p.registerFunction("noise3", n3);
|
||||
|
Loading…
x
Reference in New Issue
Block a user