Class BuffSpell

java.lang.Object
com.binaris.wizardry.api.content.spell.Spell
com.binaris.wizardry.content.spell.abstr.BuffSpell
Direct Known Subclasses:
CureEffects, GreaterHeal, Heal, RemoveCurse, ReplenishHunger, Satiety

public class BuffSpell extends Spell
Spell that applies mob effects to the caster. Can be cast by mobs, entities and if cast by location, it will apply the effects to the nearest entity. If the caster/selected entity already has all the effects, the spell will not be cast.

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 Details

    • r

      protected final float r
      color of the particles spawned when the spell is cast.
    • g

      protected final float g
      color of the particles spawned when the spell is cast.
    • b

      protected final float b
      color of the particles spawned when the spell is cast.
    • mobEffects

      protected Set<net.minecraft.world.effect.MobEffect> mobEffects
      set of mob effects applied by this spell.
    • particleCount

      protected float particleCount
      amount 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

      public BuffSpell particleCount(int 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: 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.
    • applyEffects

      protected boolean applyEffects(CastContext ctx, net.minecraft.world.entity.LivingEntity target)
      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

      public Set<net.minecraft.world.effect.MobEffect> 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

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