配置文件

[!INFO] 文件 config/neirecipepanels.cfg | 源码 src/main/java/com/neirecipepanels/Config.java | 读取于 CommonProxy.preInit

配置文件名由 FML 的 event.getSuggestedConfigurationFile() 决定,取的是 modid neirecipepanels,所以落在 config/neirecipepanels.cfg。

基本信息

属性 值
文件名 config/neirecipepanels.cfg
分类 recipe、server 两个
加载时机 CommonProxy.preInit → Config.synchronizeConfiguration
副作用 有变化时自动 configuration.save()

选项总表

键 类型 默认值 取值范围 说明
recipe.registerBlueprintRecipe 布尔 true — 注册 Recipe Blueprint 的内置合成配方。关掉可自行用脚本定义
server.panelMode 字符串(枚举) EVERYONE DISABLED / CREATIVE_ONLY / OP_ONLY / EVERYONE 哪些玩家可以刻印配方面板
server.consumeInCreative 布尔 false — 创造模式玩家刻印时也扣蓝图
server.maxIngredients 整数 64 1 – 256 配方材料/副产物格数超过此值则拒绝刻印
server.maxSnapshotBytes 整数 16384 512 – 262144 配方数据 gzip 后超过此字节数则拒绝刻印

源码默认值出处

  • Config.registerBlueprintRecipe 字段初值 true;configuration.getBoolean("registerBlueprintRecipe", "recipe", true, ...) 的默认实参也是 true
  • Config.panelMode 字段初值 PanelMode.EVERYONE;getString("panelMode", "server", PanelMode.EVERYONE.name(), ...)
  • Config.consumeInCreative 字段初值 false;getBoolean("consumeInCreative", "server", false, ...)
  • Config.maxIngredients 字段初值 64;getInt("maxIngredients", "server", 64, 1, 256, ...)
  • Config.maxSnapshotBytes 字段初值 16384;getInt("maxSnapshotBytes", "server", 16384, 512, 262144, ...)

Forge 的 getInt 在读出越界值时会把范围两端作为钳制依据,因此 1–256 与 512–262144 是实际生效区间。

panelMode 四个取值

PanelMode 是一个四值枚举,parseMode 对输入做 trim() 再 toUpperCase(Locale.ROOT),所以配置里大小写不敏感、前后空格也容错;解析失败(IllegalArgumentException)一律回落到 EVERYONE。

取值 谁能刻印 权限判定 被拒时的反馈
EVERYONE 任何玩家 无 —
CREATIVE_ONLY 仅创造模式 player.capabilities.isCreativeMode neirecipepanels.chat.notAllowed
OP_ONLY 仅 OP server.getConfigurationManager().func_152596_g(player.getGameProfile())(SRG 名,对应 isOp) neirecipepanels.chat.notAllowed
DISABLED 无人 提前返回 静默,不发任何聊天消息

DISABLED 与其他两个的区别在于:它在 grant 最开头就 return,被拒绝的玩家看不到提示,只有按钮本身仍显示为可用(可用性判断只看客户端有没有蓝图,与服务端配置无关)。

CREATIVE_ONLY 与 OP_ONLY 的检查是顺序且不互斥的:EVERYONE 跳过全部检查;CREATIVE_ONLY 只查创造模式;OP_ONLY 只查 OP 身份(不要求创造模式)。

服务端上限的作用

maxIngredients 与 maxSnapshotBytes 只在服务端扣蓝图之前生效,作为对客户端提交数据的边界检查:

  • maxIngredients → RecipeSnapshot.sanitize(raw, Config.maxIngredients, Config.maxSnapshotBytes) 的 maxSlots,约束 inPerms 与 otherPerms 两个整数数组的长度
  • maxSnapshotBytes → 同一个 sanitize 的 maxBytes,比较 NBT gzip 后的字节数

任一超限即拒绝,回一条 neirecipepanels.chat.badSnapshot = That recipe could not be imprinted.

相关条目