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();
}
}
}
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);
}
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();
}
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;
}
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();
}
Aggregations