Class CastItemDataHelper
java.lang.Object
com.binaris.wizardry.api.content.util.CastItemDataHelper
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 stringResourceLocationss. - 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
FieldsModifier and TypeFieldDescriptionstatic final StringThe 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 StringThe 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 StringThe NBT key used to store the item progression level in form of an integer.static final StringThe NBT key used to store the currently selected spell index on the item in form of an integer.static final StringThe NBT key used to store the array of spells on the item in form ofResourceLocation.static final StringThe NBT key used to store the item upgrades in form of an array of integers. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddProgression(net.minecraft.world.item.ItemStack stack, int progression) Increases the stack's progression level by the specified amount.static voidapplyUpgrade(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 intgetCurrentCooldown(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 intgetCurrentMaxCooldown(net.minecraft.world.item.ItemStack stack) Gives the maximum cooldown for the currently selected spell on the stack.static SpellgetCurrentSpell(net.minecraft.world.item.ItemStack stack) Gives the currently selected spell on the stack.static intgetCurrentSpellIndex(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 SpellgetNextSpell(net.minecraft.world.item.ItemStack stack) Gives the next spell in the stack's spell list, wrapping around to the start if necessary.static SpellgetPreviousSpell(net.minecraft.world.item.ItemStack stack) Returns the previous spell in the stack's spell list, wrapping around to the end if necessary.static intgetProgression(net.minecraft.world.item.ItemStack stack) Returns the stack's current progression level.getSpells(net.minecraft.world.item.ItemStack stack) Gives the list of spells stored on the stack.static intgetTotalUpgrades(net.minecraft.world.item.ItemStack stack) Gives the total number of upgrades applied to the stack.static intgetUpgradeLevel(net.minecraft.world.item.ItemStack stack, net.minecraft.world.item.Item upgrade) Gives the level of the specified upgrade on the stack.static voidselectNextSpell(net.minecraft.world.item.ItemStack stack) Selects the next spell on the stack by incrementing the index, wrapping around if necessary.static voidselectPreviousSpell(net.minecraft.world.item.ItemStack stack) Selects the previous spell on the stack by decrementing the index, wrapping around if necessary.static voidsetCooldownEndTimes(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 voidsetCurrentCooldown(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 booleansetCurrentSpell(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 voidsetCurrentSpell(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 voidsetMaxCooldowns(net.minecraft.world.item.ItemStack stack, int[] cooldowns) Sets the array of maximum cooldowns for each spell on the stack.static voidsetProgression(net.minecraft.world.item.ItemStack stack, int progression) Sets the stack's progression level to the specified value.static voidsetSpells(net.minecraft.world.item.ItemStack stack, Collection<Spell> spells) Sets the list of spells on the stack's tag.
-
Field Details
-
SPELL_ARRAY_KEY
The NBT key used to store the array of spells on the item in form ofResourceLocation.- See Also:
-
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
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
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
The NBT key used to store the item upgrades in form of an array of integers.- See Also:
-
PROGRESSION_KEY
The NBT key used to store the item progression level in form of an integer.- See Also:
-
-
Method Details
-
getSpells
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 withSpells.NONEto reach the maximum size.- Parameters:
stack- The ItemStack.- Returns:
- A list of spells on the item, padded with
Spells.NONEif necessary. If the item has no tag, an empty list is returned.
-
setSpells
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
Gives the currently selected spell on the stack.- Parameters:
stack- The ItemStack.- Returns:
- The currently selected spell, or
Spells.NONEif 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
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
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
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.
-