Class GetEquipmentDropChanceEvent
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.
-
Nested Class Summary
Nested classes/interfaces inherited from class LivingEvent
LivingEvent.LivingJumpEvent, LivingEvent.LivingVisibilityEventNested classes/interfaces inherited from class EntityEvent
EntityEvent.EnteringSection, EntityEvent.EntityConstructing, EntityEvent.Size -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final org.apache.commons.lang3.mutable.MutableFloatprivate final DamageSourceprivate final ServerLevelprivate final floatprivate final @Nullable EquipmentSlot -
Constructor Summary
ConstructorsConstructorDescriptionGetEquipmentDropChanceEvent(ServerLevel level, LivingEntity entity, DamageSource killingBlow, org.apache.commons.lang3.mutable.MutableFloat chance, float originalChance, @Nullable EquipmentSlot slot) -
Method Summary
Modifier and TypeMethodDescriptionfloatReturns the current chance modified by enchantments and event consumers.Returns the damage source used to kill the entity.getLevel()floatReturns the chance before any enchantments or event consumers ran.getSlot()Returns the slot containing the item to drop.getStack()Returns the stack being considered for dropping.booleanReturns true if the equipment was guaranteed to drop. Typically means the item was picked rather than natural equipment.voidsetChance(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.Methods inherited from class LivingEvent
getEntity
-
Field Details
-
level
-
killingBlow
-
chance
private final org.apache.commons.lang3.mutable.MutableFloat chance -
originalChance
private final float originalChance -
slot
-
-
Constructor Details
-
GetEquipmentDropChanceEvent
@Internal public GetEquipmentDropChanceEvent(ServerLevel level, LivingEntity entity, DamageSource killingBlow, org.apache.commons.lang3.mutable.MutableFloat chance, float originalChance, @Nullable EquipmentSlot slot)
-
-
Method Details
-
getLevel
-
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
Returns the slot containing the item to drop. May be null ifEnchantmentHelper.processEquipmentDropChance(ServerLevel, LivingEntity, DamageSource, float, EquipmentSlot)is called without the slot.- Returns:
- the slot containing the item to drop
-
getStack
Returns the stack being considered for dropping. May be empty ifEnchantmentHelper.processEquipmentDropChance(ServerLevel, LivingEntity, DamageSource, float, EquipmentSlot)is called without the slot.- Returns:
- the stack being considered for dropping
-