Class SpellModifiers

java.lang.Object
com.binaris.wizardry.api.content.spell.internal.SpellModifiers

public final class SpellModifiers extends Object
Glorified map for storing and saving spell modifier values such as potency, cost, chargeup and many others. This is a mutable object that is intended to be modified rather than replaced, for example, inside the SpellCastEvent.Pre you would use this object to modify specific parts of the spell ("modifiers") rather making some hacky replacement.

If you try to add a new modifier that's not on the original mod (e.g. custom wand upgrades/modifiers) make sure to mark them as needing syncing if you want the client to be aware of them and of course make the needed implementations on your spell casting code to make use of them.

  • Field Details

    • POTENCY

      public static final String POTENCY
      Constant string identifier for the potency modifier.
      See Also:
    • COST

      public static final String COST
      Constant string identifier for the mana cost modifier.
      See Also:
    • CHARGEUP

      public static final String CHARGEUP
      Constant string identifier for the wand charge-up modifier.
      See Also:
    • PROGRESSION

      public static final String PROGRESSION
      Constant string identifier for the wand progression modifier.
      See Also:
    • DURATION

      public static final String DURATION
      Constant string identifier for modifying the duration effects of spells
      See Also:
    • BLAST

      public static final String BLAST
      Constant string identifier for modifying the area effect of spells
      See Also:
    • RANGE

      public static final String RANGE
      Constant string identifier for modifying the effect range of spells
      See Also:
    • COOLDOWN

      public static final String COOLDOWN
      Constant string identifier for modifying cooldown of spells
      See Also:
  • Constructor Details

    • SpellModifiers

      public SpellModifiers()
  • Method Details

    • fromTag

      public static SpellModifiers fromTag(net.minecraft.nbt.CompoundTag tag)
      Creates a SpellModifiers instance from the given NBT tag. All entries in the tag are treated as float multipliers with their keys as the modifier identifiers.
      Parameters:
      tag - The NBT tag containing the modifier data.
      Returns:
      A SpellModifiers instance populated with the data from the tag.
    • toTag

      public net.minecraft.nbt.CompoundTag toTag()
      Converts this SpellModifiers instance to an NBT tag. All entries in the multiplier map are added to the tag as float values with their keys as the modifier identifiers.
      Returns:
      A CompoundTag containing the modifier data.
    • combine

      public SpellModifiers combine(SpellModifiers modifiers)
      Combines this SpellModifiers instance with another by multiplying their corresponding modifier values. If a modifier exists in either instance, it will be included in the result. The syncing status of each modifier is preserved if it exists in either instance.
      Parameters:
      modifiers - The other SpellModifiers instance to combine with.
      Returns:
      This SpellModifiers instance after combining.
    • set

      public SpellModifiers set(String key, float multiplier)
      Sets the multiplier for a specific upgrade identified by the given key.
      Parameters:
      key - The string identifier for the upgrade.
      multiplier - The multiplier value to set.
      Returns:
      This SpellModifiers instance after setting the multiplier.
    • add

      public SpellModifiers add(String key, float value)
      Adds the value to the given key. In case there's not already a value for this modifier it will be saved as the base.
      Parameters:
      key - The string identifier for the upgrade.
      value - The value that's going to be added to the modifier
      Returns:
      This SpellModifiers instance after setting the multiplier.
    • subtract

      public SpellModifiers subtract(String key, float value)
      Subtract the value based on the given key. In case there's not already a value for this modifier it will be saved as the base.
      Parameters:
      key - The string identifier for the upgrade.
      value - The value that's going to be subtracted to the modifier
      Returns:
      This SpellModifiers instance after setting the multiplier.
    • multiply

      public SpellModifiers multiply(String key, float factor)
      Multiply the value based on the given key. In case there's not already a value for this modifier it won't do anything.
      Parameters:
      key - The string identifier for the upgrade.
      factor - The value that's going to serve as the factor of the multiply
      Returns:
      This SpellModifiers instance after setting the multiplier.
    • divide

      public SpellModifiers divide(String key, float divisor)
      Divide the value based on the given key. In case there's not already a value for this modifier it won't do anything.
      Parameters:
      key - The string identifier for the upgrade.
      divisor - The value that's going to serve as the divisor
      Returns:
      This SpellModifiers instance after setting the multiplier.
    • get

      public float get(String key)
      Gets the multiplier for a specific upgrade identified by the given key.
      Parameters:
      key - The string identifier for the upgrade.
      Returns:
      The multiplier value for the specified upgrade, or 1 if not set.
    • getMultipliers

      public Map<String,Float> getMultipliers()
      Retrieves the complete map of all multipliers, including those that do not require syncing.
      Returns:
      A map containing all modifier identifiers and their corresponding multiplier values.
    • reset

      public void reset()
      Resets all multipliers and synced multipliers, clearing all stored values, including those that do not require syncing.
    • toString

      public String toString()
      Overrides:
      toString in class Object