配置项
基本信息
| 属性 |
值 |
| 处理类 |
com.github.lunatrius.core.handler.ConfigurationHandler |
| 配置文件 |
由 preInit 传入的 event.getSuggestedConfigurationFile() 决定,FML 依 modid 生成,即 config/LunatriusCore.cfg |
| 初始化时机 |
LunatriusCore.preInit → ConfigurationHandler.init(File) |
| 分类数 |
2(versioncheck / tweaks) |
| 可见选项数 |
3(另有 1 个 setShowInGui(false) 的隐藏项) |
[!IMPORTANT]
本 mod 确实会写出配置文件。 loadConfiguration() 末尾有 if (configuration.hasChanged()) { configuration.save(); },首次启动时 Forge 会把所有默认值写入文件。addUpdate(String, String) 也会在追加已知版本后保存。
全部配置属性
| 分类 |
属性名 |
类型 |
默认值 |
需要重开 MC |
GUI 中可见 |
说明(源码原文) |
versioncheck |
checkForUpdates |
boolean |
true |
是 |
是 |
Should the mod check for updates? |
versioncheck |
silenceKnownUpdates |
boolean |
false |
是 |
是 |
Should the mod remind you only for new updates (once per version)? |
versioncheck |
knownVersions |
String[] |
new String[0](空数组) |
否 |
否 |
A list of known updates. Deleting versions from the list will remind you about them again. |
tweaks |
replaceInGameConfig |
boolean |
true |
否 |
是 |
Replace the FML test config GUI with a working GUI. |
默认值常量
| 常量 |
值 |
CHECK_FOR_UPDATES_DEFAULT |
true |
SILENCE_KNOWN_UPDATES_DEFAULT |
false |
REPLACE_IN_GAME_CONFIG_DEFAULT |
true |
[!NOTE]
knownVersions 是唯一没有对应 *_DEFAULT 常量的属性(默认值直接内联为 new String[0]),也是唯一不带语言键、不要求重开游戏、且不出现在配置 GUI 里的属性。
公开静态字段
| 字段 |
类型 |
初值 |
configuration |
net.minecraftforge.common.config.Configuration |
未初始化(由 init 赋值) |
checkForUpdates |
boolean |
CHECK_FOR_UPDATES_DEFAULT |
silenceKnownUpdates |
boolean |
SILENCE_KNOWN_UPDATES_DEFAULT |
replaceInGameConfig |
boolean |
REPLACE_IN_GAME_CONFIG_DEFAULT |
私有 Property 字段
propCheckForUpdates、propSilenceKnownUpdates、propKnownUpdates、propReplaceInGameConfig —— 全部 private static Property,初值 null。
公共方法
| 签名 |
行为 |
public static void init(File configFile) |
仅当 configuration == null 时 new Configuration(configFile) 并调用 loadConfiguration();重复调用是空操作 |
public static void addUpdate(String modid, String version) |
把 "<modid> <version>" 追加进 knownVersions 列表(去重后 Collections.sort 排序),写回属性并保存 |
public static boolean canNotifyOfUpdate(String modid, String version) |
返回 !knownVersions.contains("<modid> <version>") || !silenceKnownUpdates |
事件处理
| 签名 |
事件 |
条件 |
@SubscribeEvent public void onConfigurationChangedEvent(ConfigChangedEvent.OnConfigChangedEvent event) |
cpw.mods.fml.client.event.ConfigChangedEvent.OnConfigChangedEvent |
event.modID.equalsIgnoreCase(Reference.MODID) 时调用 loadConfiguration() |
[!WARNING]
addUpdate 与 canNotifyOfUpdate 都直接解引用 propKnownUpdates,而该字段只在 loadConfiguration() 执行后才是非 null。在本 mod 自身不注册监听器的前提下,二者只能由外部 mod 在 preInit 之后调用,否则会 NullPointerException。
实际生效情况
| 配置项 |
是否真的生效 |
checkForUpdates |
否 — VersionChecker 的全部方法已被掏空为空实现,见版本检测 |
silenceKnownUpdates |
否 — 只被 canNotifyOfUpdate 读取,而该方法无内部调用方 |
knownVersions |
否 — 只被上面两个同属死代码的方法读写 |
replaceInGameConfig |
是 — 被 GuiHandler.onGuiOpen 读取,唯一真正影响游戏行为的选项 |
[!IMPORTANT]
4 个配置项中只有 replaceInGameConfig 真正起作用。整个 versioncheck 分类是 GTNH 分支移除联网版本检测后留下的残留。
本地化键
| 完整键 |
en_US |
zh_CN |
lunatriuscore.config.category.versioncheck |
Version Check |
版本检测 |
lunatriuscore.config.category.tweaks |
Tweaks |
Tweaks(未汉化) |
lunatriuscore.config.checkForUpdates |
Check for Updates |
检测版本更新 |
lunatriuscore.config.checkForUpdates.tooltip |
Should the mod check for updates? |
是否让该Mod检测版本更新? |
lunatriuscore.config.silenceKnownUpdates |
Silence Known Updates |
静默更新已知的新版本 |
lunatriuscore.config.silenceKnownUpdates.tooltip |
Should the mod remind you only for new updates (once per version)? |
是否让该Mod只提醒你新版本的更新(每个版本只提醒一次)? |
lunatriuscore.config.replaceInGameConfig |
Replace Config GUI |
替换Config GUI |
lunatriuscore.config.replaceInGameConfig.tooltip |
Replace the FML test config GUI with a working GUI. |
将FML测试config GUI替换为working GUI. |
[!NOTE]
属性键与 .tooltip 后缀的映射由 Forge 的 ConfigElement 自动完成:setLanguageKey() 只设了属性键本身,tooltip 键是 Forge 约定的 <属性键>.tooltip。
相关条目
- 常量与配置键名 -
Names.Config 全部常量与 LANG_PREFIX
- Mod 入口与生命周期 - 调用
ConfigurationHandler.init 的位置
- 配置界面 - 这些选项在 GUI 中的呈现方式
- 版本检测 -
versioncheck 分类对应功能的现状
- Proxy 体系 - 注册
ConfigurationHandler 到 FML 总线的位置