Class ConstructSpell<T extends MagicConstructEntity>
- Type Parameters:
T- The type ofMagicConstructEntitythis spell creates.
- Direct Known Subclasses:
ArrowRain,Boulder,ConstructRangedSpell,Hailstorm,Tornado,ZombieApocalypse
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 Summary
FieldsModifier and TypeFieldDescriptionprotected booleanWhether multiple constructs of the same type can overlap at the same position.Factory function to create instances of the construct entity.protected final booleanWhether this construct is permanent (true) or has a limited lifetime (false).protected booleanWhether the construct requires a floor surface to spawn on.Fields inherited from class com.binaris.wizardry.api.content.spell.Spell
pitch, pitchVariation, volume -
Constructor Summary
ConstructorsConstructorDescriptionConstructSpell(Function<net.minecraft.world.level.Level, T> constructFactory, boolean permanent) Creates a new construct spell with the specified factory and permanence setting. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddConstructExtras(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.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.floor(boolean requiresFloor) Sets whether this spell requires a floor surface to spawn the construct on.overlap(boolean allowOverlap) Sets whether multiple constructs of the same type can overlap at the same position.protected @NotNull SpellPropertiesThis method is where you should set the default properties for your spell when creating a new spell class.booleanWhether this spell requires a packet to be sent on client when it is cast.protected booleanspawnConstruct(CastContext ctx, net.minecraft.world.phys.Vec3 vec3, @Nullable net.minecraft.core.Direction side) Spawns the construct entity in the world at the specified position.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, property, soundValues, toString
-
Field Details
-
constructFactory
protected final Function<net.minecraft.world.level.Level,T extends MagicConstructEntity> constructFactoryFactory function to create instances of the construct entity. -
permanent
protected final boolean permanentWhether this construct is permanent (true) or has a limited lifetime (false). -
requiresFloor
protected boolean requiresFloorWhether the construct requires a floor surface to spawn on. Defaults to false. -
allowOverlap
protected boolean allowOverlapWhether 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 worldpermanent- Whether the construct should be permanent (true) or temporary (false)
-
-
Method Details
-
floor
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
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: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.
-
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
allowOverlapis 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 modifiersvec3- the position where the construct should be spawnedside- 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
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 modifiersconstruct- construct entity that has been created and configuredside- direction the construct is facing, or null if not applicable
-
requiresPacket
public boolean requiresPacket()Description copied from class:SpellWhether 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:
requiresPacketin classSpell- 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
Description copied from class:SpellThis 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:
propertiesin classSpell- Returns:
- A SpellProperties object with the default properties for your spell.
-