Configuration Version
基本信息
net.glease.tc4tweak.ConfigurationVersion —— 枚举,每个常量是一次配置迁移步,
按顺序执行把旧配置升级到当前格式。
迁移驱动
public static void migrateToLatest(Configuration c) {
for (int i = identify(c).ordinal() + 1; i < VALUES.length; i++) {
TC4Tweak.log.info("Migrating config to {}", VALUES[i].getVersionMarker());
VALUES[i].step(c);
}
}
从配置里识别出的版本 ordinal() + 1 开始,依次执行后续所有步。
每步打一条 Migrating config to <VERSION>。
版本阶梯
| 版本 | step 做的事 |
|---|---|
LEGACY(versionMarker = null) |
throw new IllegalStateException() —— 见下 |
| 下一版 | 把 general 下的一批属性移到 client(c.moveProperty("general", name, "client")) |
| 再下一版 | 把 client 下的一批属性移到 client.browser_scale,再重命名(c.renameProperty) |
| 再下一版 | infusionOreDictMode:general → general.infusion_recipes,随后重命名为 oreDictMode |
⚠️ LEGACY 的陷阱
LEGACY(null) 的 step 直接抛 IllegalStateException。
由于 VALUES = values(),LEGACY 是 ordinal() == 0,
而循环从 identify(c).ordinal() + 1 开始 —— 只要 identify 不会返回
LEGACY 就不会触发。若用户配置缺失版本标记而被识别为 LEGACY,
迁移第一步就会抛异常导致启动失败。
这是「枚举 + 索引」式版本管理的固有脆弱点。
相关条目
源码
src/main/java/net/glease/tc4tweak/ConfigurationVersion.java