Class FrostRay


public class FrostRay extends RaySpell
  • Constructor Details

    • FrostRay

      public FrostRay()
  • Method Details

    • onEntityHit

      protected boolean onEntityHit(CastContext ctx, net.minecraft.world.phys.EntityHitResult entityHit, net.minecraft.world.phys.Vec3 origin)
      Description copied from class: RaySpell
      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).
      Specified by:
      onEntityHit in class RaySpell
      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.
    • onMiss

      protected boolean onMiss(CastContext ctx, net.minecraft.world.phys.Vec3 origin, net.minecraft.world.phys.Vec3 direction)
      Description copied from class: RaySpell
      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).
      Specified by:
      onMiss in class RaySpell
      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.
    • onBlockHit

      protected boolean onBlockHit(CastContext ctx, net.minecraft.world.phys.BlockHitResult blockHit, net.minecraft.world.phys.Vec3 origin)
      Description copied from class: RaySpell
      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).
      Specified by:
      onBlockHit in class RaySpell
      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.
    • getChargeUp

      public int getChargeUp()
      Description copied from class: Spell
      Gets the charge-up time of this spell in ticks. By default, this is 0, meaning the spell is instant and has no charge-up time.
      Overrides:
      getChargeUp in class Spell
      Returns:
      The charge-up time of this spell in ticks.
    • spawnParticle

      protected void spawnParticle(CastContext ctx, double x, double y, double z, double vx, double vy, double vz)
      Description copied from class: RaySpell
      Spawns a particle at the given position with the given velocity. Override this method to spawn custom particles for the ray.
      Overrides:
      spawnParticle in class RaySpell
      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.
    • playSound

      protected void playSound(net.minecraft.world.level.Level world, net.minecraft.world.entity.LivingEntity entity, int castTicks, int duration)
      Description copied from class: Spell
      Plays this spell's sound at the given entity in the given world. This calls Spell.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.

      Overrides:
      playSound in class Spell
      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, double x, double y, double z, int ticksInUse, int duration)
      Description copied from class: Spell
      Plays this spell's sounds at the given position in the given world. This is not called automatically by the Spell class; subclasses should call it at the appropriate point(s) in the cast methods. You can also override this method if you want to implement a sound loop (normally for continuous spells), check FrostRaySpell as an example.

      In case you're using any standard subclass of Spell (e.g. RaySpell ArrowSpell) you won't need to handle the sound system by yourself, as these classes will call the playSound in the right moment for you.

      Overrides:
      playSound in class Spell
      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.
      ticksInUse - The number of ticks this spell has already been cast for, passed in from the cast(...) methods.
      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.
    • isInstantCast

      public boolean isInstantCast()
      Description copied from class: Spell
      Whether this spell is instant or not. An instant spell is a spell that is cast in a single tick, (it could have cooldown and/or charge-up time) and does not have a duration. By default, this returns true, as most spells are instant, but you can override this to return false if your spell is meant to have a duration and be cast over multiple ticks.
      Overrides:
      isInstantCast in class Spell
      Returns:
      true if this spell is instant, false otherwise.
    • properties

      @NotNull protected @NotNull SpellProperties properties()
      Description copied from class: Spell
      This 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:
      properties in class Spell
      Returns:
      A SpellProperties object with the default properties for your spell.