Class WandHelper

java.lang.Object
com.binaris.wizardry.api.content.util.WandHelper

public final class WandHelper extends Object
For avoiding a big and messy WandItem class (and helping addon devs by providing an API a similar way to use the wand NBT structure). This class provides static methods for getting and setting wand-related data on wand ItemStacks.

Wand data is stored in the wand's NBT as follows:

  • A list of spells under the key SPELL_ARRAY_KEY, stored as a list of string ResourceLocations.
  • The currently selected spell index under the key SELECTED_SPELL_KEY, stored as an integer.
  • An array of longs under the key COOLDOWN_END_TIME_ARRAY_KEY, storing the gametime when each spell's cooldown ends.
  • An array of integers under the key MAX_COOLDOWN_ARRAY_KEY, storing the maximum cooldown for each spell slot.
  • A compound tag under the key UPGRADES_KEY, storing the levels of each upgrade.
  • An integer under the key PROGRESSION_KEY, storing the wand's progression level.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The NBT key used to store the array of cooldown end times (gametime) for each spell on the wand.
    static final String
    The NBT key used to store the array of maximum cooldowns for each spell on the wand.
    static final String
    The NBT key used to store the wand progression level.
    static final String
    The NBT key used to store the currently selected spell index on the wand.
    static final String
    The NBT key used to store the array of spells on the wand.
    static final String
    The NBT key used to store the wand upgrades.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    addProgression(net.minecraft.world.item.ItemStack wand, int progression)
    Increases the wand's progression level by the specified amount.
    static void
    applyUpgrade(net.minecraft.world.item.ItemStack wand, net.minecraft.world.item.Item upgrade)
    Applies the specified upgrade to the wand, increasing its level by 1.
    calculateModifiers(net.minecraft.world.item.ItemStack stack, net.minecraft.world.entity.player.Player player, Spell spell)
    Calculates the spell modifiers provided by the wand for the given spell and player.
    static long[]
    getCooldownEndTimes(net.minecraft.world.item.ItemStack wand)
    Returns the array of cooldown end times (gametime) for each spell on the wand.
    static int
    getCurrentCooldown(net.minecraft.world.item.ItemStack wand, long currentGameTime)
    Returns the current cooldown for the currently selected spell on the wand based on gametime.
    static int
    getCurrentMaxCooldown(net.minecraft.world.item.ItemStack wand)
    Returns the maximum cooldown for the currently selected spell on the wand.
    static Spell
    getCurrentSpell(net.minecraft.world.item.ItemStack wand)
    Returns the currently selected spell on the wand.
    static int
    getCurrentSpellIndex(net.minecraft.world.item.ItemStack wand)
     
    static int
    getDistributedCost(int cost, int castingTick)
    Calculates the distributed cost of a spell being cast over multiple ticks.
    static int[]
    getMaxCooldowns(net.minecraft.world.item.ItemStack wand)
    Returns the array of maximum cooldowns for each spell on the wand.
    static Spell
    getNextSpell(net.minecraft.world.item.ItemStack wand)
    Returns the next spell in the wand's spell list, wrapping around to the start if necessary.
    static Spell
    getPreviousSpell(net.minecraft.world.item.ItemStack wand)
    Returns the previous spell in the wand's spell list, wrapping around to the end if necessary.
    static int
    getProgression(net.minecraft.world.item.ItemStack wand)
    Returns the wand's current progression level.
    static List<Spell>
    getSpells(net.minecraft.world.item.ItemStack wand)
    Returns the list of spells stored on the wand.
    static int
    getTotalUpgrades(net.minecraft.world.item.ItemStack wand)
    Returns the total number of upgrades applied to the wand.
    static int
    getUpgradeLevel(net.minecraft.world.item.ItemStack wand, net.minecraft.world.item.Item upgrade)
    Returns the level of the specified upgrade on the wand.
    static void
    selectNextSpell(net.minecraft.world.item.ItemStack wand)
    Selects the next spell on the wand by incrementing the index, wrapping around if necessary.
    static void
    selectPreviousSpell(net.minecraft.world.item.ItemStack wand)
    Selects the previous spell on the wand by decrementing the index, wrapping around if necessary.
    static void
    setCooldownEndTimes(net.minecraft.world.item.ItemStack wand, long[] cooldownEndTimes)
    Sets the array of cooldown end times (gametime) for each spell on the wand.
    static void
    setCurrentCooldown(net.minecraft.world.item.ItemStack wand, int cooldown, long currentGameTime)
    Sets the cooldown for the currently selected spell on the wand using gametime.
    static boolean
    setCurrentSpell(net.minecraft.world.item.ItemStack wand, int index)
    Sets the currently selected spell on the wand by index.
    static void
    setCurrentSpell(net.minecraft.world.item.ItemStack wand, Spell spell)
    Sets the currently selected spell on the wand by finding its index.
    static void
    setMaxCooldowns(net.minecraft.world.item.ItemStack wand, int[] cooldowns)
    Sets the array of maximum cooldowns for each spell on the wand.
    static void
    setProgression(net.minecraft.world.item.ItemStack wand, int progression)
    Sets the wand's progression level to the specified value.
    static void
    setSpells(net.minecraft.world.item.ItemStack wand, Collection<Spell> spells)
    Sets the list of spells on the wand.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • SPELL_ARRAY_KEY

      public static final String SPELL_ARRAY_KEY
      The NBT key used to store the array of spells on the wand.
      See Also:
    • SELECTED_SPELL_KEY

      public static final String SELECTED_SPELL_KEY
      The NBT key used to store the currently selected spell index on the wand.
      See Also:
    • COOLDOWN_END_TIME_ARRAY_KEY

      public static final String COOLDOWN_END_TIME_ARRAY_KEY
      The NBT key used to store the array of cooldown end times (gametime) for each spell on the wand.
      See Also:
    • MAX_COOLDOWN_ARRAY_KEY

      public static final String MAX_COOLDOWN_ARRAY_KEY
      The NBT key used to store the array of maximum cooldowns for each spell on the wand.
      See Also:
    • UPGRADES_KEY

      public static final String UPGRADES_KEY
      The NBT key used to store the wand upgrades.
      See Also:
    • PROGRESSION_KEY

      public static final String PROGRESSION_KEY
      The NBT key used to store the wand progression level.
      See Also:
  • Method Details

    • getSpells

      public static List<Spell> getSpells(net.minecraft.world.item.ItemStack wand)
      Returns the list of spells stored on the wand. If there are fewer spells stored than the wand's maximum spell slots, the list is padded with Spells.NONE to reach the maximum size.
      Parameters:
      wand - The wand ItemStack.
      Returns:
      A list of spells on the wand.
    • setSpells

      public static void setSpells(net.minecraft.world.item.ItemStack wand, Collection<Spell> spells)
      Sets the list of spells on the wand.
      Parameters:
      wand - The wand ItemStack.
      spells - The collection of spells to set on the wand.
    • getCurrentSpell

      public static Spell getCurrentSpell(net.minecraft.world.item.ItemStack wand)
      Returns the currently selected spell on the wand.
      Parameters:
      wand - The wand ItemStack.
      Returns:
      The currently selected spell.
    • getCurrentSpellIndex

      public static int getCurrentSpellIndex(net.minecraft.world.item.ItemStack wand)
    • setCurrentSpell

      public static void setCurrentSpell(net.minecraft.world.item.ItemStack wand, Spell spell)
      Sets the currently selected spell on the wand by finding its index.
      Parameters:
      wand - The wand ItemStack.
      spell - The spell to set as currently selected.
    • setCurrentSpell

      public static boolean setCurrentSpell(net.minecraft.world.item.ItemStack wand, int index)
      Sets the currently selected spell on the wand by index.
      Parameters:
      wand - The wand ItemStack.
      index - The index of the spell to set as currently selected.
      Returns:
      True if the index was valid and the spell was set, false otherwise.
    • getNextSpell

      public static Spell getNextSpell(net.minecraft.world.item.ItemStack wand)
      Returns the next spell in the wand's spell list, wrapping around to the start if necessary.
      Parameters:
      wand - The wand ItemStack.
      Returns:
      The next spell.
    • getPreviousSpell

      public static Spell getPreviousSpell(net.minecraft.world.item.ItemStack wand)
      Returns the previous spell in the wand's spell list, wrapping around to the end if necessary.
      Parameters:
      wand - The wand ItemStack.
      Returns:
      The previous spell.
    • selectNextSpell

      public static void selectNextSpell(net.minecraft.world.item.ItemStack wand)
      Selects the next spell on the wand by incrementing the index, wrapping around if necessary. This method directly manipulates indices to avoid issues with duplicate spells (e.g., multiple NONE spells).
      Parameters:
      wand - The wand ItemStack.
    • selectPreviousSpell

      public static void selectPreviousSpell(net.minecraft.world.item.ItemStack wand)
      Selects the previous spell on the wand by decrementing the index, wrapping around if necessary. This method directly manipulates indices to avoid issues with duplicate spells (e.g., multiple NONE spells).
      Parameters:
      wand - The wand ItemStack.
    • getCooldownEndTimes

      public static long[] getCooldownEndTimes(net.minecraft.world.item.ItemStack wand)
      Returns the array of cooldown end times (gametime) for each spell on the wand.
      Parameters:
      wand - The wand ItemStack.
      Returns:
      An array of cooldown end times.
    • setCooldownEndTimes

      public static void setCooldownEndTimes(net.minecraft.world.item.ItemStack wand, long[] cooldownEndTimes)
      Sets the array of cooldown end times (gametime) for each spell on the wand.
      Parameters:
      wand - The wand ItemStack.
      cooldownEndTimes - The array of cooldown end times to set.
    • getCurrentCooldown

      public static int getCurrentCooldown(net.minecraft.world.item.ItemStack wand, long currentGameTime)
      Returns the current cooldown for the currently selected spell on the wand based on gametime.
      Parameters:
      wand - The wand ItemStack.
      currentGameTime - The current game time from the world.
      Returns:
      The current cooldown remaining for the selected spell.
    • setCurrentCooldown

      public static void setCurrentCooldown(net.minecraft.world.item.ItemStack wand, int cooldown, long currentGameTime)
      Sets the cooldown for the currently selected spell on the wand using gametime.
      Parameters:
      wand - The wand ItemStack.
      cooldown - The cooldown duration in ticks.
      currentGameTime - The current game time from the world.
    • getMaxCooldowns

      public static int[] getMaxCooldowns(net.minecraft.world.item.ItemStack wand)
      Returns the array of maximum cooldowns for each spell on the wand.
      Parameters:
      wand - The wand ItemStack.
      Returns:
      An array of maximum cooldowns.
    • setMaxCooldowns

      public static void setMaxCooldowns(net.minecraft.world.item.ItemStack wand, int[] cooldowns)
      Sets the array of maximum cooldowns for each spell on the wand.
      Parameters:
      wand - The wand ItemStack.
      cooldowns - The array of maximum cooldowns to set.
    • getCurrentMaxCooldown

      public static int getCurrentMaxCooldown(net.minecraft.world.item.ItemStack wand)
      Returns the maximum cooldown for the currently selected spell on the wand.
      Parameters:
      wand - The wand ItemStack.
      Returns:
      The maximum cooldown for the selected spell, or 0 if not set.
    • getUpgradeLevel

      public static int getUpgradeLevel(net.minecraft.world.item.ItemStack wand, net.minecraft.world.item.Item upgrade)
      Returns the level of the specified upgrade on the wand.
      Parameters:
      wand - The wand ItemStack.
      upgrade - The upgrade item.
      Returns:
      The level of the upgrade, or 0 if the upgrade is not found.
    • getTotalUpgrades

      public static int getTotalUpgrades(net.minecraft.world.item.ItemStack wand)
      Returns the total number of upgrades applied to the wand.
      Parameters:
      wand - The wand ItemStack.
      Returns:
      The total number of upgrades, could be zero if no upgrades are applied.
    • applyUpgrade

      public static void applyUpgrade(net.minecraft.world.item.ItemStack wand, net.minecraft.world.item.Item upgrade)
      Applies the specified upgrade to the wand, increasing its level by 1.
      Parameters:
      wand - The wand ItemStack.
      upgrade - The upgrade item.
    • getProgression

      public static int getProgression(net.minecraft.world.item.ItemStack wand)
      Returns the wand's current progression level.
      Parameters:
      wand - The wand ItemStack.
      Returns:
      The wand's progression level.
    • setProgression

      public static void setProgression(net.minecraft.world.item.ItemStack wand, int progression)
      Sets the wand's progression level to the specified value.
      Parameters:
      wand - The wand ItemStack.
      progression - The progression level to set.
    • addProgression

      public static void addProgression(net.minecraft.world.item.ItemStack wand, int progression)
      Increases the wand's progression level by the specified amount.
      Parameters:
      wand - The wand ItemStack.
      progression - The amount to increase the progression level by.
    • getDistributedCost

      public static int getDistributedCost(int cost, int castingTick)
      Calculates the distributed cost of a spell being cast over multiple ticks.

      The cost is halved at 10 ticks and again at 20 ticks, with any remainder added to the first half.

      Parameters:
      cost - The total cost of the spell.
      castingTick - The current tick of casting.
      Returns:
      The distributed cost for the current tick.
    • calculateModifiers

      public static SpellModifiers calculateModifiers(net.minecraft.world.item.ItemStack stack, net.minecraft.world.entity.player.Player player, Spell spell)
      Calculates the spell modifiers provided by the wand for the given spell and player.
      Parameters:
      stack - The wand ItemStack.
      player - The player casting the spell.
      spell - The spell being cast.
      Returns:
      The calculated spell modifiers.