Class ArrowSpell<T extends MagicArrowEntity>

java.lang.Object
com.binaris.wizardry.api.content.spell.Spell
com.binaris.wizardry.content.spell.abstr.ArrowSpell<T>
Type Parameters:
T - The type of MagicArrowEntity this spell launches.
Direct Known Subclasses:
ForceArrowSpell

public class ArrowSpell<T extends MagicArrowEntity> extends Spell
Represents a spell that launches a MagicArrowEntity-based projectile.

This class abstracts the logic of casting spells that behave like arrows, handling all the core steps such as entity creation, aiming, velocity calculation, and launch.

Check Spells#Dart - Spells#MagicMissile for some examples

You must override the properties() to return an actual instance of SpellProperties for this spell or use Spell.assignProperties(SpellProperties), otherwise the spell will have no properties and may not function as intended.

  • Field Details

    • arrowFactory

      protected final Function<net.minecraft.world.level.Level,T extends MagicArrowEntity> arrowFactory
      factory function to create instances of the projectile entity.
  • Constructor Details

    • ArrowSpell

      public ArrowSpell(Function<net.minecraft.world.level.Level,T> arrowFactory)
  • Method Details

    • canCastByEntity

      public boolean canCastByEntity()
      Description copied from class: Spell
      Whether this spell can be cast by an entity source (e.g. a player or a mob). By default, this returns false, as some spells may be designed to only be cast by non-entity sources, but you can override this to return true if your spell is meant to be cast by entities.
      Overrides:
      canCastByEntity in class Spell
      Returns:
      true if this spell can be cast by an entity source, false otherwise.
    • canCastByLocation

      public boolean canCastByLocation()
      Description copied from class: Spell
      Whether this spell can be cast by a non-entity source (e.g. a command block or a dispenser). By default, this returns false, as most spells are meant to be cast by entities, but you can override this to return true if your spell is designed to be cast by non-entity sources.
      Overrides:
      canCastByLocation in class Spell
      Returns:
      true if this spell can be cast by a non-entity source, false otherwise.
    • cast

      public boolean cast(PlayerCastContext ctx)
      Description copied from class: Spell
      This cast method is meant to be used for spells that are cast by a player source. This is useful for spells that are meant to be cast by players, as it provides more information about the caster and the context of the cast.

      Override this method to implement the casting behavior for spells that are meant to be cast by players.

      Specified by:
      cast in class Spell
      Parameters:
      ctx - The context of the spell cast, containing information about the world, caster, hand used, modifiers, etc.
      Returns:
      true if the spell was successfully cast, false otherwise. If this returns false, the spell will not be considered as having been cast, so no cooldown will be applied.
    • cast

      public boolean cast(EntityCastContext ctx)
      Description copied from class: Spell
      This cast method is meant to be used for spells that are cast by an entity source, like a mob. This is useful for spells that are meant to be cast by entities, as it provides more information about the caster and the context of the cast.

      Override this method to implement the casting behavior for spells that are meant to be cast by entities.

      Overrides:
      cast in class Spell
      Parameters:
      ctx - The context of the spell cast, containing information about the world, caster, modifiers, etc.
      Returns:
      true if the spell was successfully cast, false otherwise. If this returns false, the spell will not be considered as having been cast, so no cooldown will be applied.
    • cast

      public boolean cast(LocationCastContext ctx)
      Description copied from class: Spell
      This cast method is meant to be used for spells that are not cast by an entity, but rather by a non-entity source, like a command block or a dispenser. This is useful for spells that are meant to be cast in a specific location without needing an entity to cast them. By default, this returns false, as most spells are meant to be cast by entities. You can override this to return true if your spell is meant to be cast by non-entity sources and to implement the casting behavior for that case.
      Overrides:
      cast in class Spell
      Parameters:
      ctx - The context of the spell cast, containing information about the world, location, modifiers, etc.
      Returns:
      true if the spell was successfully cast, false otherwise. If this returns false, the spell will not be considered as having been cast, so no cooldown will be applied.
    • calculateVelocity

      public float calculateVelocity(CastContext ctx, MagicArrowEntity projectile, float launchHeight)
      Calculates the velocity of the projectile based on gravity and range.
      Parameters:
      ctx - Cast Context about how the spell is cast
      projectile - The projectile entity.
      launchHeight - The vertical height from which the projectile is launched.
      Returns:
      The velocity value to be used when launching the projectile.
    • addArrowExtras

      protected void addArrowExtras(CastContext ctx, T arrow)
      Makes changes to arrows before it's spawned. Override this is subclasses to apply special effects
      Parameters:
      ctx - The context of the spell cast, which may contain useful information for modifying the arrow.
      arrow - The arrow instance to modify.
    • requiresPacket

      public boolean requiresPacket()
      Description copied from class: Spell
      Whether this spell requires a packet to be sent on client when it is cast. Returns true by default, but can be overridden to return false if the spell's cast() method does not use any code that must be executed client-side (i.e. particle spawning).

      If in doubt, leave this method as is; it is purely an optimization.

      Overrides:
      requiresPacket in class Spell
      Returns:
      true if the spell code should be run on the server and all clients in the dimension, false if the spell code should only be run on the server and the client of the player casting it.
    • properties

      @NotNull protected @NotNull SpellProperties properties()
      Description copied from class: Spell
      This method is where you should set the default properties for your spell when creating a new spell class. This method is called in the constructor of the Spell class, and the properties returned by this method are assigned to the spell's properties field.
      Specified by:
      properties in class Spell
      Returns:
      A SpellProperties object with the default properties for your spell.