Class ConstructRangedSpell<T extends MagicConstructEntity>

Type Parameters:
T - The type of MagicConstructEntity this spell creates.
Direct Known Subclasses:
Decay, IceSpickes

public class ConstructRangedSpell<T extends MagicConstructEntity> extends ConstructSpell<T>
Extension of ConstructSpell that spawns constructs at a distance from the caster using ray casting.

This spell traces a ray from the caster's position (or from a block face when cast by location) to find the target spawn position. The range of the ray is determined by the DefaultProperties.RANGE property and can be modified by range upgrades.

When cast by a player, the construct is spawned at the point where the player's look direction intersects with a block surface (or at maximum range if no block is hit and ConstructSpell.requiresFloor is false). When cast by an entity, the construct is spawned at the target entity's position if it is within range and not obstructed by blocks. When cast by location, the construct is spawned along the direction specified by the block face, at the point where the ray intersects with a block surface (or at maximum range if no block is hit).

You can configure whether the ray casting should detect liquid blocks by calling hitLiquids(boolean), and whether it should ignore uncollidable blocks by calling ignoreUncollidables(boolean).

You must override the ConstructSpell.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 Details

    • hitLiquids

      protected boolean hitLiquids
      Whether ray casting should detect liquid blocks as solid surfaces. Defaults to false.
    • ignoreUncollidables

      protected boolean ignoreUncollidables
      Whether ray casting should ignore uncollidable blocks (e.g., tall grass, flowers). Defaults to false.
  • Constructor Details

    • ConstructRangedSpell

      public ConstructRangedSpell(Function<net.minecraft.world.level.Level,T> constructFactory, boolean permanent)
      Creates a new ranged construct spell with the specified factory and permanence setting.
      Parameters:
      constructFactory - A function that creates the construct entity given a world
      permanent - Whether the construct should be permanent (true) or temporary (false)
  • Method Details

    • hitLiquids

      public Spell hitLiquids(boolean hitLiquids)
      Sets whether ray casting should detect liquid blocks as solid surfaces.

      When set to true, the ray cast will stop when it hits water, lava, or other liquid blocks, and the construct will be spawned at that position.

      When set to false (default), liquids are treated as air and the ray cast will pass through them.

      Parameters:
      hitLiquids - true to detect liquids, false to ignore them
      Returns:
      this spell instance for method chaining
    • ignoreUncollidables

      public Spell ignoreUncollidables(boolean ignoreUncollidables)
      Sets whether ray casting should ignore uncollidable blocks (e.g., tall grass, flowers, vines).

      When set to true, the ray cast will pass through blocks that don't have collision (like plants and decorative blocks), only stopping when it hits a solid block.

      When set to false (default), the ray cast will stop at any block, including decorative ones.

      Parameters:
      ignoreUncollidables - true to ignore uncollidable blocks, false to detect them
      Returns:
      this spell instance for method chaining
    • cast

      public boolean cast(PlayerCastContext ctx)
      Description copied from class: Spell
      This 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.

      Overrides:
      cast in class ConstructSpell<T extends MagicConstructEntity>
      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

      public boolean cast(EntityCastContext ctx)
      Description copied from class: Spell
      This 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:
      cast in class ConstructSpell<T extends MagicConstructEntity>
      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

      public boolean cast(LocationCastContext ctx)
      Description copied from class: Spell
      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. 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:
      cast in class ConstructSpell<T extends MagicConstructEntity>
      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.