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

  • Field Details

    • arrowFactory

      protected final Function<net.minecraft.world.level.Level,T extends MagicArrowEntity> arrowFactory
      A 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()
      Overrides:
      canCastByEntity in class Spell
    • canCastByLocation

      public boolean canCastByLocation()
      Overrides:
      canCastByLocation in class Spell
    • cast

      public boolean cast(PlayerCastContext ctx)
      Specified by:
      cast in class Spell
    • cast

      public boolean cast(EntityCastContext ctx)
      Overrides:
      cast in class Spell
    • cast

      public boolean cast(LocationCastContext ctx)
      Overrides:
      cast in class Spell
    • 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(T arrow, CastContext ctx)
      Makes changes to arrows before it's spawned. Override this is subclasses to apply special effects
      Parameters:
      arrow - The arrow instance to modify.
      ctx - The context of the spell cast, which may contain useful information for modifying the arrow.
    • requiresPacket

      public boolean requiresPacket()
      Description copied from class: Spell
      Whether this spell requires a packet to be sent 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). This is not checked for continuous spells, because they never need to send packets.

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

      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()
      Specified by:
      properties in class Spell