Class Spell
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
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 Summary
FieldsModifier and TypeFieldDescriptionprotected floatprotected floatprotected float -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal SpellassignProperties(SpellProperties properties) booleanbooleanbooleancast(EntityCastContext ctx) booleancast(LocationCastContext ctx) abstract booleancast(PlayerCastContext ctx) voidendCast(CastContext cxt) intintintgetCost()net.minecraft.network.chat.ComponentgetDesc()net.minecraft.network.chat.ComponentWill return the description for the spell (e.g.Will return the description ID for the spell (e.g.net.minecraft.resources.ResourceLocationgetIcon()net.minecraft.resources.ResourceLocationWill return the location for the spell (e.g.protected net.minecraft.sounds.SoundEvent[]Helper method that you could change if you want to add/change the behavior of the sound loops.protected Stringprotected net.minecraft.resources.ResourceLocationfloatgetPitch()floatfinal SpellPropertiesgetTier()getType()floatfinal booleanhasEnded()final booleanfinal booleanWill return true if the spell is registered at the given locationfinal booleanis(net.minecraft.resources.ResourceLocation location) Will return true if the spell is registered at the given locationfinal BooleanisEmpty()booleanisEnabled(SpellContext context) booleanvoidonCharge(CastContext ctx) protected voidplaySound(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.protected voidplaySound(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.protected voidplaySound(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.protected final voidplaySoundLoop(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.protected final voidplaySoundLoop(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.protected abstract @NotNull SpellPropertiesfinal <T> Tproperty(SpellProperty<T> property) booleanWhether this spell requires a packet to be sent when it is cast.voidsetProperties(SpellProperties properties) soundValues(float volume, float pitch, float pitchVariation) Sets the sound parameters for this spell.toString()
-
Field Details
-
volume
protected float volume -
pitch
protected float pitch -
pitchVariation
protected float pitchVariation
-
-
Constructor Details
-
Spell
public Spell()
-
-
Method Details
-
cast
-
cast
-
cast
-
endCast
-
onCharge
-
hasEnded
public final boolean hasEnded() -
isInstantCast
public boolean isInstantCast() -
canCastByEntity
public boolean canCastByEntity() -
canCastByLocation
public boolean canCastByLocation() -
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
-
getDescriptionId
Will return the description ID for the spell (e.g. "spell.ebwizardry.fireball") if you want the location instead, usegetLocation() -
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
Will return true if the spell is registered at the given location -
getProperties
-
setProperties
-
properties
-
assignProperties
-
property
-
is
-
getCharge
public int getCharge() -
getType
-
getAction
-
getElement
-
getTier
-
getCost
public int getCost() -
getCooldown
public int getCooldown() -
isEnabled
-
toString
-
soundValues
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 callsplaySound(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, checkFrostRaySpellas 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 thecast(...)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 thecast(...)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 forplaySound(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 thecast(...)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 thecast(...)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.
-