添加依赖 [
只需使用 CurseMaven,对应仓库在这里,https://www.cursemaven.com/
在 Files 中使用所需版本提供的代码片段添加依赖
示例(不是正确的模组)
implementation "curse.maven:cloth-config-348521:5987045"
]
与 Forge 配置相比的优缺点
使用 JSON 而不是 TOML,因此更可靠(例如,Forge Config 不太容易支持空列表,并且在使用它们时可能会出问题)
与 Forge 配置相比,兼容读取和写入更多 Java / Minecraft 类(例如,Vec3 无法写入或从 Forge 配置中读取,而 JasonConfig 因为使用 JSON 对象则没有这个问题)
在代码中编写更简单,同时仍然与创建 Forge 配置类的方式相似(见下方)
由于采用 JSON 格式,用户可读性略差
仍属实验性内容,虽然我目前还没发现 bug,但我相信以后总会有一些,毕竟我也只是一个人
示例配置(在将其添加到依赖后,也可以在该模组的 "api" 包中找到)
你在 "api" 包中需要的一切都有完善的文档,应当以其为准
public class ExampleConfigClass {
public static final Config EXAMPLE_CONFIG = new Config(MODID + "-example_config");
public static final ConfigComment DEVCOMMENT
= new ConfigComment("This file is only generated in a Dev environment", EXAMPLE_CONFIG);
///The following config values are called with the {EXAMPLE_CONFIG} Config passed in, this automatically adds it to the Config
public static final ConfigValue EXAMPLE_FLOAT
= new ConfigValue<>(10f, "exampleFloat", EXAMPLE_CONFIG, new TypeToken(){}.getType());
///Comments are placed in order of declaration, so this comment will be below {EXAMPLE_FLOAT} and above {EXAMPLE_LIST}
public static final ConfigComment EXAMPLE_COMMENT
= new ConfigComment("This is a list!", EXAMPLE_CONFIG);
public static final ConfigValue> EXAMPLE_LIST
= new ConfigValue<>(List.of("value1", "value2", "value3", "value4"), "exampleList", EXAMPLE_CONFIG, new TypeToken>(){}.getType());
public static final ConfigComment VEC3_COMMENT
= new ConfigComment("This is a Vec3! Many Java classes that don't work in Forge configs will work here!", EXAMPLE_CONFIG);
public static final ConfigValue> EXAMPLE_VEC3
= new ConfigValue<>(List.of(new Vec3(123,123,123), Vec3.ZERO), "exampleVec3", EXAMPLE_CONFIG, new TypeToken>(){}.getType());
public static final ConfigComment CLASS_COMMENT
= new ConfigComment("This is a newly created class, records are the best way to hold data like this", EXAMPLE_CONFIG);
public static final ConfigValue> EXAMPLE
= new ConfigValue<>(new LinkedHashMap<>(Map.of("information", new Info(1.0f, false, 8))), "example", EXAMPLE_CONFIG, new TypeToken>(){}.getType());
///This method must be called in your mod's Main class
///
/// You will need to call the {register()} method on the {Config} you declared
/// and add any {ConfigValue} variables you created if you did not assign them in the constructor
public static void init()/* This method can be called anything, init(), register(), etc*/ {
EXAMPLE_CONFIG.register();
///EXAMPLES OF GRABBING VALUES
//EXPLICIT (Very similar to Forge's Config)
}
public record Info(float f, boolean bool, int integer) { }
} 友情链接: 网易我的世界 | 泰拉瑞亚 | ocent云计算 | 米饭Minecraft插件文档 | 友链合作
历史访问人数:176,115 | 历史访问人次:277,193
今日访问人数:13,153 | 今日访问人次:15,086
昨日访问人数:23,567 | 昨日访问人次:27,193
Copyright © 2019-2026 我的世界服务器列表站. All rights reserved.
❤ Powered by GermMC 京ICP备17023959号-6