下面列出了怎么用net.minecraftforge.common.ForgeConfigSpec的API类实例代码及写法,或者点击链接到github查看源代码。
public ModConfig(final Type type, final ForgeConfigSpec spec, final ModContainer container, final String fileName) {
this.type = type;
this.spec = spec;
this.fileName = fileName;
this.container = container;
this.configHandler = ConfigFileTypeHandler.TOML;
ConfigTracker.INSTANCE.trackConfig(this);
}
public static void loadConfig(ForgeConfigSpec spec, Path path) {
final CommentedFileConfig configData = CommentedFileConfig.builder(path)
.sync()
.autosave()
.writingMode(WritingMode.REPLACE)
.build();
configData.load();
spec.setConfig(configData);
}
public static void register(ModLoadingContext context, ModConfig.Type type, ForgeConfigSpec spec, String suffix){
String fileName = BetterSprintingMod.id + "-" + suffix + ".toml";
context.registerConfig(type, spec, fileName);
if (Files.notExists(Paths.get("config", fileName))){
migrationFile = Paths.get("config", "bettersprinting.cfg").toAbsolutePath();
isNew = true; // since keybinds are not migrated and first time setup only modifies keybinds, this is fine
}
}
public void registerConfig(ModConfig.Type type, ForgeConfigSpec spec) {
getActiveContainer().addConfig(new ModConfig(type, spec, getActiveContainer()));
}
public void registerConfig(ModConfig.Type type, ForgeConfigSpec spec, String fileName) {
getActiveContainer().addConfig(new ModConfig(type, spec, getActiveContainer(), fileName));
}
public ModConfig(final Type type, final ForgeConfigSpec spec, final ModContainer activeContainer) {
this(type, spec, activeContainer, defaultConfigName(type, activeContainer.getModId()));
}
public ForgeConfigSpec getSpec() {
return spec;
}
ServerConfig(ForgeConfigSpec.Builder builder)
{
builder.comment("Settings for stick crafting").push("sticks");
removeSticksFromPlanks = builder.define("RemoveSticksFromPlanksRecipes", true);
builder.pop();
builder.comment("Settings for rock and ore rock drops").push("rocks");
enableRocks = builder.define("Enable", true);
replaceStoneDrops = builder.define("ReplaceStoneDrops", true);
replaceIronOreDrops = builder.define("ReplaceIronOreDrops", true);
replaceGoldOreDrops = builder.define("ReplaceGoldOreDrops", true);
replaceModOreDrops = builder.define("ReplaceModOreDrops", true);
replacePoorOreDrops = builder.define("ReplacePoorOreDrops", true);
cobbleRequiresClay = builder.define("CobbleRequiresClay", true);
builder.pop();
builder.comment("Settings for the Scraping feature and enchant").push("scraping");
enableScraping = builder.define("Enable", false);
scrapingIsTreasure = builder.define("IsTreasureEnchantment", false);
enableToolScraping = builder.define("EnableToolScraping", true);
enableArmorScraping = builder.define("EnableArmorScraping", true);
builder.pop();
builder.comment("Settings for the drying rack block").push("drying_rack");
enableMeatRotting = builder.define("EnableMeatRotting", true);
enableRottenDrying = builder.define("EnableRottenDrying", true);
enableJerky = builder.define("EnableJerky", true);
enableMeatDrying = builder.define("EnableMeatDrying", true);
enableLeatherTanning = builder.define("EnableLeatherTanning", true);
enableSaddleCrafting = builder.define("EnableSaddleCrafting", true);
builder.pop();
builder.comment("Settings for the torch setting fire to entities").push("torch_fire");
enableTorchFire = builder.define("Enable", true);
builder.pop();
builder.comment("Settings for the dough/bread replacements").push("bread");
enableBread = builder.define("Enable", true);
removeVanillaBread = builder.define("RemoveVanillaBread", true);
builder.pop();
builder.comment("Settings for the chopping block").push("chopping");
disablePlanksRecipes = builder.define("DisablePlanksRecipes", true);
choppingDegradeChance = builder
.comment("The average number of uses before degrading to the next phase will be 1/DegradeChance. Default is 16.67 average uses.")
.defineInRange("DegradeChance", 0.06, 0, Double.MAX_VALUE);
choppingExhaustion = builder.defineInRange("Exhaustion", 0.0025, 0, Double.MAX_VALUE);
choppingWithEmptyHand = builder.defineInRange("EmptyHandFactor", 0.4, 0, Double.MAX_VALUE);
builder.pop();
builder.comment("Settings for the fibre collection").push("fibres");
dropStringFromSheep = builder.define("DropStringFromSheep", true);
enableStringCrafting = builder.define("EnableStringCrafting", true);
builder.pop();
builder.comment("Settings for slime merging").push("slimes");
mergeSlimes = builder
.comment("If enabled, slimes will have new AI rules to feel attracted to other slimes, and if 4 slimes of the same size are nearby they will merge into a slime of higher size.")
.define("Merge", true);
builder.pop();
axeLevels = builder
.comment("If enabled, slimes will have new AI rules to feel attracted to other slimes, and if 4 slimes of the same size are nearby they will merge into a slime of higher size.")
.define(Arrays.asList("axe_levels"), () -> Config.of(InMemoryFormat.defaultInstance()), x -> true, Config.class);
/*
configuration.addCustomCategoryComment("AxeMultipliers",
"Allows customizing the multiplier for each axe level. By default this is 'baseOutput * (1+axeLevel)'.\n" +
"To customize an axeLevel, add a line like 'D:AxeLevel1=2.0' or 'D:AxeLevel5=3.0' without the quotes.\n" +
"Levels that are not defined will continue using their default value."
);
axeMultipliers = configuration.getCategory("AxeMultipliers");
*/
}
public static boolean getConfigBoolean(String categoryName, String keyName)
{
ForgeConfigSpec.BooleanValue value = SERVER_SPEC.getValues().get(Arrays.asList(categoryName, keyName));
return value.get();
}