Class CastItemDataHelper

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

public final class CastItemDataHelper extends Object
This class avoids big classes just to handle NBT data for getting/saving values.

Data is stored in the NBT as follows:

  • A list of spells under the key SPELL_ARRAY_KEY, stored as a list of string ResourceLocationss.
  • 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 game time 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 item'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 (game time) for each spell on the item in form of an array of longs.
    static final String
    The NBT key used to store the array of maximum cooldowns for each spell on the item in form of an array of longs.
    static final String
    The NBT key used to store the item progression level in form of an integer.
    static final String
    The NBT key used to store the currently selected spell index on the item in form of an integer.
    static final String
    The NBT key used to store the array of spells on the item in form of ResourceLocation.
    static final String
    The NBT key used to store the item upgrades in form of an array of integers.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    addProgression(net.minecraft.world.item.ItemStack stack, int progression)
    Increases the stack's progression level by the specified amount.
    static void
    applyUpgrade(net.minecraft.world.item.ItemStack stack, net.minecraft.world.item.Item upgrade)
    Applies the specified upgrade to the stack, increasing its level by 1 each time.
    static long[]
    getCooldownEndTimes(net.minecraft.world.item.ItemStack stack)
    Gives the array of cooldown end times (level game time) for each spell on the stack.
    static int
    getCurrentCooldown(net.minecraft.world.item.ItemStack stack, long currentGameTime)
    Gives the current cooldown for the currently selected spell on the stack based on game time.
    static int
    getCurrentMaxCooldown(net.minecraft.world.item.ItemStack stack)
    Gives the maximum cooldown for the currently selected spell on the stack.
    static Spell
    getCurrentSpell(net.minecraft.world.item.ItemStack stack)
    Gives the currently selected spell on the stack.
    static int
    getCurrentSpellIndex(net.minecraft.world.item.ItemStack stack)
    Gives the index of the current spell selected by the stack.
    static int[]
    getMaxCooldowns(net.minecraft.world.item.ItemStack stack)
    Gives the array of maximum cooldowns for each spell on the stack.
    static Spell
    getNextSpell(net.minecraft.world.item.ItemStack stack)
    Gives the next spell in the stack's spell list, wrapping around to the start if necessary.
    static Spell
    getPreviousSpell(net.minecraft.world.item.ItemStack stack)
    Returns the previous spell in the stack's spell list, wrapping around to the end if necessary.
    static int
    getProgression(net.minecraft.world.item.ItemStack stack)
    Returns the stack's current progression level.
    static List<Spell>
    getSpells(net.minecraft.world.item.ItemStack stack)
    Gives the list of spells stored on the stack.
    static int
    getTotalUpgrades(net.minecraft.world.item.ItemStack stack)
    Gives the total number of upgrades applied to the stack.
    static int
    getUpgradeLevel(net.minecraft.world.item.ItemStack stack, net.minecraft.world.item.Item upgrade)
    Gives the level of the specified upgrade on the stack.
    static void
    selectNextSpell(net.minecraft.world.item.ItemStack stack)
    Selects the next spell on the stack by incrementing the index, wrapping around if necessary.
    static void
    selectPreviousSpell(net.minecraft.world.item.ItemStack stack)
    Selects the previous spell on the stack by decrementing the index, wrapping around if necessary.
    static void
    setCooldownEndTimes(net.minecraft.world.item.ItemStack stack, long[] cooldownEndTimes)
    Sets the array of cooldown end times (level game time) for each spell on the stack.
    static void
    setCurrentCooldown(net.minecraft.world.item.ItemStack stack, int cooldown, long currentGameTime)
    Sets the cooldown for the currently selected spell on the stack using game time.
    static boolean
    setCurrentSpell(net.minecraft.world.item.ItemStack stack, int index)
    Sets the currently selected spell on the stack by index based on the list of saved spells.
    static void
    setCurrentSpell(net.minecraft.world.item.ItemStack stack, Spell spell)
    Sets the currently selected spell on the stack based on its location in the list of saved spells.
    static void
    setMaxCooldowns(net.minecraft.world.item.ItemStack stack, int[] cooldowns)
    Sets the array of maximum cooldowns for each spell on the stack.
    static void
    setProgression(net.minecraft.world.item.ItemStack stack, int progression)
    Sets the stack's progression level to the specified value.
    static void
    setSpells(net.minecraft.world.item.ItemStack stack, Collection<Spell> spells)
    Sets the list of spells on the stack's tag.

    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 item in form of ResourceLocation.
      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 item in form of an integer.
      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 (game time) for each spell on the item in form of an array of longs.
      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 item in form of an array of longs.
      See Also:
    • UPGRADES_KEY

      public static final String UPGRADES_KEY
      The NBT key used to store the item upgrades in form of an array of integers.
      See Also:
    • PROGRESSION_KEY

      public static final String PROGRESSION_KEY
      The NBT key used to store the item progression level in form of an integer.
      See Also:
  • Method Details

    • getSpells

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

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

      public static Spell getCurrentSpell(net.minecraft.world.item.ItemStack stack)
      Gives the currently selected spell on the stack.
      Parameters:
      stack - The ItemStack.
      Returns:
      The currently selected spell, or Spells.NONE if the stack has no tag or no spells are stored/selected.
    • getCurrentSpellIndex

      public static int getCurrentSpellIndex(net.minecraft.world.item.ItemStack stack)
      Gives the index of the current spell selected by the stack.
      Parameters:
      stack - The ItemStack.
      Returns:
      The index of the currently selected spell, or 0 if the stack has no tag or no spells are stored/selected.
    • setCurrentSpell

      public static void setCurrentSpell(net.minecraft.world.item.ItemStack stack, Spell spell)
      Sets the currently selected spell on the stack based on its location in the list of saved spells.
      Parameters:
      stack - The ItemStack.
      spell - The spell to set as currently selected. If the spell is not in the list, the first spell is selected.
    • setCurrentSpell

      public static boolean setCurrentSpell(net.minecraft.world.item.ItemStack stack, int index)
      Sets the currently selected spell on the stack by index based on the list of saved spells.
      Parameters:
      stack - The 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 stack)
      Gives the next spell in the stack's spell list, wrapping around to the start if necessary.
      Parameters:
      stack - The ItemStack.
      Returns:
      The next spell in the list based on the currently selected spell.
    • getPreviousSpell

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

      public static void selectNextSpell(net.minecraft.world.item.ItemStack stack)
      Selects the next spell on the stack 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:
      stack - The ItemStack.
    • selectPreviousSpell

      public static void selectPreviousSpell(net.minecraft.world.item.ItemStack stack)
      Selects the previous spell on the stack 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:
      stack - The ItemStack.
    • getCooldownEndTimes

      public static long[] getCooldownEndTimes(net.minecraft.world.item.ItemStack stack)
      Gives the array of cooldown end times (level game time) for each spell on the stack.
      Parameters:
      stack - The ItemStack.
      Returns:
      An array of cooldown end times. If the tag is null or empty, returns an empty array.
    • setCooldownEndTimes

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

      public static int getCurrentCooldown(net.minecraft.world.item.ItemStack stack, long currentGameTime)
      Gives the current cooldown for the currently selected spell on the stack based on game time.
      Parameters:
      stack - The ItemStack.
      currentGameTime - The current game time from the world.
      Returns:
      The current cooldown remaining for the selected spell. If the tag is null or empty, returns 0.
    • setCurrentCooldown

      public static void setCurrentCooldown(net.minecraft.world.item.ItemStack stack, int cooldown, long currentGameTime)
      Sets the cooldown for the currently selected spell on the stack using game time.
      Parameters:
      stack - The 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 stack)
      Gives the array of maximum cooldowns for each spell on the stack.
      Parameters:
      stack - The ItemStack.
      Returns:
      An array of maximum cooldowns, or an empty array if the tag is null or empty.
    • setMaxCooldowns

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

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

      public static int getUpgradeLevel(net.minecraft.world.item.ItemStack stack, net.minecraft.world.item.Item upgrade)
      Gives the level of the specified upgrade on the stack.
      Parameters:
      stack - The 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 stack)
      Gives the total number of upgrades applied to the stack.
      Parameters:
      stack - The ItemStack.
      Returns:
      The total number of upgrades, could be 0 if no upgrades are applied.
    • applyUpgrade

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

      public static int getProgression(net.minecraft.world.item.ItemStack stack)
      Returns the stack's current progression level.
      Parameters:
      stack - The ItemStack.
      Returns:
      The stack's progression level. If the tag is null or empty, returns 0.
    • setProgression

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

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