mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-10-26 05:50:08 +00:00
move compat options to compat.yml
This commit is contained in:
1 parent
bb2601252a
commit
1bd5cf31fa
2 files changed
+29
-4
No files matched your search
@@ -1,5 +1,6 @@
|
|||||||
package com.dfsek.terra.config.fileloaders;
|
package com.dfsek.terra.config.fileloaders;
|
||||||
|
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
@@ -20,7 +21,7 @@ public class ZIPLoader extends Loader {
|
|||||||
ZipEntry entry = entries.nextElement();
|
ZipEntry entry = entries.nextElement();
|
||||||
if(!entry.isDirectory() && entry.getName().equals(singleFile)) return file.getInputStream(entry);
|
if(!entry.isDirectory() && entry.getName().equals(singleFile)) return file.getInputStream(entry);
|
||||||
}
|
}
|
||||||
throw new IllegalArgumentException("No such file: " + singleFile);
|
throw new FileNotFoundException("No such file: " + singleFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
package com.dfsek.terra.fabric;
|
package com.dfsek.terra.fabric;
|
||||||
|
|
||||||
|
import com.dfsek.tectonic.config.Configuration;
|
||||||
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.ConfigLoader;
|
||||||
import com.dfsek.tectonic.loading.TypeRegistry;
|
import com.dfsek.tectonic.loading.TypeRegistry;
|
||||||
import com.dfsek.terra.api.TerraPlugin;
|
import com.dfsek.terra.api.TerraPlugin;
|
||||||
import com.dfsek.terra.api.addons.TerraAddon;
|
import com.dfsek.terra.api.addons.TerraAddon;
|
||||||
@@ -71,6 +73,7 @@ import org.apache.commons.io.FileUtils;
|
|||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -307,8 +310,13 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
|||||||
|
|
||||||
private final Map<ConfigPack, Pair<PreLoadCompatibilityOptions, PostLoadCompatibilityOptions>> templates = new HashMap<>();
|
private final Map<ConfigPack, Pair<PreLoadCompatibilityOptions, PostLoadCompatibilityOptions>> templates = new HashMap<>();
|
||||||
|
|
||||||
|
private final Map<ConfigPack, Configuration> compatConfigs = new HashMap<>();
|
||||||
|
|
||||||
|
private final ConfigLoader compatLoader = new ConfigLoader();
|
||||||
|
|
||||||
private FabricAddon(TerraPlugin main) {
|
private FabricAddon(TerraPlugin main) {
|
||||||
this.main = main;
|
this.main = main;
|
||||||
|
main.register(compatLoader);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -340,9 +348,24 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
|||||||
injectTree(treeRegistry, "CRIMSON_FUNGUS", ConfiguredFeatures.CRIMSON_FUNGI);
|
injectTree(treeRegistry, "CRIMSON_FUNGUS", ConfiguredFeatures.CRIMSON_FUNGI);
|
||||||
injectTree(treeRegistry, "WARPED_FUNGUS", ConfiguredFeatures.WARPED_FUNGI);
|
injectTree(treeRegistry, "WARPED_FUNGUS", ConfiguredFeatures.WARPED_FUNGI);
|
||||||
|
|
||||||
PreLoadCompatibilityOptions template = new PreLoadCompatibilityOptions();
|
Configuration compat;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
event.loadTemplate(template);
|
compat = new Configuration(event.getLoader().get("compat.yml"));
|
||||||
|
main.logger().info("Loading compatibility options from compat.yml.");
|
||||||
|
} catch(FileNotFoundException e) {
|
||||||
|
compat = new Configuration(new HashMap<>()); // blank config
|
||||||
|
main.logger().info("No compat.yml found, not loading compatibility options.");
|
||||||
|
} catch(IOException e) {
|
||||||
|
throw new RuntimeException("Failed to load compatibility config", e); // Something went wrong.
|
||||||
|
}
|
||||||
|
|
||||||
|
compatConfigs.put(event.getPack(), compat);
|
||||||
|
|
||||||
|
PreLoadCompatibilityOptions template = new PreLoadCompatibilityOptions();
|
||||||
|
|
||||||
|
try {
|
||||||
|
compatLoader.load(template, compat);
|
||||||
} catch(ConfigException e) {
|
} catch(ConfigException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -359,6 +382,7 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
templates.put(event.getPack(), Pair.of(template, null));
|
templates.put(event.getPack(), Pair.of(template, null));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Priority(Priority.HIGHEST)
|
@Priority(Priority.HIGHEST)
|
||||||
@@ -367,7 +391,7 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
|||||||
PostLoadCompatibilityOptions template = new PostLoadCompatibilityOptions();
|
PostLoadCompatibilityOptions template = new PostLoadCompatibilityOptions();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
event.loadTemplate(template);
|
compatLoader.load(template, compatConfigs.get(event.getPack()));
|
||||||
} catch(ConfigException e) {
|
} catch(ConfigException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user