Record Class SpellCondition

java.lang.Object
java.lang.Record
com.binaris.wizardry.api.content.spell.SpellCondition

public record SpellCondition(List<SpellCondition.SingleCondition> conditions) extends Record
Represents a set of conditions that can be tested against a Spell. This record encapsulates a list of SpellCondition.SingleCondition predicates that must all be satisfied for the condition to pass.
  • Constructor Details

    • SpellCondition

      public SpellCondition(List<SpellCondition.SingleCondition> conditions)
      Creates an instance of a SpellCondition record class.
      Parameters:
      conditions - the value for the conditions record component
  • Method Details

    • test

      public boolean test(Spell spell)
      Tests if the given spell satisfies all conditions in this SpellCondition.
      Parameters:
      spell - the spell to test.
      Returns:
      true if all conditions are met, false otherwise.
    • test

      public boolean test(SpellCondition condition)
      Tests if this SpellCondition is a subset or equals of the given condition. That is, all conditions in this instance are present in the other condition.
      Parameters:
      condition - the other condition to compare against.
      Returns:
      true if this condition is a subset or equals, false otherwise.
    • isEmpty

      public boolean isEmpty()
      Checks if this condition has no single conditions.
      Returns:
      true if the conditions list is empty, false otherwise.
    • load

      @Nullable public static @Nullable SpellCondition load(net.minecraft.nbt.CompoundTag nbt)
      Loads a SpellCondition from the provided NBT compound tag.
      Parameters:
      nbt - the NBT compound tag to load from.
      Returns:
      the loaded SpellCondition, or null if no conditions were found.
    • save

      public net.minecraft.nbt.CompoundTag save(net.minecraft.nbt.CompoundTag nbt)
      Saves this SpellCondition to the provided NBT compound tag.
      Parameters:
      nbt - the NBT compound tag to save to.
      Returns:
      the modified NBT compound tag. (Or same nbt tag if there isn't any conditions)
    • parse

      @Nullable public static @Nullable SpellCondition parse(String raw)
      Parses a string representation of conditions into a SpellCondition. The string should be in the format "key1=value1,key2=value2,...". Valid keys are defined by SpellCondition.Type.key().
      Parameters:
      raw - the raw string to parse.
      Returns:
      the parsed SpellCondition, or null if the string is blank or no conditions are parsed.
      Throws:
      IllegalArgumentException - if the string format is invalid or contains unknown keys/values.
    • 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. All components in this record class are compared with Objects::equals(Object,Object).
      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.
    • conditions

      public List<SpellCondition.SingleCondition> conditions()
      Returns the value of the conditions record component.
      Returns:
      the value of the conditions record component