Class ConstructSpell<T extends MagicConstructEntity>

java.lang.Object
com.binaris.wizardry.api.content.spell.Spell
com.binaris.wizardry.content.spell.abstr.ConstructSpell<T>
Type Parameters:
T - The type of MagicConstructEntity this spell creates.
Direct Known Subclasses:
ArrowRain, Boulder, ConstructRangedSpell, Hailstorm, Tornado, ZombieApocalypse

public class ConstructSpell<T extends MagicConstructEntity> extends Spell
Base class for spells that spawn magical construct entities (MagicConstructEntity). Handles the creation, positioning, and spawning of constructs with support for lifetime management, scaling, and damage modifiers.

This spell can be cast by entities (spawning the construct at the caster's position) and by location (spawning the construct at a specific block position). Constructs can be either permanent (lifetime = -1) or temporary with a duration determined by the DefaultProperties.DURATION property.

The construct's position can be constrained to require a floor surface by calling floor(boolean), and multiple constructs can be prevented from overlapping by calling overlap(boolean).

If the construct implements ScaledConstructEntity, its size will automatically scale based on blast upgrade modifiers. The construct's damage is also automatically modified by the potency modifier.

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.

  • Field Details

    • constructFactory

      protected final Function<net.minecraft.world.level.Level,T extends MagicConstructEntity> constructFactory
      Factory function to create instances of the construct entity.
    • permanent

      protected final boolean permanent
      Whether this construct is permanent (true) or has a limited lifetime (false).
    • requiresFloor

      protected boolean requiresFloor
      Whether the construct requires a floor surface to spawn on. Defaults to false.
    • allowOverlap

      protected boolean allowOverlap
      Whether multiple constructs of the same type can overlap at the same position. Defaults to false.
  • Constructor Details

    • ConstructSpell

      public ConstructSpell(Function<net.minecraft.world.level.Level,T> constructFactory, boolean permanent)
      Creates a new 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

    • floor

      public ConstructSpell<T> floor(boolean requiresFloor)
      Sets whether this spell requires a floor surface to spawn the construct on.

      When set to true, the spell will search for the nearest floor surface below the target position (up to 1 block away for entities, configured distance for locations). If no floor is found, the spell will fail to cast.

      When set to false (default), the construct can be spawned in midair.

      Parameters:
      requiresFloor - true to require a floor surface, false to allow midair spawning
      Returns:
      this spell instance for method chaining
    • overlap

      public ConstructSpell<T> overlap(boolean allowOverlap)
      Sets whether multiple constructs of the same type can overlap at the same position.

      When set to false (default), the spell will check if another construct of the same type already exists at the target position before spawning. If one exists, the spell will fail to cast.

      When set to true, multiple constructs can be spawned at the same location.

      Parameters:
      allowOverlap - true to allow overlapping constructs, false to prevent them
      Returns:
      this spell instance for method chaining
    • canCastByEntity

      public boolean canCastByEntity()
      Description copied from class: Spell
      Whether 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:
      canCastByEntity in class Spell
      Returns:
      true if this spell can be cast by an entity source, false otherwise.
    • canCastByLocation

      public boolean canCastByLocation()
      Description copied from class: Spell
      Whether 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:
      canCastByLocation in class Spell
      Returns:
      true if this spell can be cast by a non-entity source, false otherwise.
    • 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.

      Specified by:
      cast in class Spell
      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 Spell
      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 Spell
      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.
    • spawnConstruct

      protected boolean spawnConstruct(CastContext ctx, net.minecraft.world.phys.Vec3 vec3, @Nullable @Nullable net.minecraft.core.Direction side)
      Spawns the construct entity in the world at the specified position.

      This method creates the construct entity using the factory, sets its position and caster, configures its lifetime, applies damage and size multipliers, and adds it to the world.

      If allowOverlap is false, this method checks for existing constructs of the same type at the target position and prevents spawning if one exists.

      This method also calls addConstructExtras(CastContext, MagicConstructEntity, Direction) to allow subclasses to apply additional modifications to the construct before spawning.

      Parameters:
      ctx - the cast context containing spell information and modifiers
      vec3 - the position where the construct should be spawned
      side - the direction the construct is facing, or null if not applicable
      Returns:
      true if the construct was successfully spawned, false if spawning was prevented (e.g., due to overlap)
    • addConstructExtras

      protected void addConstructExtras(CastContext ctx, T construct, net.minecraft.core.Direction side)
      Applies additional modifications to the construct after it has been created and configured, but before it is added to the world.

      Override this method in subclasses to apply spell-specific behavior, additional attributes, or visual effects to the construct.

      Parameters:
      ctx - the cast context containing spell information and modifiers
      construct - construct entity that has been created and configured
      side - direction the construct is facing, or null if not applicable
    • requiresPacket

      public boolean requiresPacket()
      Description copied from class: Spell
      Whether 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:
      requiresPacket in class Spell
      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

      @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.