Record Class DropItemEffect
java.lang.Object
java.lang.Record
johnsmith.enchantmentcore.api.enchantment.effect.DropItemEffect
- Record Components:
chance- TheLevelBasedValuegoverning the probability (0.0 to 1.0) that the disarm triggers.slots- The list of candidateEquipmentSlots eligible to be dropped.pickOneRandomly- Iftrue, only one randomly chosen populated slot fromslotsis dropped; iffalse, all populated candidate slots are dropped simultaneously.
- All Implemented Interfaces:
net.minecraft.world.item.enchantment.effects.EnchantmentEntityEffect,net.minecraft.world.item.enchantment.effects.EnchantmentLocationBasedEffect
public record DropItemEffect(net.minecraft.world.item.enchantment.LevelBasedValue chance, List<net.minecraft.world.entity.EquipmentSlot> slots, boolean pickOneRandomly)
extends Record
implements net.minecraft.world.item.enchantment.effects.EnchantmentEntityEffect
An
EnchantmentEntityEffect that forces a target LivingEntity to unequip and drop
items from specified EquipmentSlots into the world with a 40-tick pickup delay.
Armor pieces enchanted with Curse of Binding (EnchantmentEffectComponents.PREVENT_ARMOR_CHANGE)
are automatically excluded from being disarmed.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringJSON field key for the drop trigger probability.static final com.mojang.serialization.MapCodec<DropItemEffect> MapCodec for serializing and deserializingDropItemEffectinstances from JSON.static final StringRegistry path identifier for this entity effect.static final LevelBasedKeyProviderSupplies the JSON property keys holdingLevelBasedValuedefinitions for data transformation.static final StringJSON field key for selecting a single random slot versus dropping all matching slots.static final StringJSON field key for the list of targeted equipment slots. -
Constructor Summary
ConstructorsConstructorDescriptionDropItemEffect(net.minecraft.world.item.enchantment.LevelBasedValue chance, boolean pickOneRandomly) Constructs aDropItemEffectwith an initially empty slot list for fluent builder-style configuration.DropItemEffect(net.minecraft.world.item.enchantment.LevelBasedValue chance, List<net.minecraft.world.entity.EquipmentSlot> slots, boolean pickOneRandomly) Creates an instance of aDropItemEffectrecord class. -
Method Summary
Modifier and TypeMethodDescriptionaddSlot(net.minecraft.world.entity.EquipmentSlot... slot) Returns a copy of thisDropItemEffectwith the specified equipment slots appended to the target list.voidapply(net.minecraft.server.level.ServerLevel level, int enchantmentLevel, net.minecraft.world.item.enchantment.EnchantedItemInUse itemInUse, net.minecraft.world.entity.Entity target, net.minecraft.world.phys.Vec3 origin) Evaluates the drop probability and forces the target living entity to drop items from the configured equipment slots.net.minecraft.world.item.enchantment.LevelBasedValuechance()Returns the value of thechancerecord component.com.mojang.serialization.MapCodec<? extends net.minecraft.world.item.enchantment.effects.EnchantmentEntityEffect> codec()final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.booleanReturns the value of thepickOneRandomlyrecord component.List<net.minecraft.world.entity.EquipmentSlot> slots()Returns the value of theslotsrecord component.final StringtoString()Returns a string representation of this record class.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface net.minecraft.world.item.enchantment.effects.EnchantmentEntityEffect
onChangedBlockMethods inherited from interface net.minecraft.world.item.enchantment.effects.EnchantmentLocationBasedEffect
onDeactivated
-
Field Details
-
CHANCE
JSON field key for the drop trigger probability.- See Also:
-
SLOTS
JSON field key for the list of targeted equipment slots.- See Also:
-
PICK_ONE_RANDOMLY
JSON field key for selecting a single random slot versus dropping all matching slots.- See Also:
-
KEY
Registry path identifier for this entity effect.- See Also:
-
KEY_PROVIDER
Supplies the JSON property keys holdingLevelBasedValuedefinitions for data transformation. -
CODEC
MapCodec for serializing and deserializingDropItemEffectinstances from JSON.
-
-
Constructor Details
-
DropItemEffect
public DropItemEffect(net.minecraft.world.item.enchantment.LevelBasedValue chance, boolean pickOneRandomly) Constructs aDropItemEffectwith an initially empty slot list for fluent builder-style configuration.- Parameters:
chance- The probability of dropping equipment.pickOneRandomly- Whether to pick only one slot at random from the configured slots.
-
DropItemEffect
public DropItemEffect(net.minecraft.world.item.enchantment.LevelBasedValue chance, List<net.minecraft.world.entity.EquipmentSlot> slots, boolean pickOneRandomly) Creates an instance of aDropItemEffectrecord class.- Parameters:
chance- the value for thechancerecord componentslots- the value for theslotsrecord componentpickOneRandomly- the value for thepickOneRandomlyrecord component
-
-
Method Details
-
apply
public void apply(net.minecraft.server.level.ServerLevel level, int enchantmentLevel, net.minecraft.world.item.enchantment.EnchantedItemInUse itemInUse, net.minecraft.world.entity.Entity target, net.minecraft.world.phys.Vec3 origin) Evaluates the drop probability and forces the target living entity to drop items from the configured equipment slots.- Specified by:
applyin interfacenet.minecraft.world.item.enchantment.effects.EnchantmentEntityEffect- Parameters:
level- The server level in which the effect is triggered.enchantmentLevel- The level of the source enchantment.itemInUse- The context of the enchanted item in use.target- The entity being disarmed.origin- The origin position vector of the trigger.
-
codec
public com.mojang.serialization.MapCodec<? extends net.minecraft.world.item.enchantment.effects.EnchantmentEntityEffect> codec()- Specified by:
codecin interfacenet.minecraft.world.item.enchantment.effects.EnchantmentEntityEffect- Specified by:
codecin interfacenet.minecraft.world.item.enchantment.effects.EnchantmentLocationBasedEffect
-
addSlot
Returns a copy of thisDropItemEffectwith the specified equipment slots appended to the target list.- Parameters:
slot- One or moreEquipmentSlots to append.- Returns:
- A new
DropItemEffectinstance containing the combined slot list.
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with '=='. -
chance
public net.minecraft.world.item.enchantment.LevelBasedValue chance()Returns the value of thechancerecord component.- Returns:
- the value of the
chancerecord component
-
slots
Returns the value of theslotsrecord component.- Returns:
- the value of the
slotsrecord component
-
pickOneRandomly
public boolean pickOneRandomly()Returns the value of thepickOneRandomlyrecord component.- Returns:
- the value of the
pickOneRandomlyrecord component
-