java.lang.Object
com.binaris.wizardry.api.content.spell.Spell
Direct Known Subclasses:
AreaEffectSpell, ArrowSpell, BetterFlight, Blink, BlockWithSurprise, BuffSpell, Charge, ConjureItemSpell, ConstructSpell, DragonFireball, Evade, Fangs, FlamingWeapon, Flight, FrostBarrier, GrowthAura, ImbueWeapon, InvokeWeather, Leap, Levitation, LightningPulse, MinionSpell, NoneSpell, PhaseStep, PocketFurnace, PocketWorkbench, ProjectileSpell, RaySpell, ShulkerBullet, SpeedTime, VanishingBox, WitherSkullSpell

public abstract class Spell extends Object
The Spell class serves as a blueprint for different types of spells. Subclasses inherit from it to ensure consistency. By defining common behavior and methods in the Spell class, we establish a standardized interface for interacting with spells throughout the codebase. This makes the code more organized, easier to understand, and less prone to errors.
  • Field Details

    • volume

      protected float volume
    • pitch

      protected float pitch
    • pitchVariation

      protected float pitchVariation
  • Constructor Details

    • Spell

      public Spell()
  • Method Details

    • cast

      public abstract boolean cast(PlayerCastContext ctx)
    • cast

      public boolean cast(EntityCastContext ctx)
    • cast

      public boolean cast(LocationCastContext ctx)
    • endCast

      public void endCast(CastContext cxt)
    • onCharge

      public void onCharge(CastContext ctx)
    • hasEnded

      public final boolean hasEnded()
    • isInstantCast

      public boolean isInstantCast()
    • canCastByEntity

      public boolean canCastByEntity()
    • canCastByLocation

      public boolean canCastByLocation()
    • isEmpty

      public final Boolean isEmpty()
    • requiresPacket

      public boolean requiresPacket()
      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.

      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.
    • getDescriptionFormatted

      public net.minecraft.network.chat.Component getDescriptionFormatted()
      Will return the description for the spell (e.g. "Fireball")
    • getOrCreateDescriptionId

      protected String getOrCreateDescriptionId()
    • getDescriptionId

      public String getDescriptionId()
      Will return the description ID for the spell (e.g. "spell.ebwizardry.fireball") if you want the location instead, use getLocation()
    • getOrCreateLocation

      protected net.minecraft.resources.ResourceLocation getOrCreateLocation()
    • getLocation

      public net.minecraft.resources.ResourceLocation getLocation()
      Will return the location for the spell (e.g. "ebwizardry:fireball")
    • getDesc

      public net.minecraft.network.chat.Component getDesc()
    • getIcon

      public net.minecraft.resources.ResourceLocation getIcon()
    • is

      public final boolean is(net.minecraft.resources.ResourceLocation location)
      Will return true if the spell is registered at the given location
    • is

      public final boolean is(String location)
      Will return true if the spell is registered at the given location
    • getProperties

      public final SpellProperties getProperties()
    • setProperties

      public void setProperties(SpellProperties properties)
    • properties

      @NotNull protected abstract @NotNull SpellProperties properties()
    • assignProperties

      public final Spell assignProperties(SpellProperties properties)
    • property

      public final <T> T property(SpellProperty<T> property)
    • is

      public final boolean is(Spell spell)
    • getCharge

      public int getCharge()
    • getType

      public SpellType getType()
    • getAction

      public SpellAction getAction()
    • getElement

      public Element getElement()
    • getTier

      public SpellTier getTier()
    • getCost

      public int getCost()
    • getCooldown

      public int getCooldown()
    • isEnabled

      public boolean isEnabled(SpellContext context)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • soundValues

      public Spell soundValues(float volume, float pitch, float pitchVariation)
      Sets the sound parameters for this spell.
      Parameters:
      volume - The volume of the sound played by this spell, relative to 1.
      pitch - The pitch of the sound played by this spell, relative to 1.
      pitchVariation - The random variation in the pitch of the sound played by this spell. The pitch at which the sound is played will be randomly chosen from the range: pitch +/- pitchVariation.
      Returns:
      The spell instance, allowing this method to be chained onto the constructor.
    • getVolume

      public float getVolume()
    • getPitch

      public float getPitch()
    • getPitchVariation

      public float getPitchVariation()
    • playSound

      protected void playSound(net.minecraft.world.level.Level world, net.minecraft.world.entity.LivingEntity entity, int castTicks, int duration)
      Plays this spell's sound at the given entity in the given world. This calls playSound(Level, double, double, double, int, int), passing in the given entity's position as the xyz coordinates. Also checks if the given entity is silent, and if so, does not play the sound.

      You should override this is you're trying to implement a custom sound loop, check FrostRaySpell as an example.
      Parameters:
      world - The world to play the sound in.
      entity - The entity to play the sound at, provided it is not silent.
      castTicks - The number of ticks this spell has already been cast for, passed in from the cast(...) methods. Not used in the base method, but included for use by subclasses overriding this method.
      duration - The number of ticks this spell will be cast for, passed in from the cast(...) methods. Not used in the base method, but included for use by subclasses overriding this method.
    • playSound

      protected void playSound(net.minecraft.world.level.Level world, net.minecraft.world.phys.Vec3 pos, int castTicks, int duration)
      Plays this spell's sound at the given position in the given world. This is a vector-based wrapper for playSound(Level, double, double, double, int, int).
      Parameters:
      world - The world to play the sound in.
      pos - A vector representing the position to play the sound at.
      castTicks - The number of ticks this spell has already been cast for, passed in from the cast(...) methods. Not used in the base method, but included for use by subclasses overriding this method.
      duration - The number of ticks this spell will be cast for, passed in from the cast(...) methods. Not used in the base method, but included for use by subclasses overriding this method.
    • playSound

      protected void playSound(net.minecraft.world.level.Level world, double x, double y, double z, int ticksInUse, int duration)
      Plays this spell's sounds at the given position in the given world. This is not called automatically; subclasses should call it at the appropriate point(s) in the cast methods. Extend this method entirely if you want to add extra sounds or change the sound behaviour.
      Parameters:
      world - The world to play the sound in.
      x - The x position to play the sound at.
      y - The y position to play the sound at.
      z - The z position to play the sound at.
    • playSoundLoop

      protected final void playSoundLoop(net.minecraft.world.level.Level world, net.minecraft.world.entity.LivingEntity entity, int ticksInUse)
      Helper method which plays a standard continuous spell sound loop on the first casting tick, which moves with the given entity.
    • playSoundLoop

      protected final void playSoundLoop(net.minecraft.world.level.Level world, double x, double y, double z, int ticksInUse, int duration)
      Helper method which plays a standard continuous spell sound loop on the first casting tick, at the given coordinates. If the given duration is -1, the coordinates must be those of a dispenser.
    • getLoopSounds

      protected net.minecraft.sounds.SoundEvent[] getLoopSounds()
      Helper method that you could change if you want to add/change the behavior of the sound loops.