mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-03 08:25:31 +00:00
make loadConfig less jank
This commit is contained in:
parent
4203121d40
commit
fa647e1e2c
@ -1,31 +1,30 @@
|
|||||||
package com.dfsek.terra.api.event.events.config;
|
package com.dfsek.terra.api.event.events.config;
|
||||||
|
|
||||||
import com.dfsek.tectonic.config.ConfigTemplate;
|
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||||
|
import com.dfsek.tectonic.exception.ConfigException;
|
||||||
import com.dfsek.terra.config.pack.ConfigPack;
|
import com.dfsek.terra.config.pack.ConfigPack;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called before a config pack's registries are filled. At this point, the pack manifest has been loaded, and all registries are empty.
|
* Called before a config pack's registries are filled. At this point, the pack manifest has been loaded, and all registries are empty.
|
||||||
*/
|
*/
|
||||||
public class ConfigPackPreLoadEvent extends ConfigPackLoadEvent {
|
public class ConfigPackPreLoadEvent extends ConfigPackLoadEvent {
|
||||||
public ConfigPackPreLoadEvent(ConfigPack pack) {
|
private final ExceptionalConsumer<ConfigTemplate> configLoader;
|
||||||
|
|
||||||
|
public ConfigPackPreLoadEvent(ConfigPack pack, ExceptionalConsumer<ConfigTemplate> configLoader) {
|
||||||
super(pack);
|
super(pack);
|
||||||
|
this.configLoader = configLoader;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final List<ConfigTemplate> templates = new ArrayList<>();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add an additional config template to load using the pack manifest.
|
* Load a custom {@link ConfigTemplate} using the pack manifest.
|
||||||
*
|
*
|
||||||
* @param template Template to register.
|
* @param template Template to register.
|
||||||
*/
|
*/
|
||||||
public void addTemplate(ConfigTemplate template) {
|
public void loadTemplate(ConfigTemplate template) throws ConfigException {
|
||||||
templates.add(template);
|
configLoader.accept(template);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ConfigTemplate> getTemplates() {
|
public interface ExceptionalConsumer<T extends ConfigTemplate> {
|
||||||
return new ArrayList<>(templates);
|
void accept(T value) throws ConfigException;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ 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.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;
|
||||||
import com.dfsek.tectonic.exception.LoadException;
|
import com.dfsek.tectonic.exception.LoadException;
|
||||||
@ -137,11 +136,7 @@ public class ConfigPack implements LoaderRegistrar {
|
|||||||
|
|
||||||
main.logger().info("Loading config pack \"" + template.getID() + "\"");
|
main.logger().info("Loading config pack \"" + template.getID() + "\"");
|
||||||
|
|
||||||
ConfigPackPreLoadEvent event = new ConfigPackPreLoadEvent(this);
|
main.getEventManager().callEvent(new ConfigPackPreLoadEvent(this, template -> selfLoader.load(template, configuration)));
|
||||||
main.getEventManager().callEvent(event);
|
|
||||||
for(ConfigTemplate eventTemplate : event.getTemplates()) {
|
|
||||||
selfLoader.load(eventTemplate, configuration);
|
|
||||||
}
|
|
||||||
|
|
||||||
load(l, main);
|
load(l, main);
|
||||||
|
|
||||||
@ -188,12 +183,7 @@ public class ConfigPack implements LoaderRegistrar {
|
|||||||
selfLoader.load(template, configuration);
|
selfLoader.load(template, configuration);
|
||||||
main.logger().info("Loading config pack \"" + template.getID() + "\"");
|
main.logger().info("Loading config pack \"" + template.getID() + "\"");
|
||||||
|
|
||||||
ConfigPackPreLoadEvent event = new ConfigPackPreLoadEvent(this);
|
main.getEventManager().callEvent(new ConfigPackPreLoadEvent(this, template -> selfLoader.load(template, configuration)));
|
||||||
main.getEventManager().callEvent(event);
|
|
||||||
for(ConfigTemplate eventTemplate : event.getTemplates()) {
|
|
||||||
selfLoader.load(eventTemplate, configuration);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
load(l, main);
|
load(l, main);
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.dfsek.terra.fabric;
|
package com.dfsek.terra.fabric;
|
||||||
|
|
||||||
|
import com.dfsek.tectonic.exception.ConfigException;
|
||||||
import com.dfsek.tectonic.exception.LoadException;
|
import com.dfsek.tectonic.exception.LoadException;
|
||||||
import com.dfsek.tectonic.loading.TypeRegistry;
|
import com.dfsek.tectonic.loading.TypeRegistry;
|
||||||
import com.dfsek.terra.api.TerraPlugin;
|
import com.dfsek.terra.api.TerraPlugin;
|
||||||
@ -329,7 +330,7 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
|||||||
};
|
};
|
||||||
//noinspection ConstantConditions
|
//noinspection ConstantConditions
|
||||||
((GeneratorTypeAccessor) generatorType).setTranslationKey(new LiteralText("Terra:" + pack.getTemplate().getID()));
|
((GeneratorTypeAccessor) generatorType).setTranslationKey(new LiteralText("Terra:" + pack.getTemplate().getID()));
|
||||||
GeneratorTypeAccessor.getValues().add(generatorType);
|
GeneratorTypeAccessor.getValues().add(1, generatorType);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -475,7 +476,11 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
|||||||
injectTree(treeRegistry, "WARPED_FUNGUS", ConfiguredFeatures.WARPED_FUNGI);
|
injectTree(treeRegistry, "WARPED_FUNGUS", ConfiguredFeatures.WARPED_FUNGI);
|
||||||
|
|
||||||
PackFeatureOptionsTemplate template = new PackFeatureOptionsTemplate();
|
PackFeatureOptionsTemplate template = new PackFeatureOptionsTemplate();
|
||||||
event.addTemplate(template);
|
try {
|
||||||
|
event.loadTemplate(template);
|
||||||
|
} catch(ConfigException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
templates.put(event.getPack(), template);
|
templates.put(event.getPack(), template);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user