mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-06 15:56:14 +00:00
update to tectonic 2.0.0
This commit is contained in:
@@ -16,8 +16,6 @@ dependencies {
|
||||
"shadedApi"(project(":common:api"))
|
||||
"compileOnly"("com.google.guava:guava:30.0-jre")
|
||||
|
||||
"shadedApi"("com.dfsek.tectonic:yaml:2.0.0")
|
||||
|
||||
"testImplementation"("com.google.guava:guava:30.0-jre")
|
||||
}
|
||||
|
||||
|
||||
@@ -13,9 +13,10 @@ configureDependencies()
|
||||
group = "com.dfsek.terra.common"
|
||||
|
||||
dependencies {
|
||||
|
||||
"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"("org.yaml:snakeyaml:1.27")
|
||||
|
||||
@@ -11,12 +11,6 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
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;
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||
import com.dfsek.tectonic.exception.ConfigException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.tectonic.yaml.YamlConfiguration;
|
||||
import com.dfsek.terra.api.Logger;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
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");
|
||||
try(FileInputStream file = new FileInputStream(new File(main.getDataFolder(), "config.yml"))) {
|
||||
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.
|
||||
try(JarFile jar = main.getModJar()) {
|
||||
JarUtil.copyResourcesToDirectory(jar, "packs", new File(main.getDataFolder(), "packs").toString());
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.dfsek.terra.config.fileloaders;
|
||||
|
||||
import com.dfsek.tectonic.config.Configuration;
|
||||
import com.dfsek.tectonic.exception.ConfigException;
|
||||
import com.dfsek.terra.api.config.Loader;
|
||||
import com.dfsek.terra.api.util.function.ExceptionalConsumer;
|
||||
@@ -16,21 +15,6 @@ import java.util.Set;
|
||||
public abstract class LoaderImpl implements Loader {
|
||||
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
|
||||
public Loader thenNames(ExceptionalConsumer<List<String>> consumer) throws ConfigException {
|
||||
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.yaml.YamlConfiguration;
|
||||
import com.dfsek.terra.api.entity.CommandSender;
|
||||
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;
|
||||
|
||||
public LanguageImpl(File file) throws IOException {
|
||||
configuration = new Configuration(new FileInputStream(file));
|
||||
configuration = new YamlConfiguration(new FileInputStream(file), file.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -4,6 +4,8 @@ import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
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.Type;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -12,13 +14,13 @@ import java.util.Map;
|
||||
@SuppressWarnings("unchecked")
|
||||
public class LinkedHashMapLoader implements TypeLoader<LinkedHashMap<Object, Object>> {
|
||||
@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;
|
||||
LinkedHashMap<Object, Object> map = new LinkedHashMap<>();
|
||||
if(t instanceof ParameterizedType) {
|
||||
ParameterizedType pType = (ParameterizedType) t;
|
||||
Type key = pType.getActualTypeArguments()[0];
|
||||
Type value = pType.getActualTypeArguments()[1];
|
||||
if(t instanceof AnnotatedParameterizedType) {
|
||||
AnnotatedParameterizedType pType = (AnnotatedParameterizedType) t;
|
||||
AnnotatedType key = pType.getAnnotatedActualTypeArguments()[0];
|
||||
AnnotatedType value = pType.getAnnotatedActualTypeArguments()[1];
|
||||
for(Map.Entry<String, Object> entry : config.entrySet()) {
|
||||
map.put(loader.loadType(key, entry.getKey()), loader.loadType(value, entry.getValue()));
|
||||
}
|
||||
|
||||
@@ -6,19 +6,20 @@ import com.dfsek.tectonic.loading.TypeLoader;
|
||||
import com.dfsek.terra.api.block.BlockType;
|
||||
import com.dfsek.terra.api.util.collection.MaterialSet;
|
||||
|
||||
import java.lang.reflect.AnnotatedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class MaterialSetLoader implements TypeLoader<MaterialSet> {
|
||||
@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;
|
||||
MaterialSet set = new MaterialSet();
|
||||
|
||||
for(String string : stringData) {
|
||||
try {
|
||||
set.add(configLoader.loadClass(BlockType.class, string));
|
||||
set.add(configLoader.loadType(BlockType.class, string));
|
||||
} catch(NullPointerException e) {
|
||||
throw new LoadException("Invalid data identifier \"" + string + "\"", e);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.tectonic.loading.TypeLoader;
|
||||
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.Type;
|
||||
import java.util.List;
|
||||
@@ -13,12 +15,12 @@ import java.util.Map;
|
||||
@SuppressWarnings("unchecked")
|
||||
public class ProbabilityCollectionLoader implements TypeLoader<ProbabilityCollection<Object>> {
|
||||
@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<>();
|
||||
|
||||
if(type instanceof ParameterizedType) {
|
||||
ParameterizedType pType = (ParameterizedType) type;
|
||||
Type generic = pType.getActualTypeArguments()[0];
|
||||
if(type instanceof AnnotatedParameterizedType) {
|
||||
AnnotatedParameterizedType pType = (AnnotatedParameterizedType) type;
|
||||
AnnotatedType generic = pType.getAnnotatedActualTypeArguments()[0];
|
||||
if(o instanceof Map) {
|
||||
Map<Object, Integer> map = (Map<Object, Integer>) o;
|
||||
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.Range;
|
||||
|
||||
import java.lang.reflect.AnnotatedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class RangeLoader implements TypeLoader<Range> {
|
||||
@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;
|
||||
return new ConstantRange(map.get("min"), map.get("max"));
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.dfsek.terra.api.config.Loader;
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.AnnotatedType;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class BufferedImageLoader implements TypeLoader<BufferedImage> {
|
||||
@@ -18,7 +19,7 @@ public class BufferedImageLoader implements TypeLoader<BufferedImage> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BufferedImage load(Type t, Object c, ConfigLoader loader) throws LoadException {
|
||||
public BufferedImage load(AnnotatedType t, Object c, ConfigLoader loader) throws LoadException {
|
||||
try {
|
||||
return ImageIO.read(files.get((String) c));
|
||||
} catch(IOException e) {
|
||||
|
||||
@@ -5,13 +5,14 @@ import com.dfsek.tectonic.loading.TypeLoader;
|
||||
import com.dfsek.terra.api.structure.StructureSpawn;
|
||||
import com.dfsek.terra.math.GridSpawn;
|
||||
|
||||
import java.lang.reflect.AnnotatedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class GridSpawnLoader implements TypeLoader<StructureSpawn> {
|
||||
@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;
|
||||
return new GridSpawn(map.get("width"), map.get("padding"), map.getOrDefault("salt", 0));
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.dfsek.terra.config.pack;
|
||||
|
||||
import com.dfsek.paralithic.eval.parser.Scope;
|
||||
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.Configuration;
|
||||
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.TypeRegistry;
|
||||
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
||||
import com.dfsek.tectonic.yaml.YamlConfiguration;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
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.ConfigPack;
|
||||
import com.dfsek.terra.api.config.ConfigType;
|
||||
import com.dfsek.terra.api.config.Loader;
|
||||
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.ConfigurationLoadEvent;
|
||||
import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||
import com.dfsek.terra.api.registry.OpenRegistry;
|
||||
import com.dfsek.terra.api.registry.exception.DuplicateEntryException;
|
||||
@@ -106,7 +107,7 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
File pack = new File(folder, "pack.yml");
|
||||
|
||||
try {
|
||||
configuration = new Configuration(new FileInputStream(pack));
|
||||
this.configuration = new YamlConfiguration(new FileInputStream(pack), "pack.yml");
|
||||
|
||||
ConfigPackAddonsTemplate addonsTemplate = new ConfigPackAddonsTemplate();
|
||||
selfLoader.load(addonsTemplate, configuration);
|
||||
@@ -120,7 +121,7 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
load(l, main);
|
||||
|
||||
ConfigPackPostTemplate packPostTemplate = new ConfigPackPostTemplate();
|
||||
selfLoader.load(packPostTemplate, new FileInputStream(pack));
|
||||
selfLoader.load(packPostTemplate, configuration);
|
||||
biomeProviderBuilder = packPostTemplate.getProviderBuilder();
|
||||
biomeProviderBuilder.build(0); // Build dummy provider to catch errors at load time.
|
||||
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());
|
||||
|
||||
configuration = new Configuration(file.getInputStream(pack));
|
||||
this.configuration = new YamlConfiguration(file.getInputStream(pack), "pack.yml");
|
||||
|
||||
ConfigPackAddonsTemplate addonsTemplate = new ConfigPackAddonsTemplate();
|
||||
selfLoader.load(addonsTemplate, configuration);
|
||||
@@ -178,7 +179,7 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
|
||||
ConfigPackPostTemplate packPostTemplate = new ConfigPackPostTemplate();
|
||||
|
||||
selfLoader.load(packPostTemplate, file.getInputStream(pack));
|
||||
selfLoader.load(packPostTemplate, configuration);
|
||||
biomeProviderBuilder = packPostTemplate.getProviderBuilder();
|
||||
biomeProviderBuilder.build(0); // Build dummy provider to catch errors at load time.
|
||||
checkDeadEntries(main);
|
||||
@@ -225,7 +226,7 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
|
||||
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<>();
|
||||
|
||||
@@ -236,9 +237,10 @@ public class ConfigPackImpl implements ConfigPack {
|
||||
}
|
||||
|
||||
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 {
|
||||
((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) {
|
||||
throw new LoadException("Duplicate registry entry: ", e);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.dfsek.terra.fabric;
|
||||
|
||||
import com.dfsek.tectonic.abstraction.TemplateProvider;
|
||||
import com.dfsek.tectonic.exception.ConfigException;
|
||||
import com.dfsek.tectonic.exception.LoadException;
|
||||
import com.dfsek.tectonic.loading.TypeLoader;
|
||||
@@ -83,6 +82,7 @@ import java.io.InputStream;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
|
||||
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<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 GenericLoaders genericLoaders = new GenericLoaders(this);
|
||||
private final Profiler profiler = new ProfilerImpl();
|
||||
@@ -244,7 +244,7 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
return identifier;
|
||||
});
|
||||
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
|
||||
@@ -301,8 +301,8 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T> TerraFabricPlugin applyLoader(Type type, TemplateProvider<ObjectTemplate<T>> loader) {
|
||||
objectLoaders.put(type, (TemplateProvider<ObjectTemplate<?>>) ((Object) loader));
|
||||
public <T> TerraFabricPlugin applyLoader(Type type, Supplier<ObjectTemplate<T>> loader) {
|
||||
objectLoaders.put(type, (Supplier<ObjectTemplate<?>>) ((Object) loader));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user