Class BuffSpell
- Direct Known Subclasses:
CureEffects,GreaterHeal,Heal,RemoveCurse,ReplenishHunger,Satiety
With this you can handle easy property handling for mob effect properties, as well as standard bonus amplifier calculation based on potency modifier. You can also easily add particles and sounds to the spell by overriding the respective methods.
Check Spells.AGILITY and Heal for some examples of buff spells.
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 final floatcolor of the particles spawned when the spell is cast.protected final floatcolor of the particles spawned when the spell is cast.protected Set<net.minecraft.world.effect.MobEffect>set of mob effects applied by this spell.protected floatamount of particles spawned when the spell is cast.protected final floatcolor of the particles spawned when the spell is cast.Fields inherited from class com.binaris.wizardry.api.content.spell.Spell
pitch, pitchVariation, volume -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanapplyEffects(CastContext ctx, net.minecraft.world.entity.LivingEntity target) Applies the mob effects to the target.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.static SpellProperty<Integer>getEffectDurationProperty(net.minecraft.world.effect.MobEffect effect) Utility method to get the spell property for the duration of a mob effect.static SpellProperty<Integer>getEffectStrengthProperty(net.minecraft.world.effect.MobEffect effect) Utility method to get the spell property for the strength of a mob effect.Set<net.minecraft.world.effect.MobEffect>Gets the set of mob effects applied by this spell.static intgetStandardBonusAmplifier(float potencyModifier) Calculates the standard bonus amplifier based on the potency modifier.particleCount(int particleCount) Sets the amount of particles spawned when the spell is cast.protected @NotNull SpellPropertiesThis method is where you should set the default properties for your spell when creating a new spell class.protected voidspawnParticles(net.minecraft.world.level.Level world, net.minecraft.world.entity.LivingEntity target) Spawns particles when the spell is cast.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, requiresPacket, soundValues, toString
-
Field Details
-
r
protected final float rcolor of the particles spawned when the spell is cast. -
g
protected final float gcolor of the particles spawned when the spell is cast. -
b
protected final float bcolor of the particles spawned when the spell is cast. -
mobEffects
set of mob effects applied by this spell. -
particleCount
protected float particleCountamount of particles spawned when the spell is cast.
-
-
Constructor Details
-
BuffSpell
@SafeVarargs public BuffSpell(float r, float g, float b, Supplier<net.minecraft.world.effect.MobEffect>... effects)
-
-
Method Details
-
particleCount
Sets the amount of particles spawned when the spell is cast. Default is 10.- Parameters:
particleCount- the amount of particles spawned when the spell is cast- Returns:
- this spell, for 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.
-
applyEffects
Applies the mob effects to the target. The duration and amplifier of the effects are calculated based on the spell properties and the potency and duration modifiers of the cast context.- Parameters:
ctx- the cast context of the spell, used to get the modifiers for duration and potency, as well as the world for applying the effects.target- the target of the spell, the entity that is going to receive the mob effects. Normally the caster, but if the spell is cast by location, it will be the nearest entity to the selected location.- Returns:
- true if the effects were applied, false if the target already had all the effects or if there was an error applying the effects.
-
spawnParticles
protected void spawnParticles(net.minecraft.world.level.Level world, net.minecraft.world.entity.LivingEntity target) Spawns particles when the spell is cast. By default, it spawns some sparkle particles around the target and a buff particle on the target. You can override this method to spawn different particles or to change the way the particles are spawned. The color of the particles is determined by the r,g,b fields of the spell, which are set in the constructor. The amount of particles spawned is determined by the particleCount field, which can be set using the particleCount() method.Note that this method is only called on the client side.
- Parameters:
world- the world where the particles are going to be spawned, used to spawn the particles.target- the entity that is going to be the center of the particles, normally the caster of the spell, but if the spell is cast by location, it will be the nearest entity to the selected location.
-
getStandardBonusAmplifier
public static int getStandardBonusAmplifier(float potencyModifier) Calculates the standard bonus amplifier based on the potency modifier. The formula is (potencyModifier - 1) / 0.4, which means that for every 0.4 increase in potency modifier, the amplifier increases by 1. For example, if the potency modifier is 1.4, the bonus amplifier will be 1, if the potency modifier is 1.8, the bonus amplifier will be 2, and so on.- Parameters:
potencyModifier- the potency modifier of the cast context, used to calculate the bonus amplifier.- Returns:
- the bonus amplifier calculated based on the potency modifier.
-
getEffectDurationProperty
public static SpellProperty<Integer> getEffectDurationProperty(net.minecraft.world.effect.MobEffect effect) Utility method to get the spell property for the duration of a mob effect. The property name is the description id of the effect followed by "_duration". For example, if the effect is "minecraft:speed", the property name will be 'effect.minecraft.speed_duration'.Used to easily get the properties for the duration of the mob effects applied by this spell. You must use this method to get the properties for the duration of the mob effects.
- Parameters:
effect- the mob effect for which to get the duration property, used to generate the property name.- Returns:
- the spell property for the duration of the given mob effect.
-
getEffectStrengthProperty
public static SpellProperty<Integer> getEffectStrengthProperty(net.minecraft.world.effect.MobEffect effect) Utility method to get the spell property for the strength of a mob effect. The property name is the description id of the effect followed by "_strength". For example, if the effect is "minecraft:speed", the property name will be 'effect.minecraft.speed_strength'.Used to easily get the properties for the strength of the mob effects applied by this spell. You must use this method to get the properties for the strength of the mob effects.
- Parameters:
effect- the mob effect for which to get the strength property, used to generate the property name.- Returns:
- the spell property for the strength of the given mob effect.
-
getMobEffects
Gets the set of mob effects applied by this spell. Used to check if the target already has all the effects before applying them.- Returns:
- the set of mob effects applied by this spell.
-
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.
-