📖 简介
Food API 是一个面向开发者的库,它移除了 Minecraft 原版饥饿系统的硬编码限制。它将饥饿容量和消耗速度暴露为标准的实体属性,支持多行食物条渲染,并提供了一个基于提供者的简洁系统来替换食物图标——同时可选兼容流行的 HUD 模组。
✨ 特性
▶ 动态饥饿容量 — 最大饥饿值现在是一个属性,支持最多 2 行(40 点)。
▶ 可配置的消耗速度 — 通过乘数属性控制饥饿值的消耗速度。
▶ 多行食物条 — 第二行无缝渲染在第一行上方,并与原版抖动动画完全同步。
▶ 图标提供者系统 — 通过简单的注册 API,可按玩家、按行、按槽位替换任何食物图标(空、半满、满、饥饿效果、叠加层、饱和度)。
▶ 可选模组兼容 — 当存在 Overflowing Bars 和 AppleSkin 时,提供原生支持。
🖼️ 截图
原版渲染 — 单行,标准图标
搭配 Overflowing Bars — 行数计数器,叠加图标堆叠在顶部
📦 新增属性
加载 Food API 时会自动注册两个新的玩家属性:
| 属性 |
ID |
默认值 |
范围 |
描述 |
| Max Hunger |
food_api:max_hunger |
20 |
1 – 40 |
最大饥饿容量。20 = 一行,40 = 两行。 |
| Hunger Rate |
food_api:hunger_rate |
1.0 |
0.0 – 10.0 |
饥饿消耗速度乘数。0 = 不消耗,2 = 两倍速。 |
这两个属性都会同步到客户端,可以通过命令、其他模组或直接通过代码进行修改:
// 示例:给予玩家双倍饥饿容量
player.getAttribute(AttributeRegistries.MAX_HUNGER)
.setBaseValue(40);
// 示例:将饥饿消耗速度减半
player.getAttribute(AttributeRegistries.HUNGER_RATE)
.setBaseValue(0.5);
🔧 API 用法
替换食物图标
使用 ID 和优先级注册一个提供者。优先级高的优先生效。返回 null 则回退到下一个提供者。
FoodIconRegistry.register(
ResourceLocation.fromNamespaceAndPath("mymod", "my_provider"),
10, // 优先级 — 越高越先检查(原版 = 0)
(player, iconIndex, row, type) -> {
// iconIndex: 0 = 最右侧图标, 9 = 最左侧图标
// row: 0 = 底行, 1 = 顶行
return switch (type) {
case FULL -> ResourceLocation.fromNamespaceAndPath("mymod", "hud/my_food_full");
case HALF -> ResourceLocation.fromNamespaceAndPath("mymod", "hud/my_food_half");
case EMPTY -> ResourceLocation.fromNamespaceAndPath("mymod", "hud/my_food_empty");
default -> null; // 让其他提供者或原版处理剩余部分
};
}
);
图标类型
| 类型 |
描述 |
EMPTY |
背景(空槽位) |
HALF |
半满图标 |
FULL |
满图标 |
EMPTY_HUNGER |
饥饿效果期间的背景 |
HALF_HUNGER |
饥饿效果期间的半满图标 |
FULL_HUNGER |
饥饿效果期间的满图标 |
HALF_OVERLAY |
顶部的半满图标 (仅限 Overflowing Bars) |
FULL_OVERLAY |
顶部的满图标 (仅限 Overflowing Bars) |
SATURATION |
饱和度叠加纹理 (仅限 AppleSkin) |
正确的注册时机
请在 FMLClientSetupEvent 或更早阶段调用 FoodIconRegistry.register(...):
@SubscribeEvent
public static void onClientSetup(FMLClientSetupEvent event) {
FoodIconRegistry.register(...);
}
🔗 可选依赖
Food API 可以独立工作。以下模组在存在时会解锁额外功能:
📖 About
Food API is a developer-focused library that removes the hardcoded limitations of Minecraft's vanilla hunger system. It exposes hunger capacity and drain speed as proper entity attributes, adds multi-row food bar rendering, and provides a clean provider-based system for replacing food icons — all with optional compatibility for popular HUD mods.
✨ Features
▶ Dynamic hunger capacity — max hunger is now an attribute, supports up to 2 rows (40 units).
▶ Configurable drain speed — control how fast hunger depletes via a multiplier attribute.
▶ Multi-row food bar — second row renders seamlessly above the first, fully synced with vanilla shake animation.
▶ Icon provider system — replace any food icon (empty, half, full, hunger, overlay, saturation) per-player, per-row, per-slot with a simple registration API.
▶ Optional mod compat — native support for Overflowing Bars and AppleSkin when present.
🖼️ Screenshots
Vanilla rendering — single row, standard icons
With Overflowing Bars — row counter, overlay icons stacked on top
📦 New Attributes
Two new player attributes are registered automatically when Food API is loaded:
| Attribute |
ID |
Default |
Range |
Description |
| Max Hunger |
food_api:max_hunger |
20 |
1 – 40 |
Maximum hunger capacity. 20 = one row, 40 = two rows. |
| Hunger Rate |
food_api:hunger_rate |
1.0 |
0.0 – 10.0 |
Hunger drain speed multiplier. 0 = no drain, 2 = twice as fast. |
Both attributes are synced to the client and can be modified via commands, other mods, or directly in code:
// Example: give a player double hunger capacity
player.getAttribute(AttributeRegistries.MAX_HUNGER)
.setBaseValue(40);
// Example: slow hunger drain to half speed
player.getAttribute(AttributeRegistries.HUNGER_RATE)
.setBaseValue(0.5);
🔧 API Usage
Replacing food icons
Register a provider with an ID and priority. Higher priority wins. Return null to fall through to the next provider.
FoodIconRegistry.register(
ResourceLocation.fromNamespaceAndPath("mymod", "my_provider"),
10, // priority — higher = checked first (vanilla = 0)
(player, iconIndex, row, type) -> {
// iconIndex: 0 = rightmost icon, 9 = leftmost
// row: 0 = bottom row, 1 = top row
return switch (type) {
case FULL -> ResourceLocation.fromNamespaceAndPath("mymod", "hud/my_food_full");
case HALF -> ResourceLocation.fromNamespaceAndPath("mymod", "hud/my_food_half");
case EMPTY -> ResourceLocation.fromNamespaceAndPath("mymod", "hud/my_food_empty");
default -> null; // let other providers or vanilla handle the rest
};
}
);
Icon types
| Type |
Description |
EMPTY |
Background (empty slot) |
HALF |
Half-filled icon |
FULL |
Fully filled icon |
EMPTY_HUNGER |
Background during Hunger effect |
HALF_HUNGER |
Half icon during Hunger effect |
FULL_HUNGER |
Full icon during Hunger effect |
HALF_OVERLAY |
Half icon on top row (Overflowing Bars only) |
FULL_OVERLAY |
Full icon on top row (Overflowing Bars only) |
SATURATION |
Saturation overlay texture (AppleSkin only) |
Registering at the right time
Call FoodIconRegistry.register(...) during FMLClientSetupEvent or earlier:
@SubscribeEvent
public static void onClientSetup(FMLClientSetupEvent event) {
FoodIconRegistry.register(...);
}
🔗 Optional Dependencies
Food API works standalone. These mods unlock extra features when present:
- Overflowing Bars — enables row counter display and overlay icon rendering on the top row
- AppleSkin — enables saturation overlay icon replacement via
FoodIconType.SATURATION
评论 0
登录后参与评分
还没有评论,来抢沙发吧