Search in sources :

Example 1 with PollinatedConfigType

use of gg.moonflower.pollen.api.config.PollinatedConfigType in project pollen by MoonflowerTeam.

the class ConfigCommand method register.

public static void register(CommandDispatcher<CommandSourceStack> dispatcher, boolean dedicated) {
    // Disable showing serverconfig on a dedicated server because the files won't exist
    dispatcher.register(Commands.literal("config").then(Commands.literal("showfile").then(Commands.argument("mod", StringArgumentType.word()).suggests(PollenSuggestionProviders.MOD_IDS).then(Commands.argument("type", dedicated ? EnumArgument.enumValues(PollinatedConfigType.COMMON, PollinatedConfigType.CLIENT) : EnumArgument.enumValues(PollinatedConfigType.values())).executes(ctx -> {
        String modId = StringArgumentType.getString(ctx, "mod");
        PollinatedConfigType type = EnumArgument.getEnum(PollinatedConfigType.class, ctx, "type");
        String configFileName = getConfigFileName(modId, type);
        if (configFileName != null) {
            File f = new File(configFileName);
            ctx.getSource().sendSuccess(new TranslatableComponent("commands." + Pollen.MOD_ID + ".config.success", modId, type, new TextComponent(f.getName()).withStyle(ChatFormatting.UNDERLINE).withStyle((style) -> style.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_FILE, f.getAbsolutePath())))), false);
            return Command.SINGLE_SUCCESS;
        } else {
            ctx.getSource().sendFailure(new TranslatableComponent("commands." + Pollen.MOD_ID + ".config.fail", modId, type));
            return 0;
        }
    })))));
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) ClickEvent(net.minecraft.network.chat.ClickEvent) PollinatedConfigType(gg.moonflower.pollen.api.config.PollinatedConfigType) File(java.io.File)

Example 2 with PollinatedConfigType

use of gg.moonflower.pollen.api.config.PollinatedConfigType 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

PollinatedConfigType (gg.moonflower.pollen.api.config.PollinatedConfigType)2 PollinatedConfigBuilder (gg.moonflower.pollen.api.config.PollinatedConfigBuilder)1 PollinatedModConfig (gg.moonflower.pollen.api.config.PollinatedModConfig)1 ConfigEvent (gg.moonflower.pollen.api.event.events.ConfigEvent)1 File (java.io.File)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 ClickEvent (net.minecraft.network.chat.ClickEvent)1 TextComponent (net.minecraft.network.chat.TextComponent)1 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)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