Record Class CasterHostileCondition

java.lang.Object
java.lang.Record
johnsmith.enchantingoverhauled.api.loot.condition.CasterHostileCondition
All Implemented Interfaces:
Predicate<net.minecraft.world.level.storage.loot.LootContext>, net.minecraft.world.level.storage.loot.LootContextUser, net.minecraft.world.level.storage.loot.predicates.LootItemCondition

public record CasterHostileCondition() extends Record implements net.minecraft.world.level.storage.loot.predicates.LootItemCondition
A LootItemCondition that evaluates to true if the spell field's caster (or an active SpellFieldAnchorEntity / nearby AbstractFlyingBookEntity) is actively hostile towards the target entity (LootContextParams.THIS_ENTITY).

Allows offensive spell fields to harm players wearing enchanted armor when the caster has been provoked or is actively targeting them in self-defense, while also allowing offensive spell fields to harm hostile non-player mobs wearing enchanted armor.

  • Nested Class Summary

    Nested classes/interfaces inherited from interface net.minecraft.world.level.storage.loot.predicates.LootItemCondition

    net.minecraft.world.level.storage.loot.predicates.LootItemCondition.Builder
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Entity tag prefix applied to SpellFieldAnchorEntity instances to record the UUID of the target entity the caster was angry at when deploying the anchor.
    static final com.mojang.serialization.MapCodec<CasterHostileCondition>
    Unit MapCodec returning INSTANCE when deserializing from JSON.
    Singleton instance of CasterHostileCondition.

    Fields inherited from interface net.minecraft.world.level.storage.loot.predicates.LootItemCondition

    DIRECT_CODEC, TYPED_CODEC
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an instance of a CasterHostileCondition record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    static net.minecraft.world.level.storage.loot.predicates.LootItemCondition.Builder
    Creates a LootItemCondition.Builder that supplies INSTANCE.
    final boolean
    Indicates whether some other object is "equal to" this one.
    @NotNull net.minecraft.world.level.storage.loot.predicates.LootItemConditionType
    Retrieves the registered LootItemConditionType for this condition.
    final int
    Returns a hash code value for this object.
    boolean
    test(net.minecraft.world.level.storage.loot.LootContext context)
    Evaluates whether the spell caster is actively hostile toward LootContextParams.THIS_ENTITY.
    final String
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

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

    Methods inherited from interface net.minecraft.world.level.storage.loot.LootContextUser

    getReferencedContextParams, validate

    Methods inherited from interface java.util.function.Predicate

    and, negate, or
  • Field Details

    • INSTANCE

      public static final CasterHostileCondition INSTANCE
      Singleton instance of CasterHostileCondition.
    • CODEC

      public static final com.mojang.serialization.MapCodec<CasterHostileCondition> CODEC
      Unit MapCodec returning INSTANCE when deserializing from JSON.
    • ANGRY_AT_TAG_PREFIX

      public static final String ANGRY_AT_TAG_PREFIX
      Entity tag prefix applied to SpellFieldAnchorEntity instances to record the UUID of the target entity the caster was angry at when deploying the anchor.
      See Also:
  • Constructor Details

    • CasterHostileCondition

      public CasterHostileCondition()
      Creates an instance of a CasterHostileCondition record class.
  • Method Details

    • builder

      public static net.minecraft.world.level.storage.loot.predicates.LootItemCondition.Builder builder()
      Creates a LootItemCondition.Builder that supplies INSTANCE.
      Returns:
      A condition builder for CasterHostileCondition.
    • getType

      @NotNull public @NotNull net.minecraft.world.level.storage.loot.predicates.LootItemConditionType getType()
      Retrieves the registered LootItemConditionType for this condition.
      Specified by:
      getType in interface net.minecraft.world.level.storage.loot.predicates.LootItemCondition
      Returns:
      The LootItemConditionTypes.CASTER_HOSTILE condition type.
    • test

      public boolean test(net.minecraft.world.level.storage.loot.LootContext context)
      Evaluates whether the spell caster is actively hostile toward LootContextParams.THIS_ENTITY.

      Checks the thread-local caster context from MirageEntity.getCurrentCasterContext(), the LootContextParams.ATTACKING_ENTITY parameter (unwrapping projectiles and mirages), nearby tagged SpellFieldAnchorEntity instances within 16 blocks, and nearby hostile AbstractFlyingBookEntity instances within 48 blocks.

      Specified by:
      test in interface Predicate<net.minecraft.world.level.storage.loot.LootContext>
      Parameters:
      context - The LootContext containing the target entity and level state.
      Returns:
      true if the caster or a nearby spell anchor/flying book is hostile toward the target entity; false otherwise.
    • 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.
      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.