Class GetEnchantmentLevelEvent

java.lang.Object
net.neoforged.bus.api.Event
net.neoforged.neoforge.event.enchanting.GetEnchantmentLevelEvent

public class GetEnchantmentLevelEvent extends net.neoforged.bus.api.Event
This event is fired whenever the enchantment level of a particular item is requested for gameplay purposes.
It is called from IItemStackExtension.getEnchantmentLevel(Enchantment) and IItemStackExtension.getAllEnchantments().

It is not fired for interactions with NBT, which means these changes will not reflect in the item tooltip.

  • Field Details

  • Constructor Details

  • Method Details

    • getStack

      public ItemStack getStack()
      Returns the item stack that is being queried against.
    • getEnchantments

      public ItemEnchantments.Mutable getEnchantments()
      Returns the mutable enchantment->level map.
    • getTargetEnchant

      @Nullable public @Nullable Enchantment getTargetEnchant()
      This method returns the specific enchantment being queried from IItemStackExtension.getEnchantmentLevel(Enchantment).

      If this is value is present, you only need to adjust the level of that enchantment.

      If this value is null, then the event was fired from IItemStackExtension.getAllEnchantments() and all enchantments should be populated.

      Returns:
      The specific enchantment being queried, or null, if all enchantments are being requested.
    • isTargetting

      public boolean isTargetting(Enchantment ench)
      Helper method around getTargetEnchant() that checks if the target is the specified enchantment, or if the target is null.
      Parameters:
      ench - The enchantment to check.
      Returns:
      If modifications to the passed enchantment are relevant for this event.