Class RaySpell
java.lang.Object
com.binaris.wizardry.api.content.spell.Spell
com.binaris.wizardry.content.spell.abstr.RaySpell
- Direct Known Subclasses:
Arc,ArcaneJammer,ArcaneLockSpell,Banish,Bubble,Cobwebs,Containment,CurseOfEnfeeblement,CurseOfSoulbinding,CurseOfUndeath,Detonate,Entrapment,FireBreath,FlameRay,Freeze,FrostRay,HealAlly,Ignite,LifeDrain,Meteor,Permafrost,PlayerHand,Poison,RayOfPurification,Reversal,Telekinesis,TrapSlime,Whirlwind,Wither,WizardHand
Base class for spells that cast a ray from the caster's position or a location, affecting entities and blocks along
the ray's path. The ray is traced using ray casting, and can be configured to detect liquids, ignore uncollidable blocks,
and pass through entities.
The ray is traced from the caster's eye position (or from a block face when cast by location) in the direction the caster is looking (or in the direction of the block face).
Check FrostRay and FlameRay for examples of ray 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 floatWhether the ray should have aim assist to slightly adjust towards nearby targets.protected booleanWhether the ray should treat liquid blocks (like water and lava) as solid and stop when it hits them.protected booleanWhether the ray should ignore living entities when ray tracing, allowing it to pass through them.protected booleanWhether the ray should ignore uncollidable blocks (like tall grass, flowers, etc.) when ray tracing.protected doubleThe amount of random jitter applied to the position of each particle spawned along the ray, creating a more natural effect.protected doubleThe spacing between particles spawned along the ray.protected doubleThe velocity of the particles spawned along the rayprotected static final doubleThe vertical offset from the caster's eye position to the actual origin of the ray.Fields inherited from class com.binaris.wizardry.api.content.spell.Spell
pitch, pitchVariation, volume -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaimAssist(float aimAssist) Sets the aim assist for this ray spell.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.hitLiquids(boolean hitLiquids) When set to true, the ray will treat liquid blocks (like water and lava) as solid and stop when it hits them.ignoreLivingEntities(boolean ignoreLivingEntities) When set to true, the ray will ignore living entities when performing ray tracing.ignoreUncollidables(boolean ignoreUncollidables) When set to true, the ray will ignore uncollidable blocks such as tall grass, flowers, and other non-solid blocks.protected abstract booleanonBlockHit(CastContext ctx, net.minecraft.world.phys.BlockHitResult blockHit, net.minecraft.world.phys.Vec3 origin) Called when the ray hits a block.protected abstract booleanonEntityHit(CastContext ctx, net.minecraft.world.phys.EntityHitResult entityHit, net.minecraft.world.phys.Vec3 origin) Called when the ray hits an entity.protected abstract booleanonMiss(CastContext ctx, net.minecraft.world.phys.Vec3 origin, net.minecraft.world.phys.Vec3 direction) Called when the ray does not hit any entities or blocks.particleJitter(double particleJitter) Sets the amount of random jitter applied to the position of each particle spawned along the ray.particleSpacing(double particleSpacing) Sets the spacing between particles spawned along the ray.particleVelocity(double particleVelocity) Sets the velocity of the particles spawned along the ray.protected booleanshootSpell(CastContext ctx, net.minecraft.world.phys.Vec3 origin, net.minecraft.world.phys.Vec3 direction) Performs the ray casting logic for the spell, tracing a ray from the origin in the given direction and checking for hits against entities and blocks.protected voidspawnParticle(CastContext ctx, double x, double y, double z, double vx, double vy, double vz) Spawns a particle at the given position with the given velocity.protected voidspawnParticleRay(CastContext ctx, net.minecraft.world.phys.Vec3 origin, net.minecraft.world.phys.Vec3 direction, double distance) Spawns particles along the ray from the origin in the given direction up to the given distance.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
-
Y_OFFSET
protected static final double Y_OFFSETThe vertical offset from the caster's eye position to the actual origin of the ray.- See Also:
-
particleSpacing
protected double particleSpacingThe spacing between particles spawned along the ray. -
particleJitter
protected double particleJitterThe amount of random jitter applied to the position of each particle spawned along the ray, creating a more natural effect. -
particleVelocity
protected double particleVelocityThe velocity of the particles spawned along the ray -
ignoreLivingEntities
protected boolean ignoreLivingEntitiesWhether the ray should ignore living entities when ray tracing, allowing it to pass through them. -
hitLiquids
protected boolean hitLiquidsWhether the ray should treat liquid blocks (like water and lava) as solid and stop when it hits them. -
ignoreUncollidables
protected boolean ignoreUncollidablesWhether the ray should ignore uncollidable blocks (like tall grass, flowers, etc.) when ray tracing. -
aimAssist
protected float aimAssistWhether the ray should have aim assist to slightly adjust towards nearby targets.
-
-
Constructor Details
-
RaySpell
public RaySpell()
-
-
Method Details
-
particleSpacing
Sets the spacing between particles spawned along the ray. The particles will be spawned at regular intervals along the ray, with the distance between each particle determined by this value. A smaller value will result in more particles being spawned and a denser particle effect, while a larger value will result in fewer particles and a sparser effect. The default value is 0.85, which means that particles will be spawned approximately every 0.85 blocks along the ray.- Parameters:
particleSpacing- The distance between particles along the ray.- Returns:
- This spell instance for method chaining.
-
particleJitter
Sets the amount of random jitter applied to the position of each particle spawned along the ray. This creates a more natural and less uniform appearance for the particle effects. The jitter is applied in all directions, so a value of 0.1 means that each particle's position can be randomly offset by up to 0.1 blocks in any direction from its ideal position along the ray.- Parameters:
particleJitter- The maximum random offset for particle positions, where 0 means no jitter and higher values increase the randomness.- Returns:
- This spell instance for method chaining.
-
particleVelocity
Sets the velocity of the particles spawned along the ray. The velocity is applied in the direction of the ray, so positive values will make the particles move forward along the ray, while negative values will make them move backward towards the caster. A value of 0 means the particles will be stationary.- Parameters:
particleVelocity- The velocity of the particles along the ray direction.- Returns:
- This spell instance for method chaining.
-
ignoreLivingEntities
When set to true, the ray will ignore living entities when performing ray tracing. This means that the ray will pass through living entities without stopping, allowing it to hit blocks or entities behind them. When set to false, the ray will treat living entities as solid and stop when it hits them.- Parameters:
ignoreLivingEntities- true to ignore living entities, false to treat them as solid- Returns:
- this spell instance for method chaining
-
hitLiquids
When set to true, the ray will treat liquid blocks (like water and lava) as solid and stop when it hits them. This means that the ray will not pass through liquids and will hit the liquid block instead. When set to false, liquids are treated as air and the ray will pass through them without stopping.- Parameters:
hitLiquids- true to treat liquids as solid, false to ignore them- Returns:
- this spell instance for method chaining
-
ignoreUncollidables
When set to true, the ray will ignore uncollidable blocks such as tall grass, flowers, and other non-solid blocks. This means that the ray will pass through these blocks without stopping, allowing it to hit entities or blocks behind them. When set to false, the ray will treat uncollidable blocks as solid and stop when it hits them.- Parameters:
ignoreUncollidables- true to ignore uncollidable blocks, false to treat them as solid- Returns:
- this spell instance for method chaining
-
aimAssist
Sets the aim assist for this ray spell. Aim assist helps the ray to slightly adjust its direction towards nearby valid targets, making it easier to hit them.- Parameters:
aimAssist- The strength of the aim assist, where 0 means no assist and higher values increase the assist. A value of 1 would mean the ray can adjust its direction by up to 1 block towards a target.- 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.
-
onEntityHit
protected abstract boolean onEntityHit(CastContext ctx, net.minecraft.world.phys.EntityHitResult entityHit, net.minecraft.world.phys.Vec3 origin) Called when the ray hits an entity. Override this method to perform an action when the ray hits an entity, such as dealing damage or applying a status effect. Return true if the spell should be considered successfully cast when it hits an entity, or false if the spell should not be cast when it hits an entity (e.g. if you want to prevent casting when the ray is blocked by an uncollidable block and ignoreUncollidables is true).- Parameters:
ctx- The cast context of the spell.entityHit- The result of the entity hit, containing information about the hit entity and hit position.origin- The starting point of the ray.- Returns:
- true if the spell should be considered successfully cast when it hits an entity, false if the spell should not be cast when it hits an entity.
-
onBlockHit
protected abstract boolean onBlockHit(CastContext ctx, net.minecraft.world.phys.BlockHitResult blockHit, net.minecraft.world.phys.Vec3 origin) Called when the ray hits a block. Override this method to perform an action when the ray hits a block, such as creating an explosion or spawning particles. Return true if the spell should be considered successfully cast when it hits a block, or false if the spell should not be cast when it hits a block (e.g. if you want to prevent casting when the ray is blocked by an uncollidable block and ignoreUncollidables is true).- Parameters:
ctx- The cast context of the spell.blockHit- The result of the block hit, containing information about the hit position and block.origin- The starting point of the ray.- Returns:
- true if the spell should be considered successfully cast when it hits a block, false if the spell should not be cast when it hits a block.
-
onMiss
protected abstract boolean onMiss(CastContext ctx, net.minecraft.world.phys.Vec3 origin, net.minecraft.world.phys.Vec3 direction) Called when the ray does not hit any entities or blocks. Override this method to perform an action when the ray misses, such as spawning particles at the endpoint. Return true if the spell should be considered successfully cast even when it misses, or false if the spell should not be cast when it misses (e.g. if you want to prevent casting when the ray is blocked by an uncollidable block and ignoreUncollidables is true).- Parameters:
ctx- The cast context of the spell.origin- The starting point of the ray.direction- The normalized direction vector of the ray.- Returns:
- true if the spell should be considered successfully cast even when it misses, false if the spell should not be cast when it misses.
-
shootSpell
protected boolean shootSpell(CastContext ctx, net.minecraft.world.phys.Vec3 origin, net.minecraft.world.phys.Vec3 direction) Performs the ray casting logic for the spell, tracing a ray from the origin in the given direction and checking for hits against entities and blocks. This method handles the ray casting and hit detection, while delegating the actual effects of hitting an entity or block to theonEntityHit(com.binaris.wizardry.api.content.spell.internal.CastContext, net.minecraft.world.phys.EntityHitResult, net.minecraft.world.phys.Vec3)andonBlockHit(com.binaris.wizardry.api.content.spell.internal.CastContext, net.minecraft.world.phys.BlockHitResult, net.minecraft.world.phys.Vec3)methods.- Parameters:
ctx- The cast context of the spell.origin- The starting point of the ray.direction- The normalized direction vector of the ray.- Returns:
- true if the spell was successfully cast (hit an entity, hit a block, or missed), false if the spell should not be cast (e.g. if it was blocked by an uncollidable block and ignoreUncollidables is true).
-
spawnParticleRay
protected void spawnParticleRay(CastContext ctx, net.minecraft.world.phys.Vec3 origin, net.minecraft.world.phys.Vec3 direction, double distance) Spawns particles along the ray from the origin in the given direction up to the given distance. The particles are spaced according toparticleSpacingand have a random jitter based onparticleJitter. The velocity of the particles is determined byparticleVelocity.- Parameters:
ctx- The cast context of the spell.origin- The starting point of the ray.direction- The normalized direction vector of the ray.distance- The distance to spawn particles along the ray.
-
spawnParticle
protected void spawnParticle(CastContext ctx, double x, double y, double z, double vx, double vy, double vz) Spawns a particle at the given position with the given velocity. Override this method to spawn custom particles for the ray.- Parameters:
ctx- The cast context of the spell.x- The x-coordinate of the particle.y- The y-coordinate of the particle.z- The z-coordinate of the particle.vx- The x-component of the particle's velocity.vy- The y-component of the particle's velocity.vz- The z-component of the particle's velocity.
-