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.

It also keeps track of which modifiers need to be synced to the client, so that only those are sent over the network.

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 Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Constant string identifier for the wand charge-up modifier.
    static final String
    Constant string identifier for the mana cost modifier.
    static final String
    Constant string identifier for the potency modifier.
    static final String
    Constant string identifier for the wand progression modifier.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Combines this SpellModifiers instance with another by multiplying their corresponding modifier values.
    fromTag(net.minecraft.nbt.CompoundTag tag)
    Creates a SpellModifiers instance from the given NBT tag.
    float
    get(String key)
    Gets the multiplier for a specific upgrade identified by the given key.
    float
    get(net.minecraft.world.item.Item upgrade)
    Gets the multiplier for a specific upgrade identified by the given item.
    Retrieves the complete map of all multipliers, including those that do not require syncing.
    Retrieves the map of multipliers that need to be synced to the client.
    void
    Resets all multipliers and synced multipliers, clearing all stored values, including those that do not require syncing.
    set(String key, float multiplier, boolean needsSyncing)
    Sets the multiplier for a specific upgrade identified by the given key, along with its syncing status.
    set(net.minecraft.world.item.Item upgrade, float multiplier, boolean needsSyncing)
    Sets the multiplier for a specific upgrade identified by the given item, along with its syncing status.
    net.minecraft.nbt.CompoundTag
    Converts this SpellModifiers instance to an NBT tag.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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:
  • 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(net.minecraft.world.item.Item upgrade, float multiplier, boolean needsSyncing)
      Sets the multiplier for a specific upgrade identified by the given item, along with its syncing status. The item is converted to its string identifier using WandUpgrades.getIdentifier(Item) in order to store the multiplier.
      Parameters:
      upgrade - The item representing the upgrade.
      multiplier - The multiplier value to set.
      needsSyncing - Whether this modifier needs to be synced to the client.
      Returns:
      This SpellModifiers instance after setting the multiplier.
    • set

      public SpellModifiers set(String key, float multiplier, boolean needsSyncing)
      Sets the multiplier for a specific upgrade identified by the given key, along with its syncing status.
      Parameters:
      key - The string identifier for the upgrade.
      multiplier - The multiplier value to set.
      needsSyncing - Whether this modifier needs to be synced to the client.
      Returns:
      This SpellModifiers instance after setting the multiplier.
    • get

      public float get(net.minecraft.world.item.Item upgrade)
      Gets the multiplier for a specific upgrade identified by the given item. The item is converted to its string identifier using WandUpgrades.getIdentifier(Item) in order to retrieve the multiplier.
      Parameters:
      upgrade - The item representing the upgrade.
      Returns:
      The multiplier value for the specified upgrade, or 1 if not set.
    • 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.
    • getSyncedMultipliers

      public Map<String,Float> getSyncedMultipliers()
      Retrieves the map of multipliers that need to be synced to the client.
      Returns:
      A map containing modifier identifiers and their corresponding multiplier values that require syncing.
    • reset

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