mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-17 14:21:08 +00:00
update to tectonic 2.0.0
This commit is contained in:
@@ -16,8 +16,6 @@ dependencies {
|
|||||||
"shadedApi"(project(":common:api"))
|
"shadedApi"(project(":common:api"))
|
||||||
"compileOnly"("com.google.guava:guava:30.0-jre")
|
"compileOnly"("com.google.guava:guava:30.0-jre")
|
||||||
|
|
||||||
"shadedApi"("com.dfsek.tectonic:yaml:2.0.0")
|
|
||||||
|
|
||||||
"testImplementation"("com.google.guava:guava:30.0-jre")
|
"testImplementation"("com.google.guava:guava:30.0-jre")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,9 +13,10 @@ configureDependencies()
|
|||||||
group = "com.dfsek.terra.common"
|
group = "com.dfsek.terra.common"
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
|
||||||
"shadedApi"("com.dfsek:Paralithic:0.3.2")
|
"shadedApi"("com.dfsek:Paralithic:0.3.2")
|
||||||
"shadedApi"("com.dfsek.tectonic:common:2.0.0")
|
|
||||||
|
"shadedApi"("com.dfsek.tectonic:common:2.1.0")
|
||||||
|
"shadedApi"("com.dfsek.tectonic:yaml:2.1.0")
|
||||||
|
|
||||||
"shadedApi"("net.jafama:jafama:2.3.2")
|
"shadedApi"("net.jafama:jafama:2.3.2")
|
||||||
"shadedApi"("org.yaml:snakeyaml:1.27")
|
"shadedApi"("org.yaml:snakeyaml:1.27")
|
||||||
|
|||||||
@@ -11,12 +11,6 @@ import java.util.Map;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public interface Loader {
|
public interface Loader {
|
||||||
/**
|
|
||||||
* Do something with the InputStreams.
|
|
||||||
*
|
|
||||||
* @param consumer Something to do with the streams.
|
|
||||||
*/
|
|
||||||
Loader then(ExceptionalConsumer<List<Configuration>> consumer) throws ConfigException;
|
|
||||||
|
|
||||||
Loader thenNames(ExceptionalConsumer<List<String>> consumer) throws ConfigException;
|
Loader thenNames(ExceptionalConsumer<List<String>> consumer) throws ConfigException;
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import com.dfsek.tectonic.annotations.Value;
|
|||||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||||
import com.dfsek.tectonic.exception.ConfigException;
|
import com.dfsek.tectonic.exception.ConfigException;
|
||||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||||
|
import com.dfsek.tectonic.yaml.YamlConfiguration;
|
||||||
import com.dfsek.terra.api.Logger;
|
import com.dfsek.terra.api.Logger;
|
||||||
import com.dfsek.terra.api.TerraPlugin;
|
import com.dfsek.terra.api.TerraPlugin;
|
||||||
import com.dfsek.terra.api.util.JarUtil;
|
import com.dfsek.terra.api.util.JarUtil;
|
||||||
@@ -80,7 +81,7 @@ public class PluginConfigImpl implements ConfigTemplate, com.dfsek.terra.api.con
|
|||||||
logger.info("Loading config values");
|
logger.info("Loading config values");
|
||||||
try(FileInputStream file = new FileInputStream(new File(main.getDataFolder(), "config.yml"))) {
|
try(FileInputStream file = new FileInputStream(new File(main.getDataFolder(), "config.yml"))) {
|
||||||
ConfigLoader loader = new ConfigLoader();
|
ConfigLoader loader = new ConfigLoader();
|
||||||
loader.load(this, file);
|
loader.load(this, new YamlConfiguration(file, "config.yml"));
|
||||||
if(dumpDefaultConfig) { // Don't dump default config if already loaded.
|
if(dumpDefaultConfig) { // Don't dump default config if already loaded.
|
||||||
try(JarFile jar = main.getModJar()) {
|
try(JarFile jar = main.getModJar()) {
|
||||||
JarUtil.copyResourcesToDirectory(jar, "packs", new File(main.getDataFolder(), "packs").toString());
|
JarUtil.copyResourcesToDirectory(jar, "packs", new File(main.getDataFolder(), "packs").toString());
|
||||||
|
|||||||
-16
@@ -1,6 +1,5 @@
|
|||||||
package com.dfsek.terra.config.fileloaders;
|
package com.dfsek.terra.config.fileloaders;
|
||||||
|
|
||||||
import com.dfsek.tectonic.config.Configuration;
|
|
||||||
import com.dfsek.tectonic.exception.ConfigException;
|
import com.dfsek.tectonic.exception.ConfigException;
|
||||||
import com.dfsek.terra.api.config.Loader;
|
import com.dfsek.terra.api.config.Loader;
|
||||||
import com.dfsek.terra.api.util.function.ExceptionalConsumer;
|
import com.dfsek.terra.api.util.function.ExceptionalConsumer;
|
||||||
@@ -16,21 +15,6 @@ import java.util.Set;
|
|||||||
public abstract class LoaderImpl implements Loader {
|
public abstract class LoaderImpl implements Loader {
|
||||||
protected final Map<String, InputStream> streams = new HashMap<>();
|
protected final Map<String, InputStream> streams = new HashMap<>();
|
||||||
|
|
||||||
/**
|
|
||||||
* Do something with the InputStreams.
|
|
||||||
*
|
|
||||||
* @param consumer Something to do with the streams.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Loader then(ExceptionalConsumer<List<Configuration>> consumer) throws ConfigException {
|
|
||||||
List<Configuration> list = new ArrayList<>();
|
|
||||||
streams.forEach((id, stream) -> {
|
|
||||||
list.add(new Configuration(stream, id));
|
|
||||||
});
|
|
||||||
consumer.accept(list);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Loader thenNames(ExceptionalConsumer<List<String>> consumer) throws ConfigException {
|
public Loader thenNames(ExceptionalConsumer<List<String>> consumer) throws ConfigException {
|
||||||
consumer.accept(new ArrayList<>(streams.keySet()));
|
consumer.accept(new ArrayList<>(streams.keySet()));
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.dfsek.terra.config.lang;
|
|||||||
|
|
||||||
|
|
||||||
import com.dfsek.tectonic.config.Configuration;
|
import com.dfsek.tectonic.config.Configuration;
|
||||||
|
import com.dfsek.tectonic.yaml.YamlConfiguration;
|
||||||
import com.dfsek.terra.api.entity.CommandSender;
|
import com.dfsek.terra.api.entity.CommandSender;
|
||||||
import com.dfsek.terra.api.lang.Message;
|
import com.dfsek.terra.api.lang.Message;
|
||||||
|
|
||||||
@@ -16,7 +17,7 @@ public class LanguageImpl implements com.dfsek.terra.api.lang.Language {
|
|||||||
private final Configuration configuration;
|
private final Configuration configuration;
|
||||||
|
|
||||||
public LanguageImpl(File file) throws IOException {
|
public LanguageImpl(File file) throws IOException {
|
||||||
configuration = new Configuration(new FileInputStream(file));
|
configuration = new YamlConfiguration(new FileInputStream(file), file.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+7
-5
@@ -4,6 +4,8 @@ import com.dfsek.tectonic.exception.LoadException;
|
|||||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||||
import com.dfsek.tectonic.loading.TypeLoader;
|
import com.dfsek.tectonic.loading.TypeLoader;
|
||||||
|
|
||||||
|
import java.lang.reflect.AnnotatedParameterizedType;
|
||||||
|
import java.lang.reflect.AnnotatedType;
|
||||||
import java.lang.reflect.ParameterizedType;
|
import java.lang.reflect.ParameterizedType;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
@@ -12,13 +14,13 @@ import java.util.Map;
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public class LinkedHashMapLoader implements TypeLoader<LinkedHashMap<Object, Object>> {
|
public class LinkedHashMapLoader implements TypeLoader<LinkedHashMap<Object, Object>> {
|
||||||
@Override
|
@Override
|
||||||
public LinkedHashMap<Object, Object> load(Type t, Object c, ConfigLoader loader) throws LoadException {
|
public LinkedHashMap<Object, Object> load(AnnotatedType t, Object c, ConfigLoader loader) throws LoadException {
|
||||||
Map<String, Object> config = (Map<String, Object>) c;
|
Map<String, Object> config = (Map<String, Object>) c;
|
||||||
LinkedHashMap<Object, Object> map = new LinkedHashMap<>();
|
LinkedHashMap<Object, Object> map = new LinkedHashMap<>();
|
||||||
if(t instanceof ParameterizedType) {
|
if(t instanceof AnnotatedParameterizedType) {
|
||||||
ParameterizedType pType = (ParameterizedType) t;
|
AnnotatedParameterizedType pType = (AnnotatedParameterizedType) t;
|
||||||
Type key = pType.getActualTypeArguments()[0];
|
AnnotatedType key = pType.getAnnotatedActualTypeArguments()[0];
|
||||||
Type value = pType.getActualTypeArguments()[1];
|
AnnotatedType value = pType.getAnnotatedActualTypeArguments()[1];
|
||||||
for(Map.Entry<String, Object> entry : config.entrySet()) {
|
for(Map.Entry<String, Object> entry : config.entrySet()) {
|
||||||
map.put(loader.loadType(key, entry.getKey()), loader.loadType(value, entry.getValue()));
|
map.put(loader.loadType(key, entry.getKey()), loader.loadType(value, entry.getValue()));
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-2
@@ -6,19 +6,20 @@ import com.dfsek.tectonic.loading.TypeLoader;
|
|||||||
import com.dfsek.terra.api.block.BlockType;
|
import com.dfsek.terra.api.block.BlockType;
|
||||||
import com.dfsek.terra.api.util.collection.MaterialSet;
|
import com.dfsek.terra.api.util.collection.MaterialSet;
|
||||||
|
|
||||||
|
import java.lang.reflect.AnnotatedType;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public class MaterialSetLoader implements TypeLoader<MaterialSet> {
|
public class MaterialSetLoader implements TypeLoader<MaterialSet> {
|
||||||
@Override
|
@Override
|
||||||
public MaterialSet load(Type type, Object o, ConfigLoader configLoader) throws LoadException {
|
public MaterialSet load(AnnotatedType type, Object o, ConfigLoader configLoader) throws LoadException {
|
||||||
List<String> stringData = (List<String>) o;
|
List<String> stringData = (List<String>) o;
|
||||||
MaterialSet set = new MaterialSet();
|
MaterialSet set = new MaterialSet();
|
||||||
|
|
||||||
for(String string : stringData) {
|
for(String string : stringData) {
|
||||||
try {
|
try {
|
||||||
set.add(configLoader.loadClass(BlockType.class, string));
|
set.add(configLoader.loadType(BlockType.class, string));
|
||||||
} catch(NullPointerException e) {
|
} catch(NullPointerException e) {
|
||||||
throw new LoadException("Invalid data identifier \"" + string + "\"", e);
|
throw new LoadException("Invalid data identifier \"" + string + "\"", e);
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-4
@@ -5,6 +5,8 @@ import com.dfsek.tectonic.loading.ConfigLoader;
|
|||||||
import com.dfsek.tectonic.loading.TypeLoader;
|
import com.dfsek.tectonic.loading.TypeLoader;
|
||||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||||
|
|
||||||
|
import java.lang.reflect.AnnotatedParameterizedType;
|
||||||
|
import java.lang.reflect.AnnotatedType;
|
||||||
import java.lang.reflect.ParameterizedType;
|
import java.lang.reflect.ParameterizedType;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -13,12 +15,12 @@ import java.util.Map;
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public class ProbabilityCollectionLoader implements TypeLoader<ProbabilityCollection<Object>> {
|
public class ProbabilityCollectionLoader implements TypeLoader<ProbabilityCollection<Object>> {
|
||||||
@Override
|
@Override
|
||||||
public ProbabilityCollection<Object> load(Type type, Object o, ConfigLoader configLoader) throws LoadException {
|
public ProbabilityCollection<Object> load(AnnotatedType type, Object o, ConfigLoader configLoader) throws LoadException {
|
||||||
ProbabilityCollection<Object> collection = new ProbabilityCollection<>();
|
ProbabilityCollection<Object> collection = new ProbabilityCollection<>();
|
||||||
|
|
||||||
if(type instanceof ParameterizedType) {
|
if(type instanceof AnnotatedParameterizedType) {
|
||||||
ParameterizedType pType = (ParameterizedType) type;
|
AnnotatedParameterizedType pType = (AnnotatedParameterizedType) type;
|
||||||
Type generic = pType.getActualTypeArguments()[0];
|
AnnotatedType generic = pType.getAnnotatedActualTypeArguments()[0];
|
||||||
if(o instanceof Map) {
|
if(o instanceof Map) {
|
||||||
Map<Object, Integer> map = (Map<Object, Integer>) o;
|
Map<Object, Integer> map = (Map<Object, Integer>) o;
|
||||||
for(Map.Entry<Object, Integer> entry : map.entrySet()) {
|
for(Map.Entry<Object, Integer> entry : map.entrySet()) {
|
||||||
|
|||||||
@@ -6,13 +6,14 @@ import com.dfsek.tectonic.loading.TypeLoader;
|
|||||||
import com.dfsek.terra.api.util.ConstantRange;
|
import com.dfsek.terra.api.util.ConstantRange;
|
||||||
import com.dfsek.terra.api.util.Range;
|
import com.dfsek.terra.api.util.Range;
|
||||||
|
|
||||||
|
import java.lang.reflect.AnnotatedType;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public class RangeLoader implements TypeLoader<Range> {
|
public class RangeLoader implements TypeLoader<Range> {
|
||||||
@Override
|
@Override
|
||||||
public Range load(Type type, Object o, ConfigLoader configLoader) throws LoadException {
|
public Range load(AnnotatedType type, Object o, ConfigLoader configLoader) throws LoadException {
|
||||||
Map<String, Integer> map = (Map<String, Integer>) o;
|
Map<String, Integer> map = (Map<String, Integer>) o;
|
||||||
return new ConstantRange(map.get("min"), map.get("max"));
|
return new ConstantRange(map.get("min"), map.get("max"));
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -8,6 +8,7 @@ import com.dfsek.terra.api.config.Loader;
|
|||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.AnnotatedType;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
|
||||||
public class BufferedImageLoader implements TypeLoader<BufferedImage> {
|
public class BufferedImageLoader implements TypeLoader<BufferedImage> {
|
||||||
@@ -18,7 +19,7 @@ public class BufferedImageLoader implements TypeLoader<BufferedImage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BufferedImage load(Type t, Object c, ConfigLoader loader) throws LoadException {
|
public BufferedImage load(AnnotatedType t, Object c, ConfigLoader loader) throws LoadException {
|
||||||
try {
|
try {
|
||||||
return ImageIO.read(files.get((String) c));
|
return ImageIO.read(files.get((String) c));
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
|
|||||||
+2
-1
@@ -5,13 +5,14 @@ import com.dfsek.tectonic.loading.TypeLoader;
|
|||||||
import com.dfsek.terra.api.structure.StructureSpawn;
|
import com.dfsek.terra.api.structure.StructureSpawn;
|
||||||
import com.dfsek.terra.math.GridSpawn;
|
import com.dfsek.terra.math.GridSpawn;
|
||||||
|
|
||||||
|
import java.lang.reflect.AnnotatedType;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public class GridSpawnLoader implements TypeLoader<StructureSpawn> {
|
public class GridSpawnLoader implements TypeLoader<StructureSpawn> {
|
||||||
@Override
|
@Override
|
||||||
public StructureSpawn load(Type type, Object o, ConfigLoader configLoader) {
|
public StructureSpawn load(AnnotatedType type, Object o, ConfigLoader configLoader) {
|
||||||
Map<String, Integer> map = (Map<String, Integer>) o;
|
Map<String, Integer> map = (Map<String, Integer>) o;
|
||||||
return new GridSpawn(map.get("width"), map.get("padding"), map.getOrDefault("salt", 0));
|
return new GridSpawn(map.get("width"), map.get("padding"), map.getOrDefault("salt", 0));
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-9
@@ -2,7 +2,7 @@ package com.dfsek.terra.config.pack;
|
|||||||
|
|
||||||
import com.dfsek.paralithic.eval.parser.Scope;
|
import com.dfsek.paralithic.eval.parser.Scope;
|
||||||
import com.dfsek.tectonic.abstraction.AbstractConfigLoader;
|
import com.dfsek.tectonic.abstraction.AbstractConfigLoader;
|
||||||
import com.dfsek.tectonic.abstraction.TemplateProvider;
|
import com.dfsek.tectonic.abstraction.AbstractConfiguration;
|
||||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||||
import com.dfsek.tectonic.config.Configuration;
|
import com.dfsek.tectonic.config.Configuration;
|
||||||
import com.dfsek.tectonic.exception.ConfigException;
|
import com.dfsek.tectonic.exception.ConfigException;
|
||||||
@@ -11,15 +11,16 @@ import com.dfsek.tectonic.loading.ConfigLoader;
|
|||||||
import com.dfsek.tectonic.loading.TypeLoader;
|
import com.dfsek.tectonic.loading.TypeLoader;
|
||||||
import com.dfsek.tectonic.loading.TypeRegistry;
|
import com.dfsek.tectonic.loading.TypeRegistry;
|
||||||
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
||||||
|
import com.dfsek.tectonic.yaml.YamlConfiguration;
|
||||||
import com.dfsek.terra.api.TerraPlugin;
|
import com.dfsek.terra.api.TerraPlugin;
|
||||||
import com.dfsek.terra.api.addon.TerraAddon;
|
import com.dfsek.terra.api.addon.TerraAddon;
|
||||||
import com.dfsek.terra.api.config.AbstractableTemplate;
|
|
||||||
import com.dfsek.terra.api.config.ConfigFactory;
|
import com.dfsek.terra.api.config.ConfigFactory;
|
||||||
import com.dfsek.terra.api.config.ConfigPack;
|
import com.dfsek.terra.api.config.ConfigPack;
|
||||||
import com.dfsek.terra.api.config.ConfigType;
|
import com.dfsek.terra.api.config.ConfigType;
|
||||||
import com.dfsek.terra.api.config.Loader;
|
import com.dfsek.terra.api.config.Loader;
|
||||||
import com.dfsek.terra.api.event.events.config.ConfigPackPostLoadEvent;
|
import com.dfsek.terra.api.event.events.config.ConfigPackPostLoadEvent;
|
||||||
import com.dfsek.terra.api.event.events.config.ConfigPackPreLoadEvent;
|
import com.dfsek.terra.api.event.events.config.ConfigPackPreLoadEvent;
|
||||||
|
import com.dfsek.terra.api.event.events.config.ConfigurationLoadEvent;
|
||||||
import com.dfsek.terra.api.registry.CheckedRegistry;
|
import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||||
import com.dfsek.terra.api.registry.OpenRegistry;
|
import com.dfsek.terra.api.registry.OpenRegistry;
|
||||||
import com.dfsek.terra.api.registry.exception.DuplicateEntryException;
|
import com.dfsek.terra.api.registry.exception.DuplicateEntryException;
|
||||||
@@ -106,7 +107,7 @@ public class ConfigPackImpl implements ConfigPack {
|
|||||||
File pack = new File(folder, "pack.yml");
|
File pack = new File(folder, "pack.yml");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
configuration = new Configuration(new FileInputStream(pack));
|
this.configuration = new YamlConfiguration(new FileInputStream(pack), "pack.yml");
|
||||||
|
|
||||||
ConfigPackAddonsTemplate addonsTemplate = new ConfigPackAddonsTemplate();
|
ConfigPackAddonsTemplate addonsTemplate = new ConfigPackAddonsTemplate();
|
||||||
selfLoader.load(addonsTemplate, configuration);
|
selfLoader.load(addonsTemplate, configuration);
|
||||||
@@ -120,7 +121,7 @@ public class ConfigPackImpl implements ConfigPack {
|
|||||||
load(l, main);
|
load(l, main);
|
||||||
|
|
||||||
ConfigPackPostTemplate packPostTemplate = new ConfigPackPostTemplate();
|
ConfigPackPostTemplate packPostTemplate = new ConfigPackPostTemplate();
|
||||||
selfLoader.load(packPostTemplate, new FileInputStream(pack));
|
selfLoader.load(packPostTemplate, configuration);
|
||||||
biomeProviderBuilder = packPostTemplate.getProviderBuilder();
|
biomeProviderBuilder = packPostTemplate.getProviderBuilder();
|
||||||
biomeProviderBuilder.build(0); // Build dummy provider to catch errors at load time.
|
biomeProviderBuilder.build(0); // Build dummy provider to catch errors at load time.
|
||||||
checkDeadEntries(main);
|
checkDeadEntries(main);
|
||||||
@@ -162,7 +163,7 @@ public class ConfigPackImpl implements ConfigPack {
|
|||||||
|
|
||||||
if(pack == null) throw new LoadException("No pack.yml file found in " + file.getName());
|
if(pack == null) throw new LoadException("No pack.yml file found in " + file.getName());
|
||||||
|
|
||||||
configuration = new Configuration(file.getInputStream(pack));
|
this.configuration = new YamlConfiguration(file.getInputStream(pack), "pack.yml");
|
||||||
|
|
||||||
ConfigPackAddonsTemplate addonsTemplate = new ConfigPackAddonsTemplate();
|
ConfigPackAddonsTemplate addonsTemplate = new ConfigPackAddonsTemplate();
|
||||||
selfLoader.load(addonsTemplate, configuration);
|
selfLoader.load(addonsTemplate, configuration);
|
||||||
@@ -178,7 +179,7 @@ public class ConfigPackImpl implements ConfigPack {
|
|||||||
|
|
||||||
ConfigPackPostTemplate packPostTemplate = new ConfigPackPostTemplate();
|
ConfigPackPostTemplate packPostTemplate = new ConfigPackPostTemplate();
|
||||||
|
|
||||||
selfLoader.load(packPostTemplate, file.getInputStream(pack));
|
selfLoader.load(packPostTemplate, configuration);
|
||||||
biomeProviderBuilder = packPostTemplate.getProviderBuilder();
|
biomeProviderBuilder = packPostTemplate.getProviderBuilder();
|
||||||
biomeProviderBuilder.build(0); // Build dummy provider to catch errors at load time.
|
biomeProviderBuilder.build(0); // Build dummy provider to catch errors at load time.
|
||||||
checkDeadEntries(main);
|
checkDeadEntries(main);
|
||||||
@@ -225,7 +226,7 @@ public class ConfigPackImpl implements ConfigPack {
|
|||||||
|
|
||||||
List<Configuration> configurations = new ArrayList<>();
|
List<Configuration> configurations = new ArrayList<>();
|
||||||
|
|
||||||
loader.open("", ".yml").thenEntries(entries -> entries.forEach(stream -> configurations.add(new Configuration(stream.getValue(), stream.getKey()))));
|
main.getEventManager().callEvent(new ConfigurationLoadEvent(this, loader, configurations::add));
|
||||||
|
|
||||||
Map<ConfigType<? extends ConfigTemplate, ?>, List<Configuration>> configs = new HashMap<>();
|
Map<ConfigType<? extends ConfigTemplate, ?>, List<Configuration>> configs = new HashMap<>();
|
||||||
|
|
||||||
@@ -236,9 +237,10 @@ public class ConfigPackImpl implements ConfigPack {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for(ConfigType<?, ?> configType : configTypeRegistry.entries()) {
|
for(ConfigType<?, ?> configType : configTypeRegistry.entries()) {
|
||||||
for(AbstractableTemplate config : abstractConfigLoader.loadConfigs(configs.getOrDefault(configType, Collections.emptyList()), () -> configType.getTemplate(this, main))) {
|
CheckedRegistry registry = getCheckedRegistry(configType.getTypeClass());
|
||||||
|
for(AbstractConfiguration config : abstractConfigLoader.loadConfigs(configs.getOrDefault(configType, Collections.emptyList()))) {
|
||||||
try {
|
try {
|
||||||
((CheckedRegistry) getCheckedRegistry(configType.getTypeClass())).register(config.getID(), ((ConfigFactory) configType.getFactory()).build(config, main));
|
registry.register(config.getID(), ((ConfigFactory) configType.getFactory()).build(selfLoader.load(configType.getTemplate(this, main), config), main));
|
||||||
} catch(DuplicateEntryException e) {
|
} catch(DuplicateEntryException e) {
|
||||||
throw new LoadException("Duplicate registry entry: ", e);
|
throw new LoadException("Duplicate registry entry: ", e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.dfsek.terra.fabric;
|
package com.dfsek.terra.fabric;
|
||||||
|
|
||||||
import com.dfsek.tectonic.abstraction.TemplateProvider;
|
|
||||||
import com.dfsek.tectonic.exception.ConfigException;
|
import com.dfsek.tectonic.exception.ConfigException;
|
||||||
import com.dfsek.tectonic.exception.LoadException;
|
import com.dfsek.tectonic.exception.LoadException;
|
||||||
import com.dfsek.tectonic.loading.TypeLoader;
|
import com.dfsek.tectonic.loading.TypeLoader;
|
||||||
@@ -83,6 +82,7 @@ import java.io.InputStream;
|
|||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
|
||||||
public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||||
@@ -93,7 +93,7 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
|||||||
private final Map<DimensionType, Pair<ServerWorld, TerraWorld>> worldMap = new HashMap<>();
|
private final Map<DimensionType, Pair<ServerWorld, TerraWorld>> worldMap = new HashMap<>();
|
||||||
|
|
||||||
private final Map<Type, TypeLoader<?>> loaders = new HashMap<>();
|
private final Map<Type, TypeLoader<?>> loaders = new HashMap<>();
|
||||||
private final Map<Type, TemplateProvider<ObjectTemplate<?>>> objectLoaders = new HashMap<>();
|
private final Map<Type, Supplier<ObjectTemplate<?>>> objectLoaders = new HashMap<>();
|
||||||
private final EventManager eventManager = new EventManagerImpl(this);
|
private final EventManager eventManager = new EventManagerImpl(this);
|
||||||
private final GenericLoaders genericLoaders = new GenericLoaders(this);
|
private final GenericLoaders genericLoaders = new GenericLoaders(this);
|
||||||
private final Profiler profiler = new ProfilerImpl();
|
private final Profiler profiler = new ProfilerImpl();
|
||||||
@@ -244,7 +244,7 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
|||||||
return identifier;
|
return identifier;
|
||||||
});
|
});
|
||||||
loaders.forEach(registry::registerLoader);
|
loaders.forEach(registry::registerLoader);
|
||||||
objectLoaders.forEach((t, l) -> registry.registerLoader(t, (TemplateProvider<ObjectTemplate<Object>>) ((Object) l)));
|
objectLoaders.forEach((t, l) -> registry.registerLoader(t, (Supplier<ObjectTemplate<Object>>) ((Object) l)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -301,8 +301,8 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
|||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public <T> TerraFabricPlugin applyLoader(Type type, TemplateProvider<ObjectTemplate<T>> loader) {
|
public <T> TerraFabricPlugin applyLoader(Type type, Supplier<ObjectTemplate<T>> loader) {
|
||||||
objectLoaders.put(type, (TemplateProvider<ObjectTemplate<?>>) ((Object) loader));
|
objectLoaders.put(type, (Supplier<ObjectTemplate<?>>) ((Object) loader));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user