Class EnchantmentEvents

java.lang.Object
net.fabricmc.fabric.api.item.v1.EnchantmentEvents

public final class EnchantmentEvents extends Object
Events relating to enchantments, allowing for finer control of what enchantments can apply to different items.
  • Field Details

    • ALLOW_ENCHANTING

      public static final Event<EnchantmentEvents.AllowEnchanting> ALLOW_ENCHANTING
      An event that allows overriding whether an Enchantment can be applied to an ItemStack.

      This should only be used to modify the behavior of external items with regards to external enchantments, where 'external' means either vanilla or from another mod. For instance, a mod might allow enchanting a pickaxe with Sharpness (and only Sharpness) under certain specific conditions.

      To modify the behavior of your own modded enchantments, specify a custom tag for Enchantment.EnchantmentDefinition.supportedItems() instead. To modify the behavior of your own modded items, add to the applicable tags instead, when that suffices. Note that this event triggers before FabricItem.canBeEnchantedWith(ItemStack, Holder, EnchantingContext), and that method will only be called if no listeners override it.

      Note that allowing an enchantment using this event does not guarantee the item will receive that enchantment, only that it isn't forbidden from doing so.

      See Also:
    • MODIFY

      public static final Event<EnchantmentEvents.Modify> MODIFY
      An event that allows an Enchantment to be modified without needing to fully override an enchantment.

      This should only be used to modify the behavior of external enchantments, where 'external' means either vanilla or from another mod. For instance, a mod might add a bleed effect to Sharpness (and only Sharpness). For your own enchantments, you should simply define them in your mod's data pack. See the Enchantment Definition page on the Minecraft Wiki for more information.

      Note: If you wish to modify the exclusive set of the enchantment, consider extending the relevant tag through your mod's data pack instead.