Search in sources :

Example 1 with ForgeConfigSpec

use of net.minecraftforge.common.ForgeConfigSpec in project Champions by TheIllusiveC4.

the class Champions method config.

private void config(final ModConfigEvent evt) {
    if (evt.getConfig().getModId().equals(MODID)) {
        if (evt.getConfig().getType() == Type.SERVER) {
            ChampionsConfig.bake();
            ForgeConfigSpec spec = evt.getConfig().getSpec();
            CommentedConfig commentedConfig = evt.getConfig().getConfigData();
            if (spec == ChampionsConfig.RANKS_SPEC) {
                ChampionsConfig.transformRanks(commentedConfig);
                RankManager.buildRanks();
            } else if (spec == ChampionsConfig.AFFIXES_SPEC) {
                ChampionsConfig.transformAffixes(commentedConfig);
                AffixManager.buildAffixSettings();
            } else if (spec == ChampionsConfig.ENTITIES_SPEC) {
                ChampionsConfig.transformEntities(commentedConfig);
                EntityManager.buildEntitySettings();
            }
        } else if (evt.getConfig().getType() == Type.CLIENT) {
            ClientChampionsConfig.bake();
        }
    }
}
Also used : ForgeConfigSpec(net.minecraftforge.common.ForgeConfigSpec) CommentedConfig(com.electronwill.nightconfig.core.CommentedConfig)

Example 2 with ForgeConfigSpec

use of net.minecraftforge.common.ForgeConfigSpec in project Vampirism by TeamLapen.

the class VampirismConfig method finalizeAndRegisterConfig.

public static void finalizeAndRegisterConfig() {
    /*
        Build balance configuration
         */
    final Pair<BalanceConfig, ForgeConfigSpec> specPair = new ForgeConfigSpec.Builder().configure((builder) -> {
        builder.comment("A ton of options which allow you to balance the mod to your desire");
        builder.push("balance");
        balanceBuilder.build(BALANCE, builder);
        builder.pop();
        return BALANCE;
    });
    ForgeConfigSpec balanceSpec = specPair.getRight();
    if (VampirismMod.inDev) {
        balanceBuilder.checkFields(BALANCE);
    }
    balanceBuilder = null;
    ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, commonSpec);
    ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, clientSpec);
    ModLoadingContext.get().registerConfig(ModConfig.Type.SERVER, serverSpec);
    ModLoadingContext.get().registerConfig(ModConfig.Type.SERVER, balanceSpec, "vampirism-balance.toml");
    FMLJavaModLoadingContext.get().getModEventBus().register(VampirismConfig.class);
}
Also used : ForgeConfigSpec(net.minecraftforge.common.ForgeConfigSpec)

Example 3 with ForgeConfigSpec

use of net.minecraftforge.common.ForgeConfigSpec in project MinecraftForge by MinecraftForge.

the class ForgeConfigSpecTest method executeSpeedTest.

private <T> void executeSpeedTest(final String configKey, final T defaultKeyValue, final String testName) throws IOException {
    final ForgeConfigSpec.Builder builder = new ForgeConfigSpec.Builder();
    final ForgeConfigSpec.ConfigValue<T> simpleValue = builder.define(configKey, defaultKeyValue);
    final ForgeConfigSpec spec = builder.build();
    final String configPath = String.format(Locale.ROOT, TEST_CONFIG_PATH_TEMPLATE, testName);
    final File configFile = new File(configPath);
    configFile.getParentFile().mkdirs();
    configFile.createNewFile();
    final CommentedFileConfig configData = CommentedFileConfig.builder(configPath).sync().preserveInsertionOrder().onFileNotFound((newfile, configFormat) -> {
        Files.createFile(newfile);
        return true;
    }).writingMode(WritingMode.REPLACE).build();
    spec.setConfig(configData);
    final List<TestResult> results = runTestHarness(defaultKeyValue, testName, simpleValue, spec, 3, 20);
    final double averageEnabled = results.stream().mapToLong(value -> value.enabledWatch.elapsed(TimeUnit.NANOSECONDS)).average().getAsDouble();
    final double averageDisabled = results.stream().mapToLong(value -> value.disabledWatch.elapsed(TimeUnit.NANOSECONDS)).average().getAsDouble();
    final double maxEnabledDeviation = results.stream().mapToLong(value -> value.enabledWatch.elapsed(TimeUnit.NANOSECONDS)).mapToDouble(e -> e - averageEnabled).map(Math::abs).max().getAsDouble();
    final double maxDisabledDeviation = results.stream().mapToLong(value -> value.disabledWatch.elapsed(TimeUnit.NANOSECONDS)).mapToDouble(e -> e - averageDisabled).map(Math::abs).max().getAsDouble();
    System.out.printf("Computed test results for: %s:%n", testName);
    System.out.printf("  > Enabled:  ~%10.2f ns.   +- %10.2f ns.%n", averageEnabled, maxEnabledDeviation);
    System.out.printf("  > Disabled: ~%10.2f ns.   +- %10.2f ns.%n", averageDisabled, maxDisabledDeviation);
    configFile.delete();
}
Also used : Files(java.nio.file.Files) Stopwatch(com.google.common.base.Stopwatch) WritingMode(com.electronwill.nightconfig.core.io.WritingMode) ForgeConfigSpec(net.minecraftforge.common.ForgeConfigSpec) Test(org.junit.Test) IOException(java.io.IOException) CommentedFileConfig(com.electronwill.nightconfig.core.file.CommentedFileConfig) Field(java.lang.reflect.Field) File(java.io.File) ArrayList(java.util.ArrayList) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Lists(com.google.common.collect.Lists) Locale(java.util.Locale) Assert(org.junit.Assert) ForgeConfigSpec(net.minecraftforge.common.ForgeConfigSpec) CommentedFileConfig(com.electronwill.nightconfig.core.file.CommentedFileConfig) File(java.io.File)

Example 4 with ForgeConfigSpec

use of net.minecraftforge.common.ForgeConfigSpec in project Overloaded by CJ-MC-Mods.

the class OverloadedConfig method getConfig.

public ForgeConfigSpec getConfig(ModConfig.Type type) {
    ForgeConfigSpec.Builder builder = new ForgeConfigSpec.Builder();
    configsSections.forEach(c -> c.appendToBuilder(type, builder));
    ForgeConfigSpec spec = builder.build();
    configSpecs.put(type, spec);
    return spec;
}
Also used : ForgeConfigSpec(net.minecraftforge.common.ForgeConfigSpec)

Example 5 with ForgeConfigSpec

use of net.minecraftforge.common.ForgeConfigSpec 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

ForgeConfigSpec (net.minecraftforge.common.ForgeConfigSpec)10 AbstractConfig (com.electronwill.nightconfig.core.AbstractConfig)1 CommentedConfig (com.electronwill.nightconfig.core.CommentedConfig)1 UnmodifiableConfig (com.electronwill.nightconfig.core.UnmodifiableConfig)1 CommentedFileConfig (com.electronwill.nightconfig.core.file.CommentedFileConfig)1 WritingMode (com.electronwill.nightconfig.core.io.WritingMode)1 Stopwatch (com.google.common.base.Stopwatch)1 Lists (com.google.common.collect.Lists)1 LabeledEntry (com.simibubi.create.foundation.config.ui.ConfigScreenList.LabeledEntry)1 BooleanEntry (com.simibubi.create.foundation.config.ui.entries.BooleanEntry)1 EnumEntry (com.simibubi.create.foundation.config.ui.entries.EnumEntry)1 NumberEntry (com.simibubi.create.foundation.config.ui.entries.NumberEntry)1 SubMenuEntry (com.simibubi.create.foundation.config.ui.entries.SubMenuEntry)1 ValueEntry (com.simibubi.create.foundation.config.ui.entries.ValueEntry)1 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 File (java.io.File)1 IOException (java.io.IOException)1