配置(Config)
基本信息
| 属性 | 值 |
|---|---|
| 配置框架 | 两套并存:gtnhlib @Config + Forge 旧式 Configuration |
| 主配置文件 | config/craftingtweaks-general.cfg |
| 插件配置文件 | config/craftingtweaks.cfg(addons 分类) |
| 配置类 | net.blay09.mods.craftingtweaks.config.CraftingTweaksConfig |
| 保存时机 | CraftingTweaksConfig 在 FMLInitializationEvent 后 ConfigurationManager.onInit();addons 在 postInit 末尾 addonConfig.save();开关每次切换即时保存 |
⚠️ 两个文件不是同一个东西:craftingtweaks-general.cfg 是 gtnhlib 生成的正式配置,
craftingtweaks.cfg 是 Forge 旧 Configuration 生成的插件开关表。
配置项全表
config/craftingtweaks-general.cfg
| 选项 | 类型 | 默认值 | @Config.Sync |
注释(源码原文) | 门控什么 |
|---|---|---|---|---|---|
hideButtons |
boolean |
false |
否 | This option is toggled by the ‘Toggle Buttons’ key that can be defined in the Controls settings. | 隐藏全部 tweak 按钮;由 绑定按键 切换并即时落盘 |
hideButtonTooltips |
boolean |
false |
否 | Set this to true if you don’t want the tweak buttons’ tooltips to show. | GuiScreenEvent.DrawScreenEvent.Post 中跳过 tooltip 绘制 |
compressAnywhere |
boolean |
false |
是 | Set this to true if you want the (de)compress feature to work outside of crafting GUIs (only works if installed on server). | 服务端 HandlerCompress 中「provider 为 null 也放行」 |
三个选项全部带 @Config.DefaultBoolean(false),即默认值恒为 false。
只有 compressAnywhere 标了 @Config.Sync,会同步到客户端。
compressAnywhere 的精确门控点在 HandlerCompress:
compressAnywhere == true→ 即使当前容器没有登记 provider 也照常处理compressAnywhere == false(默认)→provider == null时直接 return
配置注释里明写「only works if installed on server」,与源码一致:该判定
provider 是否为 null 的代码只存在于服务端 handler 里。
config/craftingtweaks.cfg — addons 分类
| 键名 | 类型 | 默认值 | 合法取值 |
|---|---|---|---|
minecraft |
String(枚举) |
enabled |
enabled / buttons_only / hotkeys_only / disabled |
| 其余每个已登记模组一个键 | String(枚举) |
enabled |
同上 |
分类注释(源码原文):Here you can control whether support for a mod should be enabled, buttons_only, hotkeys_only or disabled. For Vanilla Minecraft, see the option ‘minecraft’. Mods are identified by their mod ids.
枚举语义与门控关系详见 模组支持状态。
配置项与热键/按钮的对应关系
| 配置项 | 被谁读取 | 读取位置 | 影响 |
|---|---|---|---|
hideButtons |
ClientProxy.onClientTick |
toggleButtons 键处理 | 切换后 buttonList.removeIf(GuiTweakButton) 或重新 initGui |
hideButtons |
ClientProxy.onInitGui |
InitGuiEvent.Post |
为 true 时根本不调用 initGui |
hideButtonTooltips |
ClientProxy.onDrawScreen |
DrawScreenEvent.Post |
跳过 drawHoveringText |
compressAnywhere |
net.HandlerCompress |
服务端 | 放宽压缩/拆分的容器限制 |
注意 hideButtons 有两个读取点,属于双重判定(见
绑定按键 的「双重屏蔽关系」)。
旧配置迁移
CraftingTweaks.migrateGeneralSettingsIfNeeded 在 preInit 执行:
- 目标文件
config/craftingtweaks-general.cfg已存在 → 直接 return,什么都不做 - 不存在 → 从旧的
craftingtweaks.cfg的general分类读三个同名 boolean (hideButtons/hideButtonTooltips/compressAnywhere,读取默认均为false), 写入CraftingTweaksConfig后立刻ConfigurationManager.save
即这是一次性迁移,只在新配置文件缺失时跑一次。迁移完成后旧文件里的
general 分类不再被写入。