-
Notifications
You must be signed in to change notification settings - Fork 0
D | Creating Custom Foods
Sartaj Singh edited this page May 31, 2025
·
2 revisions
- 1. Overview
- 2. FXFoodDefinition: All Options & Parameters
- 3. FXFoodBehavior: Custom Food Logic
- 4. Registering Your Food
- 5. Advanced Features
- 6. Real-World Examples
- 7. Troubleshooting & FAQ
- 8. See Also
FXItems lets you create custom edible items (foods) with unique hunger/saturation, advanced effects, custom models, and more.
Foods are defined using FXFoodDefinition and custom logic is added with FXFoodBehavior.
public FXFoodDefinition(
String id,
String displayName,
Material material,
int hunger,
float saturation,
boolean alwaysEdible,
Integer customModelData,
List<String> lore
)| Parameter | Type | Required | Description |
|---|---|---|---|
| id | String | Yes | Unique identifier for the food. Lowercase, no spaces recommended. |
| displayName | String | Yes | Name shown in-game. Supports § color codes. |
| material | Material | Yes | Minecraft material (Material.APPLE, etc.). |
| hunger | int | Yes | How many hunger bars restored (vanilla: 1 = half a drumstick). |
| saturation | float | Yes | Saturation modifier for the food. |
| alwaysEdible | boolean | No | If true, can be eaten even at full hunger. |
| customModelData | Integer (nullable) | No | For resource-pack custom models. Null for none. |
| lore | List | No | Tooltip text. Color codes supported. |
- You can omit
customModelDataandlorefor simple foods. -
alwaysEdibledefaults tofalseif not set.
Custom logic for foods (effects, abilities, events, etc.) is implemented in your own class that implements FXFoodBehavior.
public interface FXFoodBehavior {
default void onEat(Player player, ItemStack food, FXFoodDefinition def) {}
// Add more hooks as FXItems evolves!
}public class EnchantedAppleBehavior implements FXFoodBehavior {
@Override
public void onEat(Player player, ItemStack food, FXFoodDefinition def) {
player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 200, 1));
player.sendMessage("§dYou feel magically restored!");
}
}- Only
onEatis required for basic effects. - Extend with your own methods for more advanced effects (e.g., onConsume, onHeld, etc.).
Registry registry = new RegistryAPI();
registry.registerFood(
"enchanted_apple",
new FXFoodDefinition(
"enchanted_apple",
"§dEnchanted Apple",
Material.APPLE,
8, // hunger (4 drumsticks)
12.8f, // saturation
true, // alwaysEdible
3, // customModelData
Arrays.asList("§7A magical apple.", "§bRestores health and grants buffs!")
),
new EnchantedAppleBehavior()
);- Register in your plugin's
onEnable()or a setup method. - You can manually create as many foods as you want, each with its own logic and appearance.
For large projects, auto-registration is recommended.
-
Annotate your behavior class:
@AutoRegister public class EnchantedAppleBehavior implements FXFoodBehavior { ... }
-
In your plugin's main class:
BehaviorAutoRegistrar.registerAll(this, "your.base.package");
- All annotated behaviors in the package are discovered and registered.
-
Custom Models: Use
customModelDatafor resource pack integration. -
Advanced Effects: Use
onEatto apply any potion effect, run commands, or trigger custom events. - Lore: Add detailed lore for flavor and player guidance.
- Always Edible: Useful for foods that should act like golden apples.
- Synergy with Items: Foods can trigger item-based effects or interact with FXItems items (e.g., grant items on eat).
FXFoodDefinition berryPie = new FXFoodDefinition(
"berry_pie",
"§dBerry Pie",
Material.PUMPKIN_PIE,
6, // hunger
9.6f, // saturation
false, // alwaysEdible
null, // customModelData
Arrays.asList("§7A delicious berry pie.")
);
registry.registerFood("berry_pie", berryPie, new FXFoodBehavior() {
@Override
public void onEat(Player player, ItemStack food, FXFoodDefinition def) {
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 120, 0));
player.sendMessage("§aYou feel energized!");
}
});FXFoodDefinition manaFruit = new FXFoodDefinition(
"mana_fruit",
"§9Mana Fruit",
Material.APPLE,
3,
6f,
true,
7, // customModelData
Arrays.asList("§7A fruit brimming with arcane energy.")
);
registry.registerFood("mana_fruit", manaFruit, new FXFoodBehavior() {
@Override
public void onEat(Player player, ItemStack food, FXFoodDefinition def) {
// Use ManaUtils to recharge player's mana (see utility page)
Utils utils = new UtilsAPI();
utils.addMana(player, 50);
player.sendMessage("§9Your mana is replenished!");
}
});-
"My food isn't working":
- Double-check your ID and registration code.
- Make sure your behavior class is correct and implements
FXFoodBehavior.
-
"No effect on eat":
- Confirm your
onEatis implemented and registered. - Check for errors in the server log.
- Confirm your
-
"Custom model not showing":
- Make sure your resource pack is loaded and matches the
customModelDatavalue.
- Make sure your resource pack is loaded and matches the
-
"Can I make a food give items or trigger commands?"
- Yes! In
onEat, you can use Bukkit/Spigot API to do anything: give items, run commands, etc.
- Yes! In
- B | The Registry System: Items, Foods, Commands, Events
- C | Creating Custom Items
- E | Advanced: Custom Effects in FXItems
- K | ManaUtils
- S | Auto-Registration System
- Home
- A | Getting Started & Plugin Overview
- B | The Registry System: Items, Foods, Commands, Events
- C | Creating Custom Items
- D | Creating Custom Foods
- E | Advanced: Custom Effects in FXItems
- F | Creating Custom Commands
- G | Creating Custom Events & Behaviors
- H | Utility: CooldownUtils
- I | Utility: CustomItemUtils
- J | Utility: EffectUtils
- K | Utility: ManaUtils
- L | Utility: OneTimeCraftUtils
- M | Utility: TeleportUtils
- N | Utility: ProjectileUtils
- O | Utility: GammaUtils
- P | Utility: EntitySizeUtils
- Q | FXItems API (com.noctify.API) & Making Addons
- R | Advanced Techniques, Gotchas & FAQ
- S | Auto-Registration System
- T | Migration Guide (v1.1 → v1.2+)
- U | Changelog