-
Notifications
You must be signed in to change notification settings - Fork 0
D | Creating Custom Foods
Sartaj Singh edited this page May 28, 2025
·
2 revisions
FXItems supports custom food items with unique effects, hunger, saturation, and recipes.
Recommended location: com.noctify.Custom.Foods
public class MagicApple {
// Required: item definition
public static ItemStack createItem() {
ItemStack apple = new ItemStack(Material.APPLE);
ItemMeta meta = apple.getItemMeta();
meta.setDisplayName("§bMagic Apple");
meta.setLore(List.of("§7Restores health and grants power!"));
apple.setItemMeta(meta);
return apple;
}
// Required: food values
public static int getHungerPoints() { return 6; }
public static float getSaturationPoints() { return 9.6f; }
// Required: potion effects
public static List<PotionEffect> getEffects() {
return List.of(
new PotionEffect(PotionEffectType.REGENERATION, 200, 1),
new PotionEffect(PotionEffectType.ABSORPTION, 400, 1)
);
}
// Optional: Custom shaped recipe
public static ShapedRecipe getRecipe(Plugin plugin, NamespacedKey key) {
ShapedRecipe recipe = new ShapedRecipe(key, createItem());
recipe.shape("GGG", "GAG", "GGG");
recipe.setIngredient('G', Material.GOLD_INGOT);
recipe.setIngredient('A', Material.APPLE);
return recipe;
}
}In FoodRegistry:
registerFood(plugin, "MagicApple", MagicApple.class, null);The fourth parameter is for a custom behavior class (see below).
If you want special logic (for example, play a sound or trigger lightning when eaten), write a Listener:
public class MagicAppleBehavior implements Listener {
public MagicAppleBehavior(Plugin plugin) {}
@EventHandler
public void onEat(PlayerItemConsumeEvent event) {
if (!CustomItemUtils.isCustomItem(event.getItem(), Material.APPLE, "§bMagic Apple")) return;
Player player = event.getPlayer();
player.getWorld().strikeLightningEffect(player.getLocation());
}
}Register using:
registerFood(plugin, "MagicApple", MagicApple.class, MagicAppleBehavior.class);- Register your food. Reload server.
- Craft using the recipe or give with
/fxgive <player> MagicApple. - Eat and confirm hunger/saturation/effects and custom behavior.
You can add any number of potion effects, play sounds, spawn particles, etc., in your behavior class.
- Food class with
createItem(),getHungerPoints(),getSaturationPoints(),getEffects() - Optional:
getRecipe() - Register in
FoodRegistry - Optional: Custom eating behavior in
OtherBehaviorspackage
- 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