Nutrient JSON 配置格式

基本信息

属性 值
资源路径 assets/nutrition/configs/nutrients/*.json
内置文件 dairy.json / fruit.json / grain.json / protein.json / vegetable.json + example.json 模板(disabled)
加载方式 DataImporter.loadJsonNutrients 通过 ClassLoader 读硬编码列表
解析类 ca.wescook.nutrition.utility.DataParser

JSON Schema

{
  "name": "example",            // 唯一 ID(小写,推荐)
  "icon": "minecraft:carrot",   // ItemStack 表示形式,用于 GUI 栏图标
  "color": "72dd5a",            // 6 位十六进制(不带 #)营养条颜色
  "decay": 2.5,                 // 覆盖全局 decay multiplier(-100 到 100),可省略
  "visible": true,              // 是否在 GUI/tooltip 中显示,可省略(默认 true)
  "enabled": false,             // 是否加载此 Nutrient,可省略
  "food": {
    "oredict": [                // OreDict 条目列表
      "listAllveggie",
      "listAllgreenveggie"
    ],
    "items": [                  // 显式 ItemStack 列表,格式 modid:name 或 modid:name:meta
      "minecraft:carrot",
      "minecraft:apple:1",
      "minecraft:cake"
    ]
  }
}

字段约束

字段 必需 类型 说明
name ✓ string Nutrient 唯一 ID(localization key 为 nutrient.nutrition:<name>)
icon ✓ string ItemStack,格式 modid:name[:meta]
color ✓ string 6 位十六进制(不带 #),实际解析时拼上 ff 前缀成为 ARGB
decay ✗ float -100…100;缺省时使用 NutritionConfig.decay.decayMultiplier
visible ✗ bool 缺省 true
enabled ✗ bool 缺省 null(视为加载);显式 false 跳过
food.oredict ✗ array<string> 该 Nutrient 包含的 OreDict 条目
food.items ✗ array<string> 显式物品列表;mod 不存在则警告并跳过,非食物则警告

解析错误处理

  • 缺 name/icon/color → 抛 NullPointerException(致命)
  • 颜色非 hex → Integer.parseUnsignedInt("ff" + color, 16) 抛 NumberFormatException(致命)
  • decay 超出 -100…100 → 设为 0 并 Log.error(不致命)
  • items 中 modid:name 格式错误(少于 1 个冒号)→ Log.fatal(致命)
  • items 中 modid:item 的物品 ID 未注册 → 仅当 Loader.isModLoaded(modid) 且 NutritionConfig.debug.logMissingFood 才警告
  • items 中物品不是食物(AppleCoreAPI.accessor.isFood 为 false)→ 警告 "X is not a valid food" 并跳过

默认 5 大食物组

文件 name icon color 范围说明
dairy.json dairy minecraft:milk_bucket a0d4f7 乳制品(OreDict foodButter / foodCheese / listAllmilk 等)
fruit.json fruit minecraft:apple cd73f4 水果(含 HarvestCraft crop* 系列、Forestry fruitForestry)
grain.json grain minecraft:wheat f4d92e 谷物
protein.json protein minecraft:cooked_beef db6c23 蛋白(肉类 + HarvestCraft crop* 坚果等)
vegetable.json vegetable minecraft:carrot 72dd5a 蔬菜(HarvestCraft cropChilli/...、listAllveggie)
example.json example minecraft:carrot 72dd5a 模板示例(enabled: false,不会被加载)

重新加载

  • 服务启动时 PostInit 自动调用 DataImporter.reload()
  • OP 在游戏内执行 /nutrition reload → 重新解析 + 把在线玩家按 name 迁移数据到新 Nutrient 对象

相关条目