Class EnchantedEntityLootEvent

java.lang.Object
net.neoforged.bus.api.Event

public class EnchantedEntityLootEvent extends LivingEvent

Fired on the server when an entity is dropping loot and the level of a specific enchantment is being queried.

Notably, this fires when EnchantedCountIncreaseFunction or LootItemRandomChanceWithEnchantedBonusCondition are evaluated. Mods that implement similar loot conditions or functions should fire this event as well.

This event does not affect the drop chances of equipment. If you need to change that, use GetEquipmentDropChanceEvent

If you do not need the additional context of this event, prefer GetEnchantmentLevelEvent for managing enchantment levels.

  • Field Details

    • damageSource

      private final DamageSource damageSource
    • enchantment

      private final Holder<Enchantment> enchantment
    • enchantmentLevel

      private int enchantmentLevel
  • Constructor Details

  • Method Details

    • getEntity

      public LivingEntity getEntity()

      Returns the entity that is dropping loot. This is generally the entity that was killed.

      To get the attacking entity, use the getDamageSource() or the getAttacker() helper.

      Overrides:
      getEntity in class LivingEvent
    • getDamageSource

      public DamageSource getDamageSource()
    • getEnchantment

      public Holder<Enchantment> getEnchantment()
    • getEnchantmentLevel

      public int getEnchantmentLevel()
    • setEnchantmentLevel

      public void setEnchantmentLevel(int enchantmentLevel)
      Sets the new enchantment level.
      Throws:
      IllegalArgumentException - if the enchantment level is negative.
    • getAttacker

      public @Nullable Entity getAttacker()
      Returns the attacking entity. If living, the enchantment level was originally queried from that entity. To get the target entity, use getEntity().
      Returns:
      the attacking entity