-
Notifications
You must be signed in to change notification settings - Fork 0
E | Advanced: Custom Effects in FXItems
Sartaj Singh edited this page May 31, 2025
·
2 revisions
- 1. Overview
- 2. Understanding FXItemBehavior and FXFoodBehavior
- 3. Supported Effect Hooks and Event Triggers
- 4. Using EffectUtils and Utility APIs
- 5. Creating Complex Abilities: Examples
- 6. Integration with Bukkit/Spigot Events
- 7. Persistent Data, NBT, and Advanced State
- 8. Troubleshooting & Gotchas
- 9. See Also
Beyond simple item/food stats, FXItems supports powerful custom effects and active abilities for both items and foods.
This is achieved with behavior interfaces (FXItemBehavior, FXFoodBehavior), utility APIs, and integration with Minecraft’s event system.
- FXItemBehavior: Attach custom logic to any item (e.g., right/left click, on attack, on passive, on drop, etc.)
- FXFoodBehavior: Attach custom logic to foods (e.g., onEat, onConsume, etc.)
You can implement as many or as few hooks as you want; unimplemented methods are simply ignored.
These are the most common, but always check your FXItems version for new/extended hooks!
public interface FXItemBehavior {
default void onRightClick(Player player, ItemStack item, Block block, Action action) {}
default void onLeftClick(Player player, ItemStack item, Block block, Action action) {}
default void onAttack(EntityDamageByEntityEvent event, Player player, ItemStack item) {}
default void onPassive(Player player, ItemStack item) {}
default void onHeld(Player player, ItemStack item) {}
default void onDrop(Player player, ItemStack item) {}
default void onInventoryTick(Player player, ItemStack item) {}
// ...extend as the API grows!
}Common use cases:
- onRightClick: Fire projectiles, cast spells, activate abilities.
- onAttack: Modify outgoing damage, apply custom effects, trigger crits.
- onPassive/onHeld/onInventoryTick: Grant buffs while held or in inventory.
- onDrop: Prevent or customize item dropping behavior.
public interface FXFoodBehavior {
default void onEat(Player player, ItemStack food, FXFoodDefinition def) {}
// Additional: onConsume, onHeld, etc. if your version supports
}- onEat: Apply potion effects, heal, teleport, run commands, summon mobs, etc.
FXItems comes with a suite of utility classes to make advanced effects easy.
-
EffectUtils: Apply potion effects, particles, sounds, and more.
EffectUtils.applyPotionEffect(Player, PotionEffectType, duration, level, showParticles)EffectUtils.spawnParticles(World, Particle, Location, count, ...)EffectUtils.playSound(Player, Sound, volume, pitch)
-
CooldownUtils: Manage per-player cooldowns for abilities.
CooldownUtils.isOnCooldown(Player, "key")CooldownUtils.setCooldown(Player, "key", ticks)
-
ManaUtils: Get, set, and modify custom mana for players.
ManaUtils.getMana(Player)ManaUtils.setMana(Player, value)ManaUtils.addMana(Player, value)
-
ProjectileUtils: Spawn custom projectiles with callbacks.
ProjectileUtils.spawnProjectile(EntityType, Location, Vector, Consumer<Projectile>)
- TeleportUtils, OneTimeCraftUtils, etc.: See utility wiki pages for full API.
@Override
public void onRightClick(Player player, ItemStack item, Block block, Action action) {
if (CooldownUtils.isOnCooldown(player, "beamsword")) {
player.sendMessage("§cStill recharging!");
return;
}
// Do ability...
CooldownUtils.setCooldown(player, "beamsword", 40); // 2 seconds (20 ticks = 1 sec)
}@Override
public void onRightClick(Player player, ItemStack item, Block block, Action action) {
ManaUtils mana = new ManaUtilsAPI();
if (mana.getMana(player) < 50) {
player.sendMessage("§bNot enough mana!");
return;
}
mana.addMana(player, -50);
// Ability effect...
}@Override
public void onRightClick(Player player, ItemStack item, Block block, Action action) {
Location loc = player.getEyeLocation();
Vector direction = loc.getDirection().multiply(2.0);
ProjectileUtils.spawnProjectile(EntityType.SNOWBALL, loc, direction, projectile -> {
projectile.setCustomName("Beam");
// Add trail, on-hit effect, etc.
});
}@Override
public void onAttack(EntityDamageByEntityEvent event, Player player, ItemStack item) {
event.setDamage(event.getDamage() * 2);
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 60, 1));
player.getWorld().spawnParticle(Particle.CRIT, player.getLocation(), 20);
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_ATTACK_CRIT, 1, 1);
}- You can combine FXItems hooks with any Bukkit event for ultra-complex logic.
- Register your own listeners using the Registry API:
registry.registerEvent(this, MyCustomListener.class);
- Many advanced items use a mix of FXItemBehavior and event listeners.
- For persistent state (e.g., item-bound cooldowns, custom tags), use Bukkit's
PersistentDataContainer. - You may read/write custom NBT on
ItemStackin your FXItemBehavior methods:ItemMeta meta = item.getItemMeta(); NamespacedKey key = new NamespacedKey("yourplugin", "yourtag"); meta.getPersistentDataContainer().set(key, PersistentDataType.INTEGER, 1337); item.setItemMeta(meta);
- This enables per-item or per-player custom data.
-
Unregistered behaviors:
- If your item/food isn't triggering effects, check registration and class annotations.
-
Server performance:
- Avoid intensive logic in
onPassive/onInventoryTick—these run frequently!
- Avoid intensive logic in
-
Effect stacking:
- Be careful with infinite duration potion effects; use short bursts and reapply if needed.
-
Compatibility:
- Some hooks may require specific server versions (e.g., certain events in newer MC).
- H | Utility: CooldownUtils
- J | Utility: EffectUtils
- K | Utility: ManaUtils
- N | Utility: ProjectileUtils
- C | Creating Custom Items
- D | Creating Custom Foods
- 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