use of gg.moonflower.pollen.api.config.PollinatedConfigBuilder in project pollen by MoonflowerTeam.
the class ConfigManagerImpl method register.
public static <T> T register(String modId, PollinatedConfigType type, String fileName, Function<PollinatedConfigBuilder, T> consumer) {
ModLoadingContext context = ModLoadingContext.get();
IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
Pair<T, ForgeConfigSpec> pair = new PollinatedConfigBuilderImpl(new ForgeConfigSpec.Builder()).configure(consumer);
ModConfig config = new ModConfig(convert(type), pair.getRight(), context.getActiveContainer(), fileName);
context.getActiveContainer().addConfig(config);
if (registeredEvents.add(modId)) {
bus.<ModConfig.Loading>addListener(event -> {
ModConfig modConfig = event.getConfig();
get(modConfig.getModId(), convert(modConfig.getType())).ifPresent(c -> {
ConfigEvent.LOADING.invoker().configChanged(c);
});
});
bus.<ModConfig.Reloading>addListener(event -> {
ModConfig modConfig = event.getConfig();
get(modConfig.getModId(), convert(modConfig.getType())).ifPresent(c -> {
ConfigEvent.RELOADING.invoker().configChanged(c);
});
});
}
CONFIGS.computeIfAbsent(modId, __ -> new EnumMap<>(PollinatedConfigType.class)).put(type, new PollinatedModConfigImpl(config));
return pair.getLeft();
}
Aggregations