Record Class DropItemEffect

java.lang.Object
java.lang.Record
johnsmith.enchantmentcore.api.enchantment.effect.DropItemEffect
Record Components:
chance - The LevelBasedValue governing the probability (0.0 to 1.0) that the disarm triggers.
slots - The list of candidate EquipmentSlots eligible to be dropped.
pickOneRandomly - If true, only one randomly chosen populated slot from slots is dropped; if false, 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

    Fields
    Modifier and Type
    Field
    Description
    static final String
    JSON field key for the drop trigger probability.
    static final com.mojang.serialization.MapCodec<DropItemEffect>
    MapCodec for serializing and deserializing DropItemEffect instances from JSON.
    static final String
    Registry path identifier for this entity effect.
    Supplies the JSON property keys holding LevelBasedValue definitions for data transformation.
    static final String
    JSON field key for selecting a single random slot versus dropping all matching slots.
    static final String
    JSON field key for the list of targeted equipment slots.
  • Constructor Summary

    Constructors
    Constructor
    Description
    DropItemEffect(net.minecraft.world.item.enchantment.LevelBasedValue chance, boolean pickOneRandomly)
    Constructs a DropItemEffect with 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 a DropItemEffect record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    addSlot(net.minecraft.world.entity.EquipmentSlot... slot)
    Returns a copy of this DropItemEffect with the specified equipment slots appended to the target list.
    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.
    net.minecraft.world.item.enchantment.LevelBasedValue
    Returns the value of the chance record component.
    com.mojang.serialization.MapCodec<? extends net.minecraft.world.item.enchantment.effects.EnchantmentEntityEffect>
     
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    boolean
    Returns the value of the pickOneRandomly record component.
    List<net.minecraft.world.entity.EquipmentSlot>
    Returns the value of the slots record component.
    final String
    Returns a string representation of this record class.

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface net.minecraft.world.item.enchantment.effects.EnchantmentEntityEffect

    onChangedBlock

    Methods inherited from interface net.minecraft.world.item.enchantment.effects.EnchantmentLocationBasedEffect

    onDeactivated
  • Field Details

    • CHANCE

      public static final String CHANCE
      JSON field key for the drop trigger probability.
      See Also:
    • SLOTS

      public static final String SLOTS
      JSON field key for the list of targeted equipment slots.
      See Also:
    • PICK_ONE_RANDOMLY

      public static final String PICK_ONE_RANDOMLY
      JSON field key for selecting a single random slot versus dropping all matching slots.
      See Also:
    • KEY

      public static final String KEY
      Registry path identifier for this entity effect.
      See Also:
    • KEY_PROVIDER

      public static final LevelBasedKeyProvider KEY_PROVIDER
      Supplies the JSON property keys holding LevelBasedValue definitions for data transformation.
    • CODEC

      public static final com.mojang.serialization.MapCodec<DropItemEffect> CODEC
      MapCodec for serializing and deserializing DropItemEffect instances from JSON.
  • Constructor Details

    • DropItemEffect

      public DropItemEffect(net.minecraft.world.item.enchantment.LevelBasedValue chance, boolean pickOneRandomly)
      Constructs a DropItemEffect with 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 a DropItemEffect record class.
      Parameters:
      chance - the value for the chance record component
      slots - the value for the slots record component
      pickOneRandomly - the value for the pickOneRandomly record 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:
      apply in interface net.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:
      codec in interface net.minecraft.world.item.enchantment.effects.EnchantmentEntityEffect
      Specified by:
      codec in interface net.minecraft.world.item.enchantment.effects.EnchantmentLocationBasedEffect
    • addSlot

      public DropItemEffect addSlot(net.minecraft.world.entity.EquipmentSlot... slot)
      Returns a copy of this DropItemEffect with the specified equipment slots appended to the target list.
      Parameters:
      slot - One or more EquipmentSlots to append.
      Returns:
      A new DropItemEffect instance containing the combined slot list.
    • toString

      public final String 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.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • 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.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • chance

      public net.minecraft.world.item.enchantment.LevelBasedValue chance()
      Returns the value of the chance record component.
      Returns:
      the value of the chance record component
    • slots

      public List<net.minecraft.world.entity.EquipmentSlot> slots()
      Returns the value of the slots record component.
      Returns:
      the value of the slots record component
    • pickOneRandomly

      public boolean pickOneRandomly()
      Returns the value of the pickOneRandomly record component.
      Returns:
      the value of the pickOneRandomly record component