mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-10 01:36:19 +00:00
meta values in config manifest
This commit is contained in:
18
common/src/main/java/com/dfsek/terra/api/util/MapUtil.java
Normal file
18
common/src/main/java/com/dfsek/terra/api/util/MapUtil.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package com.dfsek.terra.api.util;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public final class MapUtil {
|
||||
public static <K1, V1, K2, V2, M extends Map<K2, V2>> M remap(Function<K1, K2> keys, Function<V1, V2> values, Map<K1, V1> in, Supplier<M> newMap) {
|
||||
M map = newMap.get();
|
||||
in.forEach((k, v) -> map.put(keys.apply(k), values.apply(v)));
|
||||
return map;
|
||||
}
|
||||
|
||||
public static <K1, V1, K2, V2> Map<K2, V2> remap(Function<K1, K2> keys, Function<V1, V2> values, Map<K1, V1> in) {
|
||||
return remap(keys, values, in, HashMap::new);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.dfsek.terra.api.util.generic;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public final class Lazy<T> {
|
||||
private final Supplier<T> fetch;
|
||||
|
||||
private T value;
|
||||
|
||||
private boolean needsInit = true;
|
||||
|
||||
public Lazy(Supplier<T> fetch) {
|
||||
this.fetch = fetch;
|
||||
}
|
||||
|
||||
public T get() {
|
||||
if(needsInit) {
|
||||
value = fetch.get();
|
||||
needsInit = false;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ public class GenericMetaValueLoader extends MetaValueLoader<MetaValue<Object>, O
|
||||
String possibleMeta = (String) c;
|
||||
if(possibleMeta.startsWith("$")) {
|
||||
String meta = possibleMeta.substring(1);
|
||||
return context.load(meta, generic);
|
||||
return MetaValue.of(context.load(meta, generic));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,13 +2,14 @@ package com.dfsek.terra.config.pack;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
import com.dfsek.terra.api.config.meta.MetaValue;
|
||||
import com.dfsek.terra.api.world.biome.provider.BiomeProvider;
|
||||
|
||||
public class ConfigPackPostTemplate implements ConfigTemplate {
|
||||
@Value("biomes")
|
||||
private BiomeProvider.BiomeProviderBuilder providerBuilder;
|
||||
private MetaValue<BiomeProvider.BiomeProviderBuilder> providerBuilder;
|
||||
|
||||
public BiomeProvider.BiomeProviderBuilder getProviderBuilder() {
|
||||
return providerBuilder;
|
||||
return providerBuilder.get();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,9 @@ import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
import com.dfsek.terra.api.addons.TerraAddon;
|
||||
import com.dfsek.terra.api.config.meta.MetaValue;
|
||||
import com.dfsek.terra.api.util.MapUtil;
|
||||
import com.dfsek.terra.api.util.generic.Lazy;
|
||||
import com.dfsek.terra.api.util.seeded.NoiseSeeded;
|
||||
import com.dfsek.terra.config.loaders.config.function.FunctionTemplate;
|
||||
|
||||
@@ -12,14 +15,24 @@ import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
@SuppressWarnings({"unused", "FieldMayBeFinal"})
|
||||
public class ConfigPackTemplate implements ConfigTemplate {
|
||||
@Value("id")
|
||||
private String id;
|
||||
|
||||
@Value("version")
|
||||
@Default
|
||||
private String version = "0.1.0";
|
||||
|
||||
@Value("author")
|
||||
@Default
|
||||
private String author = "Anon Y. Mous";
|
||||
|
||||
@Value("noise")
|
||||
private Map<String, NoiseSeeded> noiseBuilderMap;
|
||||
private Map<String, MetaValue<NoiseSeeded>> noiseBuilderMap;
|
||||
private final Lazy<Map<String, NoiseSeeded>> lazyNoiseBuilderMap = new Lazy<>(() -> MapUtil.remap(Function.identity(), MetaValue::get, noiseBuilderMap));
|
||||
|
||||
@Value("addons")
|
||||
@Default
|
||||
@@ -27,94 +40,89 @@ public class ConfigPackTemplate implements ConfigTemplate {
|
||||
|
||||
@Value("variables")
|
||||
@Default
|
||||
private Map<String, Double> variables = new HashMap<>();
|
||||
private Map<String, MetaValue<Double>> variables = new HashMap<>();
|
||||
private final Lazy<Map<String, Double>> lazyVariables = new Lazy<>(() -> MapUtil.remap(Function.identity(), MetaValue::get, variables));
|
||||
|
||||
@Value("beta.carving")
|
||||
@Default
|
||||
private boolean betaCarvers = false;
|
||||
private MetaValue<Boolean> betaCarvers = MetaValue.of(false);
|
||||
|
||||
@Value("functions")
|
||||
@Default
|
||||
private LinkedHashMap<String, FunctionTemplate> functions = new LinkedHashMap<>();
|
||||
private LinkedHashMap<String, MetaValue<FunctionTemplate>> functions = new LinkedHashMap<>();
|
||||
private final Lazy<LinkedHashMap<String, FunctionTemplate>> lazyFunctions = new Lazy<>(() -> MapUtil.remap(Function.identity(), MetaValue::get, functions, LinkedHashMap::new));
|
||||
|
||||
@Value("structures.locatable")
|
||||
@Default
|
||||
private Map<String, String> locatable = new HashMap<>();
|
||||
private Map<String, MetaValue<String>> locatable = new HashMap<>();
|
||||
private final Lazy<Map<String, String>> lazyLocatable = new Lazy<>(() -> MapUtil.remap(Function.identity(), MetaValue::get, locatable));
|
||||
|
||||
@Value("blend.terrain.elevation")
|
||||
@Default
|
||||
private int elevationBlend = 4;
|
||||
private MetaValue<Integer> elevationBlend = MetaValue.of(4);
|
||||
|
||||
@Value("vanilla.mobs")
|
||||
@Default
|
||||
private boolean vanillaMobs = true;
|
||||
private MetaValue<Boolean> vanillaMobs = MetaValue.of(true);
|
||||
|
||||
@Value("vanilla.caves")
|
||||
@Default
|
||||
private boolean vanillaCaves = false;
|
||||
private MetaValue<Boolean> vanillaCaves = MetaValue.of(false);
|
||||
|
||||
@Value("vanilla.decorations")
|
||||
@Default
|
||||
private boolean vanillaDecorations = false;
|
||||
private MetaValue<Boolean> vanillaDecorations = MetaValue.of(false);
|
||||
|
||||
@Value("vanilla.structures")
|
||||
@Default
|
||||
private boolean vanillaStructures = false;
|
||||
|
||||
@Value("author")
|
||||
@Default
|
||||
private String author = "Anon Y. Mous";
|
||||
private MetaValue<Boolean> vanillaStructures = MetaValue.of(false);
|
||||
|
||||
@Value("disable.sapling")
|
||||
@Default
|
||||
private boolean disableSaplings = false;
|
||||
|
||||
@Value("version")
|
||||
@Default
|
||||
private String version = "0.1.0";
|
||||
private MetaValue<Boolean> disableSaplings = MetaValue.of(false);
|
||||
|
||||
@Value("disable.carvers")
|
||||
@Default
|
||||
private boolean disableCarvers = false;
|
||||
private MetaValue<Boolean> disableCarvers = MetaValue.of(false);
|
||||
|
||||
@Value("disable.structures")
|
||||
@Default
|
||||
private boolean disableStructures = false;
|
||||
private MetaValue<Boolean> disableStructures = MetaValue.of(false);
|
||||
|
||||
@Value("disable.ores")
|
||||
@Default
|
||||
private boolean disableOres = false;
|
||||
private MetaValue<Boolean> disableOres = MetaValue.of(false);
|
||||
|
||||
@Value("disable.trees")
|
||||
@Default
|
||||
private boolean disableTrees = false;
|
||||
private MetaValue<Boolean> disableTrees = MetaValue.of(false);
|
||||
|
||||
@Value("disable.flora")
|
||||
@Default
|
||||
private boolean disableFlora = false;
|
||||
private MetaValue<Boolean> disableFlora = MetaValue.of(false);
|
||||
|
||||
public boolean disableCarvers() {
|
||||
return disableCarvers;
|
||||
return disableCarvers.get();
|
||||
}
|
||||
|
||||
public boolean disableFlora() {
|
||||
return disableFlora;
|
||||
return disableFlora.get();
|
||||
}
|
||||
|
||||
public boolean disableOres() {
|
||||
return disableOres;
|
||||
return disableOres.get();
|
||||
}
|
||||
|
||||
public boolean disableStructures() {
|
||||
return disableStructures;
|
||||
return disableStructures.get();
|
||||
}
|
||||
|
||||
public boolean disableTrees() {
|
||||
return disableTrees;
|
||||
return disableTrees.get();
|
||||
}
|
||||
|
||||
public LinkedHashMap<String, FunctionTemplate> getFunctions() {
|
||||
return functions;
|
||||
return lazyFunctions.get();
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
@@ -122,7 +130,7 @@ public class ConfigPackTemplate implements ConfigTemplate {
|
||||
}
|
||||
|
||||
public boolean isDisableSaplings() {
|
||||
return disableSaplings;
|
||||
return disableSaplings.get();
|
||||
}
|
||||
|
||||
public String getID() {
|
||||
@@ -134,39 +142,39 @@ public class ConfigPackTemplate implements ConfigTemplate {
|
||||
}
|
||||
|
||||
public boolean vanillaMobs() {
|
||||
return vanillaMobs;
|
||||
return vanillaMobs.get();
|
||||
}
|
||||
|
||||
public boolean vanillaCaves() {
|
||||
return vanillaCaves;
|
||||
return vanillaCaves.get();
|
||||
}
|
||||
|
||||
public boolean vanillaDecorations() {
|
||||
return vanillaDecorations;
|
||||
return vanillaDecorations.get();
|
||||
}
|
||||
|
||||
public boolean vanillaStructures() {
|
||||
return vanillaStructures;
|
||||
return vanillaStructures.get();
|
||||
}
|
||||
|
||||
public Map<String, NoiseSeeded> getNoiseBuilderMap() {
|
||||
return noiseBuilderMap;
|
||||
return lazyNoiseBuilderMap.get();
|
||||
}
|
||||
|
||||
public Map<String, Double> getVariables() {
|
||||
return variables;
|
||||
return lazyVariables.get();
|
||||
}
|
||||
|
||||
public int getElevationBlend() {
|
||||
return elevationBlend;
|
||||
return elevationBlend.get();
|
||||
}
|
||||
|
||||
public Map<String, String> getLocatable() {
|
||||
return locatable;
|
||||
return lazyLocatable.get();
|
||||
}
|
||||
|
||||
public boolean doBetaCarvers() {
|
||||
return betaCarvers;
|
||||
return betaCarvers.get();
|
||||
}
|
||||
|
||||
public Set<TerraAddon> getAddons() {
|
||||
|
||||
Reference in New Issue
Block a user