Class ProjectileSpell<T extends MagicProjectileEntity>
- Type Parameters:
T- The type ofMagicProjectileEntitythis spell shoots.
MagicProjectileEntity). Handles the creation,
positioning, and launching of projectiles with support for damage modifiers, velocity scaling, and spread patterns.
This spell can be cast by players (shooting in their look direction), entities (shooting towards a target), and by location (shooting in the direction of a block face).
Check Spells.POISON_BOMB and Spells.ICE_CHARGE for examples of projectile spells.
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.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionFields inherited from class com.binaris.wizardry.api.content.spell.Spell
pitch, pitchVariation, volume -
Constructor Summary
ConstructorsConstructorDescriptionProjectileSpell(Function<net.minecraft.world.level.Level, T> projectileFactory) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddProjectileExtras(CastContext ctx, T projectile) Allows subclasses to apply additional modifications to the projectile before it is launched.protected floatcalculateVelocity(CastContext ctx, MagicProjectileEntity projectile, float launchHeight) Calculates the velocity at which the projectile should be launched based on the spell's range property, the caster's modifiers, and whether the projectile is affected by gravity.booleanWhether this spell can be cast by an entity source (e.g.booleanWhether this spell can be cast by a non-entity source (e.g.booleancast(EntityCastContext ctx) This cast method is meant to be used for spells that are cast by an entity source, like a mob.booleancast(LocationCastContext ctx) 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.booleancast(PlayerCastContext ctx) This cast method is meant to be used for spells that are cast by a player source.protected @NotNull SpellPropertiesThis method is where you should set the default properties for your spell when creating a new spell class.booleanWhether this spell requires a packet to be sent on client when it is cast.Methods inherited from class com.binaris.wizardry.api.content.spell.Spell
assignProperties, endCast, equals, getAction, getChargeUp, getCooldown, getCost, getDesc, getDescriptionFormatted, getDescriptionId, getElement, getIcon, getLocation, getLoopSounds, getOrCreateDescriptionId, getOrCreateLocation, getPitch, getPitchVariation, getProperties, getTier, getType, getVolume, isEnabled, isInstantCast, onCharge, playSound, playSound, playSound, playSoundLoop, playSoundLoop, property, soundValues, toString
-
Field Details
-
projectileFactory
protected final Function<net.minecraft.world.level.Level,T extends MagicProjectileEntity> projectileFactory
-
-
Constructor Details
-
ProjectileSpell
-
-
Method Details
-
canCastByEntity
public boolean canCastByEntity()Description copied from class:SpellWhether 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:
canCastByEntityin classSpell- Returns:
- true if this spell can be cast by an entity source, false otherwise.
-
canCastByLocation
public boolean canCastByLocation()Description copied from class:SpellWhether 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:
canCastByLocationin classSpell- Returns:
- true if this spell can be cast by a non-entity source, false otherwise.
-
cast
Description copied from class:SpellThis 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:
castin classSpell- 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
Description copied from class:SpellThis 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:
castin classSpell- 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
Description copied from class:SpellThis 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:
castin classSpell- 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
protected float calculateVelocity(CastContext ctx, MagicProjectileEntity projectile, float launchHeight) Calculates the velocity at which the projectile should be launched based on the spell's range property, the caster's modifiers, and whether the projectile is affected by gravity.- Parameters:
ctx- the cast context containing spell information and modifiersprojectile- the projectile entity that will be launchedlaunchHeight- the height from which the projectile is launched (used for gravity-affected projectiles)- Returns:
- the calculated velocity for launching the projectile
-
addProjectileExtras
Allows subclasses to apply additional modifications to the projectile before it is launched.- Parameters:
ctx- the cast context containing spell information and modifiersprojectile- the projectile entity that will be launched
-
requiresPacket
public boolean requiresPacket()Description copied from class:SpellWhether 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:
requiresPacketin classSpell- 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
Description copied from class:SpellThis 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:
propertiesin classSpell- Returns:
- A SpellProperties object with the default properties for your spell.
-