Record Class SpellCondition
java.lang.Object
java.lang.Record
com.binaris.wizardry.api.content.spell.SpellCondition
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.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordA single condition predicate consisting of a type and a value.static enum -
Constructor Summary
ConstructorsConstructorDescriptionSpellCondition(List<SpellCondition.SingleCondition> conditions) Creates an instance of aSpellConditionrecord class. -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of theconditionsrecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.booleanisEmpty()Checks if this condition has no single conditions.static @Nullable SpellConditionload(net.minecraft.nbt.CompoundTag nbt) Loads aSpellConditionfrom the provided NBT compound tag.static @Nullable SpellConditionParses a string representation of conditions into aSpellCondition.net.minecraft.nbt.CompoundTagsave(net.minecraft.nbt.CompoundTag nbt) Saves thisSpellConditionto the provided NBT compound tag.booleanTests if the given spell satisfies all conditions in thisSpellCondition.booleantest(SpellCondition condition) Tests if thisSpellConditionis a subset or equals of the given condition.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
SpellCondition
Creates an instance of aSpellConditionrecord class.- Parameters:
conditions- the value for theconditionsrecord component
-
-
Method Details
-
test
Tests if the given spell satisfies all conditions in thisSpellCondition.- Parameters:
spell- the spell to test.- Returns:
- true if all conditions are met, false otherwise.
-
test
Tests if thisSpellConditionis 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
Loads aSpellConditionfrom 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 thisSpellConditionto 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
Parses a string representation of conditions into aSpellCondition. The string should be in the format "key1=value1,key2=value2,...". Valid keys are defined bySpellCondition.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
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. All components in this record class are compared withObjects::equals(Object,Object). -
conditions
Returns the value of theconditionsrecord component.- Returns:
- the value of the
conditionsrecord component
-