Nutrition
[!INFO] Git Commit:
9c1f759| Updated: 2026-08-01
Nutrition Unofficial (modid nutrition) 是 WesCook 原版 Nutrition mod 的 GTNH 1.7.10 移植版(Serenibyss & GTNH Team 维护)。它本身不添加方块、物品、实体或维度,而是一套"按食物组追踪营养值 → 触发原版/Minecraft 自定义药水效果"的纯逻辑 mod,依赖 AppleCoreAPI(食物系统)与 GTNHLib(配置系统 + Brigadier 命令)。
mod 通过 NutritionManager(INutritionManager 接口的实现,HashBasedTable<EntityPlayer, Nutrient, Float> 存储结构)为每个玩家维护多个营养值(Nutrient) 通道,每个 Nutrient 范围 0-100。Nutrient 由 assets/nutrition/configs/nutrients/*.json 资源 JSON 定义(默认 5 个:dairy/fruit/grain/protein/vegetable,外加 example 模板),可以包含:
icon— 营养栏图标(ItemStack)color— 营养条十六进制颜色decay— 衰减倍率(默认 1.0,可被 per-nutrient 覆盖,范围 -100…100)visible— 是否在 GUI/tooltip 中显示food.oredict/food.items— 该营养包含的食物(OreDict + ItemStack 列表)
玩家吃食物时(EventEatFood),Nutrition 通过 AppleCore 的 FoodEaten 事件读取食物 hunger 值,按 getNutrientValue() 公式计算每个 Nutrient 应增加的营养值。EventWorldTick 每个服务端 tick 跟踪玩家饥饿条下降,按 0.075 * difference * nutrient.decay 的速率衰减对应 Nutrient 的值,并通过 potionTicking() 每 ~5 秒(110 ticks)一次根据 Nutrient 当前值触发/刷新 EffectsList 中注册的效果。
EffectsList 提供 6 个内置效果映射——三个是 mod 自定义 Potion(Nourished / Malnourished / Toughness),三个用原版 Potion(Strength / Weakness / Resistance / Haste / Mining Fatigue),每个效果通过 EnumDetectionType(ANY / AVERAGE / ALL / CUMULATIVE)决定如何根据 Nutrient 数值判定是否触发。
死亡时(EventPlayerDeath)会按配置应用死亡惩罚;加入世界(EventPlayerJoinWorld)时通过 SPacketNutrients 同步给客户端;GUI 通过玩家背包按钮(EventNutritionButton)或自定义热键(EventNutritionKey)打开 /nutrition 命令基于 Brigadier 注册。
Witchery 吸血鬼兼容通过 WitcheryEventHandler 把 BloodPower 直接线性映射到所有 Nutrient 值。
源码结构
Nutrition/NutritionConfig—@Mod主类 + GTNHLib Config(Nutrition/Decay/DeathPenalty/Gui/Debug/Witchery 6 大节)api.NutritionManager— 核心 API(HashBasedTable<EntityPlayer, Nutrient, Float>存储)nutrients.*—NutrientPOJO +NutrientList静态注册表 +JsonNutrient资源映射 +NutrientUtils计算pots.*—ModPotions注册 3 个 mod 自定义 Potion +PotionCustom提供自定义图标渲染effects.*—Effectbuilder +EnumDetectionType4 类 +EffectsList6 默认效果 +EffectsManager阈值判定events.*—EventEatFood(吃食) /EventWorldTick(衰减+效果定时) /EventPlayerDeath/EventPlayerJoinWorld/EventAllowOvereating/EventNutritionButton/EventNutritionKey/EventTooltip/WitcheryEventHandlercommand.NutritionCommand— Brigadier 注册的/nutrition根命令gui.*—NutritionGui营养栏 GUI +GuiScreenDynamic自适应边框 +GuiButtonNutrition自定义贴图按钮network.*—SPacketNutrientsS2C 同步包 +ModPacketHandler通道注册data.PlayerDataHandler— NBT 持久化(Nutrients标签)utility.*—DataImporter(读 JSON + 重载时迁移玩家数据) /DataParser(JSON → Nutrient) /Log
设定
- 配置文件 - GTNHLib Config,6 大节(Nutrition/Decay/DeathPenalty/Gui/Debug/Witchery),含完整默认值与范围约束
- /nutrition 命令 - Brigadier 注册的根命令,提供
help/get/set/add/subtract/reset/reload7 个子命令 - 营养衰减机制 -
EventWorldTick每 tick 跟踪饥饿条下降,按0.075 × diff × decay衰减每个 Nutrient - 死亡惩罚 -
EventPlayerDeath.onPlayerClone处理死亡数据迁移 + 配置驱动的 nutrient 下限惩罚 - Witchery 吸血鬼兼容 -
WitcheryEventHandler把 BloodPower 线性映射到全部 Nutrient - 玩家数据持久化 -
PlayerDataHandler通过 NBTNutrients标签读写玩家营养值 - 食物营养计算公式 -
NutrientUtils.calculateNutrition+getNutrientValue(半饥饿值 × 配置倍率 × 多 Nutrient 衰减) - Nutrient JSON 配置格式 -
assets/nutrition/configs/nutrients/*.jsonschema(name/icon/color/decay/visible/enabled/food) - 数据包同步 -
SPacketNutrientsS2C 同步包(按 Nutrient name 序列化 → 客户端按 name 反查)
Buff/Debuff
- Nourished - 自定义增益 Potion:每 amplifier 等级 +1 HP(半颗心),
maxHealthAttributeModifier - Malnourished - 自定义减益 Potion:每 amplifier 等级 -1 HP(半颗心),
maxHealthAttributeModifier - Toughness - 自定义增益 Potion:每 amplifier 等级 +4 HP + 2 knockbackResistance
热键
- Nutrition GUI 热键 -
Keyboard.KEY_NONE默认未绑定,按下打开/关闭NutritionGui
物品效果
- 效果阈值检测类型 -
EnumDetectionType:ANY / AVERAGE / ALL / CUMULATIVE 4 种触发算法对比 - Mining Fatigue 效果 - 原版 Potion.digSlowdown,AVERAGE 检测,nutrient 0-20 触发
- Weakness 效果 - 原版 Potion.weakness,AVERAGE 检测,nutrient 0-10 触发
- Strength 效果 - 原版 Potion.damageBoost,AVERAGE 检测,nutrient 70-100 触发
- Resistance 效果 - 原版 Potion.resistance,AVERAGE 检测,nutrient 80-100 触发
- Haste 效果 - 原版 Potion.digSpeed,AVERAGE 检测,nutrient 90-100 触发
- 允许过度进食 -
EventAllowOvereating把所有ItemFood设为alwaysEdible=true,并把 cake-likeIEdibleBlock设为edibleAtMaxHunger=true - 营养工具提示 -
EventTooltip在物品 tooltip 末尾追加营养组与百分比,DARK_GREEN/DARK_AQUA 色