Class AreaEffectSpell
- Direct Known Subclasses:
BlindingFlash,Enrage,Firestorm,FontOfMana,ForestsCurse,GroupHeal,IceAge,InvigoratingPresence,PlagueOfDarkness
This spell can be cast by entities (targeting around themselves or a specific target) and by location (targeting
around a block position). The actual effect applied to each entity is defined by overriding the
affectEntity(CastContext, Vec3, LivingEntity, int) method.
The area of effect radius is determined by the DefaultProperties.EFFECT_RADIUS property and can be modified
by blast upgrades. Targets are automatically sorted by distance from the origin point, with closer entities being
affected first.
The spell automatically spawns particle effects in a circular pattern around the origin point. You can customize the
particle density by calling particleDensity(float) and override spawnParticle(Level, double, double, double)
to define which particles to spawn.
Check Firestorm and FontOfMana
for examples of area effect spells.
You must override the Spell.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 Summary
FieldsModifier and TypeFieldDescriptionprotected booleanWhether this spell should always succeed, even if no targets are affected.protected floatDensity multiplier for particle spawning.protected booleanWhether this spell targets allies instead of enemies.Fields inherited from class com.binaris.wizardry.api.content.spell.Spell
pitch, pitchVariation, volume -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract booleanaffectEntity(CastContext ctx, net.minecraft.world.phys.Vec3 origin, net.minecraft.world.entity.LivingEntity target, int targetCount) Applies the spell's effect to a single target entity.alwaysSucceed(boolean alwaysSucceed) Sets whether this spell should always succeed, regardless of whether any targets are affected.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 booleanfindAndAffectEntities(CastContext ctx, net.minecraft.world.phys.Vec3 origin) Finds all entities within the effect radius and applies the spell's effect to them.particleDensity(float particleDensity) Sets the particle density multiplier for this spell's visual effect.protected voidspawnParticle(net.minecraft.world.level.Level world, double x, double y, double z) Spawns a single particle at the specified position.protected voidspawnParticleEffect(CastContext ctx, net.minecraft.world.phys.Vec3 origin, double radius) Spawns particle effects in a circular pattern around the origin point.targetAllies(boolean targetAllies) Sets whether this spell targets allies instead of enemies.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, properties, property, requiresPacket, soundValues, toString
-
Field Details
-
targetAllies
protected boolean targetAlliesWhether this spell targets allies instead of enemies. Defaults to false. -
alwaysSucceed
protected boolean alwaysSucceedWhether this spell should always succeed, even if no targets are affected. Defaults to false. -
particleDensity
protected float particleDensityDensity multiplier for particle spawning. Higher values spawn more particles. Defaults to 0.65.
-
-
Constructor Details
-
AreaEffectSpell
public AreaEffectSpell()
-
-
Method Details
-
targetAllies
Sets whether this spell targets allies instead of enemies.When set to true, the spell will only affect entities that are allied with the caster. When set to false (default), the spell will only affect valid enemy targets.
- Parameters:
targetAllies- true to target allies, false to target enemies- Returns:
- this spell instance for method chaining
-
alwaysSucceed
Sets whether this spell should always succeed, regardless of whether any targets are affected.When set to true, the spell will return true (success) even if no entities are found or affected. When set to false (default), the spell will only succeed if at least one entity is affected.
- Parameters:
alwaysSucceed- true to always succeed, false to require at least one affected entity- Returns:
- this spell instance for method chaining
-
particleDensity
Sets the particle density multiplier for this spell's visual effect.The actual particle count is calculated as
particleDensity * π * radius², so higher values result in more particles being spawned. The default is 0.65.- Parameters:
particleDensity- the particle density multiplier- Returns:
- this spell instance for method chaining
-
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.
-
findAndAffectEntities
Finds all entities within the effect radius and applies the spell's effect to them.This method calculates the effective radius, searches for all living entities within that radius, filters them based on the
targetAlliessetting, sorts them by distance from the origin, and then callsaffectEntity(CastContext, Vec3, LivingEntity, int)for each target.On the client side, this method also spawns particle effects via
spawnParticleEffect(CastContext, Vec3, double).- Parameters:
ctx- the cast context containing spell information and modifiersorigin- the center point of the area effect- Returns:
- true if at least one entity was affected, or if
alwaysSucceedis true
-
affectEntity
protected abstract boolean affectEntity(CastContext ctx, net.minecraft.world.phys.Vec3 origin, net.minecraft.world.entity.LivingEntity target, int targetCount) Applies the spell's effect to a single target entity.This method must be implemented by subclasses to define what happens when the spell affects an entity. It is called for each valid target found within the area of effect, in order of distance from the origin (closest first).
- Parameters:
ctx- the cast context containing spell information and modifiersorigin- the center point of the area effecttarget- the entity to affecttargetCount- the index of this target in the sorted list (0 for the closest entity, 1 for the second closest, etc.)- Returns:
- true if the entity was successfully affected, false otherwise
-
spawnParticleEffect
protected void spawnParticleEffect(CastContext ctx, net.minecraft.world.phys.Vec3 origin, double radius) Spawns particle effects in a circular pattern around the origin point.The number of particles is determined by
particleDensity * π * radius². Particles are spawned at random positions within the radius, distributed in a circle around the origin.This method calls
spawnParticle(Level, double, double, double)for each particle position. OverridespawnParticleto define which particles to spawn.- Parameters:
ctx- the cast context containing spell informationorigin- the center point of the area effectradius- the radius of the area effect
-
spawnParticle
protected void spawnParticle(net.minecraft.world.level.Level world, double x, double y, double z) Spawns a single particle at the specified position.Override this method in subclasses to define which particle type to spawn and with what parameters. This method is called multiple times by
spawnParticleEffect(CastContext, Vec3, double)to create the full particle effect.- Parameters:
world- the world to spawn the particle inx- the x coordinatey- the y coordinatez- the z coordinate
-