Search in sources :

Example 1 with PollinatedConfigBuilder

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();
}
Also used : PollinatedModConfig(gg.moonflower.pollen.api.config.PollinatedModConfig) EnumMap(java.util.EnumMap) ForgeConfigSpec(net.minecraftforge.common.ForgeConfigSpec) Set(java.util.Set) PollinatedConfigBuilder(gg.moonflower.pollen.api.config.PollinatedConfigBuilder) HashMap(java.util.HashMap) IEventBus(net.minecraftforge.eventbus.api.IEventBus) Function(java.util.function.Function) FMLJavaModLoadingContext(net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext) HashSet(java.util.HashSet) PollinatedConfigType(gg.moonflower.pollen.api.config.PollinatedConfigType) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) ModConfig(net.minecraftforge.fml.config.ModConfig) Optional(java.util.Optional) ModLoadingContext(net.minecraftforge.fml.ModLoadingContext) ConfigEvent(gg.moonflower.pollen.api.event.events.ConfigEvent) ApiStatus(org.jetbrains.annotations.ApiStatus) PollinatedConfigBuilder(gg.moonflower.pollen.api.config.PollinatedConfigBuilder) PollinatedModConfig(gg.moonflower.pollen.api.config.PollinatedModConfig) ModConfig(net.minecraftforge.fml.config.ModConfig) ForgeConfigSpec(net.minecraftforge.common.ForgeConfigSpec) FMLJavaModLoadingContext(net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext) ModLoadingContext(net.minecraftforge.fml.ModLoadingContext) EnumMap(java.util.EnumMap) IEventBus(net.minecraftforge.eventbus.api.IEventBus)

Aggregations

PollinatedConfigBuilder (gg.moonflower.pollen.api.config.PollinatedConfigBuilder)1 PollinatedConfigType (gg.moonflower.pollen.api.config.PollinatedConfigType)1 PollinatedModConfig (gg.moonflower.pollen.api.config.PollinatedModConfig)1 ConfigEvent (gg.moonflower.pollen.api.event.events.ConfigEvent)1 EnumMap (java.util.EnumMap)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Function (java.util.function.Function)1 ForgeConfigSpec (net.minecraftforge.common.ForgeConfigSpec)1 IEventBus (net.minecraftforge.eventbus.api.IEventBus)1 ModLoadingContext (net.minecraftforge.fml.ModLoadingContext)1 ModConfig (net.minecraftforge.fml.config.ModConfig)1 FMLJavaModLoadingContext (net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext)1 Pair (org.apache.commons.lang3.tuple.Pair)1 ApiStatus (org.jetbrains.annotations.ApiStatus)1