java.lang.Object
java.lang.Record
johnsmith.enchantingoverhauled.api.enchantment.spellfield.AiSpellField
Record Components:
weight - The base selection weight of this spell (must be positive to be selectable).
role - The tactical SpellRole (Offensive, Defensive, or Supportive).
target - The intended SpellTarget category (Self, Ally, or Hostile).
castType - The delivery CastType (Projectile or Direct).
difficultyGate - The minimum world DifficultyGate required for AI entities to cast this spell.
griefing - Whether this spell modifies blocks or causes griefing and therefore requires mobGriefing to be enabled.
schools - An optional HolderSet of MagicSchools associated with this spell.
theme - The EnchantmentTheme key required to cast this spell (defaults to EnchantmentThemes.COMMON).
anchor - An optional AiSpellField.AnchorPayload if the spell persists over time via a SpellFieldAnchorEntity or attached tick loop.
spellField - The underlying SpellFieldComponent defining the volumes, entity/block/volume effects, and visuals.

public record AiSpellField(int weight, SpellRole role, SpellTarget target, CastType castType, DifficultyGate difficultyGate, boolean griefing, Optional<net.minecraft.core.HolderSet<MagicSchool>> schools, net.minecraft.resources.ResourceKey<EnchantmentTheme> theme, Optional<AiSpellField.AnchorPayload> anchor, johnsmith.enchantmentcore.api.enchantment.spellfield.SpellFieldComponent spellField) extends Record
A data-driven record defining an AI spell field that can be selected and cast by flying arcane book entities (AbstractFlyingBookEntity).

Encapsulates selection weight, tactical SpellRole, intended SpellTarget, delivery CastType, minimum world DifficultyGate, mobGriefing requirement, school/theme affinities, optional persistent AiSpellField.AnchorPayload, and the underlying SpellFieldComponent from Enchantment Core.

See Also:
  • Field Details

    • CODEC

      public static final com.mojang.serialization.Codec<AiSpellField> CODEC
      Lazily initialized codec so referencing AiSpellField.CODEC during Forge's DataPackRegistryEvent.NewRegistry does not prematurely trigger SpellFieldComponent class initialization before NewRegistryEvent.fill() populates Enchantment Core's custom registry suppliers.
  • Constructor Details

    • AiSpellField

      public AiSpellField(int weight, SpellRole role, SpellTarget target, CastType castType, DifficultyGate difficultyGate, Optional<net.minecraft.core.HolderSet<MagicSchool>> schools, net.minecraft.resources.ResourceKey<EnchantmentTheme> theme, Optional<AiSpellField.AnchorPayload> anchor, johnsmith.enchantmentcore.api.enchantment.spellfield.SpellFieldComponent spellField)
      Convenience constructor defaulting griefing to false.
      Parameters:
      weight - The base selection weight.
      role - The tactical spell role.
      target - The intended target category.
      castType - The delivery cast type.
      difficultyGate - The minimum world difficulty gate.
      schools - The optional set of associated magic schools.
      theme - The required enchantment theme key.
      anchor - The optional anchor configuration.
      spellField - The spell field component payload.
    • AiSpellField

      public AiSpellField(int weight, SpellRole role, SpellTarget target, CastType castType, Optional<net.minecraft.core.HolderSet<MagicSchool>> schools, net.minecraft.resources.ResourceKey<EnchantmentTheme> theme, Optional<AiSpellField.AnchorPayload> anchor, johnsmith.enchantmentcore.api.enchantment.spellfield.SpellFieldComponent spellField)
      Convenience constructor defaulting difficultyGate to DifficultyGate.EASY and griefing to false.
      Parameters:
      weight - The base selection weight.
      role - The tactical spell role.
      target - The intended target category.
      castType - The delivery cast type.
      schools - The optional set of associated magic schools.
      theme - The required enchantment theme key.
      anchor - The optional anchor configuration.
      spellField - The spell field component payload.
    • AiSpellField

      public AiSpellField(int weight, SpellRole role, SpellTarget target, DifficultyGate difficultyGate, Optional<net.minecraft.core.HolderSet<MagicSchool>> schools, net.minecraft.resources.ResourceKey<EnchantmentTheme> theme, Optional<AiSpellField.AnchorPayload> anchor, johnsmith.enchantmentcore.api.enchantment.spellfield.SpellFieldComponent spellField)
      Convenience constructor deriving castType from target and role, and defaulting griefing to false.
      Parameters:
      weight - The base selection weight.
      role - The tactical spell role.
      target - The intended target category.
      difficultyGate - The minimum world difficulty gate.
      schools - The optional set of associated magic schools.
      theme - The required enchantment theme key.
      anchor - The optional anchor configuration.
      spellField - The spell field component payload.
    • AiSpellField

      public AiSpellField(int weight, SpellRole role, SpellTarget target, Optional<net.minecraft.core.HolderSet<MagicSchool>> schools, net.minecraft.resources.ResourceKey<EnchantmentTheme> theme, Optional<AiSpellField.AnchorPayload> anchor, johnsmith.enchantmentcore.api.enchantment.spellfield.SpellFieldComponent spellField)
      Convenience constructor deriving castType from target and role, and defaulting difficultyGate to DifficultyGate.EASY and griefing to false.
      Parameters:
      weight - The base selection weight.
      role - The tactical spell role.
      target - The intended target category.
      schools - The optional set of associated magic schools.
      theme - The required enchantment theme key.
      anchor - The optional anchor configuration.
      spellField - The spell field component payload.
    • AiSpellField

      public AiSpellField(int weight, SpellRole role, Optional<net.minecraft.core.HolderSet<MagicSchool>> schools, net.minecraft.resources.ResourceKey<EnchantmentTheme> theme, Optional<AiSpellField.AnchorPayload> anchor, johnsmith.enchantmentcore.api.enchantment.spellfield.SpellFieldComponent spellField)
      Convenience constructor deriving both target and castType from role, and defaulting difficultyGate to DifficultyGate.EASY and griefing to false.
      Parameters:
      weight - The base selection weight.
      role - The tactical spell role.
      schools - The optional set of associated magic schools.
      theme - The required enchantment theme key.
      anchor - The optional anchor configuration.
      spellField - The spell field component payload.
    • AiSpellField

      public AiSpellField(int weight, SpellRole role, SpellTarget target, CastType castType, DifficultyGate difficultyGate, boolean griefing, Optional<net.minecraft.core.HolderSet<MagicSchool>> schools, net.minecraft.resources.ResourceKey<EnchantmentTheme> theme, Optional<AiSpellField.AnchorPayload> anchor, johnsmith.enchantmentcore.api.enchantment.spellfield.SpellFieldComponent spellField)
      Creates an instance of a AiSpellField record class.
      Parameters:
      weight - the value for the weight record component
      role - the value for the role record component
      target - the value for the target record component
      castType - the value for the castType record component
      difficultyGate - the value for the difficultyGate record component
      griefing - the value for the griefing record component
      schools - the value for the schools record component
      theme - the value for the theme record component
      anchor - the value for the anchor record component
      spellField - the value for the spellField record component
  • Method Details

    • isDifficultyMet

      public boolean isDifficultyMet(@Nullable @Nullable net.minecraft.world.Difficulty difficulty)
      Checks whether the given world Difficulty satisfies this spell's difficultyGate.
      Parameters:
      difficulty - The current world Difficulty, or null.
      Returns:
      true if the difficulty gate is met; false otherwise.
    • isThemeCompatible

      public boolean isThemeCompatible(@Nullable @Nullable net.minecraft.resources.ResourceKey<EnchantmentTheme> entityTheme)
      Checks whether a caster with the given entityTheme is compatible with this spell's theme.

      Compatibility holds if either the spell's theme or the entity's theme is EnchantmentThemes.COMMON, or if both themes match exactly.

      Parameters:
      entityTheme - The caster's EnchantmentTheme key, or null.
      Returns:
      true if the themes are compatible; false otherwise.
    • hasExactNonCommonThemeMatch

      public boolean hasExactNonCommonThemeMatch(@Nullable @Nullable net.minecraft.resources.ResourceKey<EnchantmentTheme> entityTheme)
      Checks whether both this spell and the caster share the exact same non-common EnchantmentTheme.
      Parameters:
      entityTheme - The caster's EnchantmentTheme key, or null.
      Returns:
      true if both themes are non-common and equal; false otherwise.
    • evaluateSchoolAffinity

      public AiSpellField.SchoolAffinity evaluateSchoolAffinity(@Nullable @Nullable net.minecraft.core.RegistryAccess registryAccess, @Nullable @Nullable net.minecraft.resources.ResourceKey<MagicSchool> entitySchool)
      Evaluates the AiSpellField.SchoolAffinity between this spell's allowed schools and the caster's entitySchool.
      Parameters:
      registryAccess - The active RegistryAccess used to check school cycle tags, or null.
      entitySchool - The caster's MagicSchool key, or null.
      Returns:
      The resolved AiSpellField.SchoolAffinity tier.
    • resolveSpellSchool

      public Optional<net.minecraft.resources.ResourceKey<MagicSchool>> resolveSpellSchool(@Nullable @Nullable net.minecraft.core.RegistryAccess registryAccess, @Nullable @Nullable net.minecraft.resources.ResourceKey<MagicSchool> entitySchool)
      Resolves the specific MagicSchool identity under which this spell is cast by an entity with entitySchool (used for tinting chanting particles and projectiles).
      Parameters:
      registryAccess - The active RegistryAccess, or null.
      entitySchool - The caster's own MagicSchool key, or null.
      Returns:
      An Optional containing the resolved MagicSchool key, or empty if unrestricted.
    • calculateEffectiveWeight

      public int calculateEffectiveWeight(@Nullable @Nullable net.minecraft.core.RegistryAccess registryAccess, @Nullable @Nullable net.minecraft.resources.ResourceKey<EnchantmentTheme> entityTheme, @Nullable @Nullable net.minecraft.resources.ResourceKey<MagicSchool> entitySchool)
      Calculates the effective selection weight of this spell for a caster with the given entityTheme and entitySchool.

      Applies a 3x multiplier for a primary school match, 2x for a cycle sibling match, and an additional 3x multiplier for an exact non-common theme match. Returns 0 if the theme or school is incompatible.

      Parameters:
      registryAccess - The active RegistryAccess, or null.
      entityTheme - The caster's EnchantmentTheme key, or null.
      entitySchool - The caster's MagicSchool key, or null.
      Returns:
      The non-negative effective selection weight.
    • deployAt

      public void deployAt(net.minecraft.server.level.ServerLevel serverLevel, net.minecraft.world.phys.Vec3 position, @Nullable @Nullable net.minecraft.world.entity.LivingEntity owner, net.minecraft.world.entity.Entity spatialSource, net.minecraft.world.item.ItemStack weapon)
      Deploys this spell field at the specified world position.
      Parameters:
      serverLevel - The executing ServerLevel.
      position - The world coordinates where the spell field is deployed.
      owner - The caster LivingEntity, or null.
      spatialSource - The spatial reference entity (such as the target or impact projectile).
      weapon - The catalyst ItemStack held by the caster.
    • deployPayload

      public static void deployPayload(net.minecraft.server.level.ServerLevel serverLevel, net.minecraft.world.phys.Vec3 position, @Nullable @Nullable net.minecraft.world.entity.LivingEntity owner, net.minecraft.world.entity.Entity spatialSource, net.minecraft.world.item.ItemStack weapon, @Nullable @Nullable johnsmith.enchantmentcore.api.enchantment.spellfield.SpellFieldComponent spellField, Optional<AiSpellField.AnchorPayload> anchorPayload)
      Deploys a SpellFieldComponent payload at the given world position, either attaching it directly to a flying book, spawning a persistent SpellFieldAnchorEntity (with hostility tags for CasterHostileCondition), or executing an immediate one-shot application within a MirageEntity.withCasterContext(Entity, Runnable) block.
      Parameters:
      serverLevel - The executing ServerLevel.
      position - The world coordinates for deployment.
      owner - The caster LivingEntity, or null.
      spatialSource - The spatial reference entity.
      weapon - The catalyst ItemStack held by the caster.
      spellField - The SpellFieldComponent to apply, or null.
      anchorPayload - The optional AiSpellField.AnchorPayload governing duration and tick phases.
    • 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 '=='.
      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.
    • weight

      public int weight()
      Returns the value of the weight record component.
      Returns:
      the value of the weight record component
    • role

      public SpellRole role()
      Returns the value of the role record component.
      Returns:
      the value of the role record component
    • target

      public SpellTarget target()
      Returns the value of the target record component.
      Returns:
      the value of the target record component
    • castType

      public CastType castType()
      Returns the value of the castType record component.
      Returns:
      the value of the castType record component
    • difficultyGate

      public DifficultyGate difficultyGate()
      Returns the value of the difficultyGate record component.
      Returns:
      the value of the difficultyGate record component
    • griefing

      public boolean griefing()
      Returns the value of the griefing record component.
      Returns:
      the value of the griefing record component
    • schools

      public Optional<net.minecraft.core.HolderSet<MagicSchool>> schools()
      Returns the value of the schools record component.
      Returns:
      the value of the schools record component
    • theme

      public net.minecraft.resources.ResourceKey<EnchantmentTheme> theme()
      Returns the value of the theme record component.
      Returns:
      the value of the theme record component
    • anchor

      Returns the value of the anchor record component.
      Returns:
      the value of the anchor record component
    • spellField

      public johnsmith.enchantmentcore.api.enchantment.spellfield.SpellFieldComponent spellField()
      Returns the value of the spellField record component.
      Returns:
      the value of the spellField record component