配置文件
MCLib 只写两个 Forge Configuration 文件,都用 Launch.minecraftHome/config/ 下的固定路径。AssetDirector 完全不写配置,只读系统属性。
基本信息
| 属性 | 值 |
|---|---|
| 类型 | Forge net.minecraftforge.common.config.Configuration |
| 所属模块 | SloppyDepLoader、UpdateCheck |
| 配置文件总数 | 2 |
| 写入方式 | config.load() → 读全部项 → if (config.hasChanged()) config.save() |
两个配置类都是 public static 字段 + loadIfNotAlready() / reload() 的固定模式,没有配置界面(无 GuiConfig),只能手改文件。
config/sloppydeploader.cfg
由 ConfigSDL 负责,路径为 new File(Launch.minecraftHome, "config/sloppydeploader.cfg")(文件名是硬编码字面量,与 SloppyDepLoader.NS 同名但不是从常量拼的)。
| 键 | 分类 | 类型 | 默认值 | 配置内注释 |
|---|---|---|---|---|
enable |
_general |
boolean | true |
Set this to false to disable this module |
showRestartNotification |
interface |
boolean | true |
Show notification when new dependencies have been downloaded and a restart is needed. |
对应静态字段:public static boolean enabled、public static boolean showRestartNotification。
| 加载时机 | 行为 |
|---|---|
SloppyDepLoader.preInit() |
直接调 ConfigSDL.reload()(不是 loadIfNotAlready),每次 pre-init 都重读 |
DepLoadInst.onGui |
弹重启动提示前再 ConfigSDL.reload() 一次,让玩家改完配置立即生效 |
enable 为假时 preInit 静默跳过整个下载流程(ConfigSDL.enabled 判断在 for 循环外),SloppyDepLoaderAPI.modDeps 里的声明仍会保留。
config/UpdateCheckLib.cfg
由 ConfigUCL 负责,路径为 new File(Launch.minecraftHome, "config/" + UpdateCheckLib.MODID + ".cfg"),即文件名来自常量 MODID = "UpdateCheckLib"。
| 键 | 分类 | 类型 | 默认值 | 范围 | 配置内注释 |
|---|---|---|---|---|---|
enable |
_general |
boolean | true |
— | Set this to false to disable this mod |
hideErrored |
_general |
boolean | false |
— | If true, results that errored won't be shown |
promoChannel |
_general |
String | "latest" |
— | The update channel which should be checked. Forge defines 'latest' for the bleeding-edge versions and 'recommended' for the stable versions of mods. |
showUpdatesButton |
interface |
boolean | true |
— | Show updates button in main menu when there are updates available |
updatesButtonX |
interface |
int | 104 |
Integer.MIN_VALUE ~ Integer.MAX_VALUE |
空字符串 |
updatesButtonY |
interface |
int | 96 |
Integer.MIN_VALUE ~ Integer.MAX_VALUE |
空字符串 |
updatesButtonAbsolutePos |
interface |
boolean | false |
— | true: the X and Y are absolute coordinates / false: the X and Y is relative to WIDTH/2 and HEIGHT/4 respectively (which is how the buttons are placed in the vanilla menu GUI) |
对应静态字段:public static boolean enabled、public static boolean hideErrored、public static String promoChannel、public static boolean showUpdatesButton、public static int updatesButtonX、public static int updatesButtonY、public static boolean updatesButtonAbsolutePos。
按钮坐标的计算
buttonX = updatesButtonX + (updatesButtonAbsolutePos ? 0 : event.gui.width / 2)
buttonY = updatesButtonY + (updatesButtonAbsolutePos ? 0 : event.gui.height / 4)
默认 104, 96 是相对坐标,即实际位置为 width/2 + 104、height/4 + 96,与原版主菜单按钮同一套基准。设 updatesButtonAbsolutePos 为真则直接当屏幕绝对坐标用(width/2 + 104 在小分辨率下会越界,所以提供了绝对模式)。
加载时机
| 调用点 | 用哪个方法 |
|---|---|
UpdateCheckLib.isEnabled() |
ConfigUCL.loadIfNotAlready() —— UpdateCheckAPI 的每个公共方法都先过这里 |
UpdateCheckLib.onGui(进入主菜单时) |
ConfigUCL.reload() —— 每次开主菜单都重读 |
UpdateCheckTask.getErrorLevel() |
直接读静态字段 hideErrored,不触发加载 |
hideErrored 有双重作用:既是"是否在结果页显示失败项"(经由 Result.isInteresting()),也决定失败日志的级别(ERROR 或 DEBUG)。
没有配置文件的模块
| 模块 | 替代机制 |
|---|---|
| AssetDirector | 系统属性 assetDirector.*、minecraft.sharedDataDir;资源需求由宿主 mod 在代码里用 ADConfig 声明 |
| MCLib 核心 / 共享状态 | 无配置,行为由宿主 mod 的 MCLib.init(boolean subscribe) 参数决定 |
| ItemConfigHelper | 只提供解析工具,黑名单由宿主 mod 自己的配置提供 |
相关条目
- SloppyDepLoader -
sloppydeploader.cfg的使用者 - UpdateCheck -
UpdateCheckLib.cfg的使用者 - GUI 注入 - 按钮坐标的实际应用位置