Class GetEquipmentDropChanceEvent

java.lang.Object
net.neoforged.bus.api.Event
net.neoforged.neoforge.event.entity.EntityEvent
net.neoforged.neoforge.event.entity.living.LivingEvent
net.neoforged.neoforge.event.entity.living.GetEquipmentDropChanceEvent

public class GetEquipmentDropChanceEvent extends LivingEvent

Fired on the server when an entity is dying to determine the chance of dropping worn equipment after enchantments process EnchantmentEffectComponents.EQUIPMENT_DROPS.

The entity that was killed and is dropping equipment is accessible in LivingEvent.getEntity(). Use getKillingBlow() for the killing entity.

Only fired if the initial drop chance was greater than 0, meaning it will not fire for cosmetic equipment such as pumpkins during Halloween.

Will be fired for equipment that was picked up by the entity with a guaranteed drop, use isPreserved() to check for that.

If your goal is to implement looting like behavior from an item stack used in the main hand, and you do not need the additional context, prefer GetEnchantmentLevelEvent for managing enchantment levels.

  • Field Details

    • level

      private final ServerLevel level
    • killingBlow

      private final DamageSource killingBlow
    • chance

      private final org.apache.commons.lang3.mutable.MutableFloat chance
    • originalChance

      private final float originalChance
    • slot

      private final @Nullable EquipmentSlot slot
  • Constructor Details

  • Method Details

    • getLevel

      public ServerLevel getLevel()
    • getKillingBlow

      public DamageSource getKillingBlow()
      Returns the damage source used to kill the entity. Will contain the killing entity if present.
      Returns:
      the damage source used to kill the entity
    • getOriginalChance

      public float getOriginalChance()
      Returns the chance before any enchantments or event consumers ran.
      Returns:
      the chance before any enchantments or event consumers ran
      See Also:
    • isPreserved

      public boolean isPreserved()
      Returns true if the equipment was guaranteed to drop. Typically means the item was picked rather than natural equipment.
      Returns:
      true if the equipment was guaranteed to drop. Typically means the item was picked rather than natural equipment
    • getChance

      public float getChance()
      Returns the current chance modified by enchantments and event consumers.
      Returns:
      the current chance modified by enchantments and event consumers
      See Also:
    • setChance

      public void setChance(float chance)
      Sets the chance for this equipment to drop as a value between 0 and 1. 0 or fewer makes it never drop. 1 or more makes it guaranteed to drop.
      Parameters:
      chance - New chance
    • getSlot

      public @Nullable EquipmentSlot getSlot()
      Returns the slot containing the item to drop. May be null if EnchantmentHelper.processEquipmentDropChance(ServerLevel, LivingEntity, DamageSource, float, EquipmentSlot) is called without the slot.
      Returns:
      the slot containing the item to drop
    • getStack

      public ItemStack getStack()
      Returns the stack being considered for dropping. May be empty if EnchantmentHelper.processEquipmentDropChance(ServerLevel, LivingEntity, DamageSource, float, EquipmentSlot) is called without the slot.
      Returns:
      the stack being considered for dropping