diff --git a/src/main/java/electroblob/wizardry/client/gui/GuiSpellDisplay.java b/src/main/java/electroblob/wizardry/client/gui/GuiSpellDisplay.java
index 265a9129..04cdc513 100644
--- a/src/main/java/electroblob/wizardry/client/gui/GuiSpellDisplay.java
+++ b/src/main/java/electroblob/wizardry/client/gui/GuiSpellDisplay.java
@@ -15,7 +15,6 @@ import electroblob.wizardry.registry.Spells;
import electroblob.wizardry.registry.WizardryPotions;
import electroblob.wizardry.spell.Spell;
import electroblob.wizardry.util.SpellModifiers;
-import electroblob.wizardry.util.WandHelper;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.GlStateManager;
@@ -156,7 +155,9 @@ public class GuiSpellDisplay {
if(Minecraft.getMinecraft().gameSettings.showDebugInfo) return; // Don't show charge meter in the debug screen
if(Minecraft.getMinecraft().gameSettings.thirdPersonView != 0) return; // Don't show in third person
- Spell spell = WandHelper.getCurrentSpell(wand);
+ if(!(wand.getItem() instanceof ISpellCastingItem)) throw new IllegalArgumentException("The given stack must contain an ISpellCastingItem!");
+
+ Spell spell = ((ISpellCastingItem)wand.getItem()).getCurrentSpell(wand);
int chargeup = spell.getChargeup();
@@ -199,6 +200,8 @@ public class GuiSpellDisplay {
if(!Wizardry.settings.showSpellHUD) return;
+ if(!(wand.getItem() instanceof ISpellCastingItem)) throw new IllegalArgumentException("The given stack must contain an ISpellCastingItem!");
+
boolean flipX = Wizardry.settings.spellHUDPosition.flipX;
boolean flipY = Wizardry.settings.spellHUDPosition.flipY;
@@ -245,19 +248,18 @@ public class GuiSpellDisplay {
y = MathHelper.ceil(y/scale);
}
- // TODO: Maybe convert this to use ISpellCastingItem
- Spell spell = WandHelper.getCurrentSpell(wand);
- int cooldown = WandHelper.getCurrentCooldown(wand);
- int maxCooldown = WandHelper.getCurrentMaxCooldown(wand);
+ Spell spell = ((ISpellCastingItem)wand.getItem()).getCurrentSpell(wand);
+ int cooldown = ((ISpellCastingItem)wand.getItem()).getCurrentCooldown(wand);
+ int maxCooldown = ((ISpellCastingItem)wand.getItem()).getCurrentMaxCooldown(wand);
if(textLayer){
float animationProgress = Math.signum(switchTimer) * ((SPELL_SWITCH_TIME - Math.abs(switchTimer) +
partialTicks) / SPELL_SWITCH_TIME);
- String prevSpellName = getFormattedSpellName(WandHelper.getPreviousSpell(wand), player, WandHelper.getPreviousCooldown(wand));
+ String prevSpellName = getFormattedSpellName(((ISpellCastingItem)wand.getItem()).getPreviousSpell(wand), player, 0);
String spellName = getFormattedSpellName(spell, player, cooldown);
- String nextSpellName = getFormattedSpellName(WandHelper.getNextSpell(wand), player, WandHelper.getNextCooldown(wand));
+ String nextSpellName = getFormattedSpellName(((ISpellCastingItem)wand.getItem()).getNextSpell(wand), player, 0);
skin.drawText(x, y, flipX, flipY, prevSpellName, spellName, nextSpellName, animationProgress);
diff --git a/src/main/java/electroblob/wizardry/item/ISpellCastingItem.java b/src/main/java/electroblob/wizardry/item/ISpellCastingItem.java
index ebac96e5..7a595919 100644
--- a/src/main/java/electroblob/wizardry/item/ISpellCastingItem.java
+++ b/src/main/java/electroblob/wizardry/item/ISpellCastingItem.java
@@ -21,7 +21,7 @@ import javax.annotation.Nonnull;
* This interface is used for the following:
* - General-purpose detection of continuous spell casting (see {@link EntityUtils#isCasting(EntityLivingBase, Spell)})
* - Display of the arcane workbench tooltip (in conjunction with {@link IManaStoringItem})
- * - Spell HUD visibility
+ * - Supplying information to the spell HUD
* - Spell switching controls (they won't do anything unless the player is holding an {@code ISpellCastingItem})
* - Artefacts that trigger a player's wands/scrolls to cast spells
* @author Electroblob
@@ -40,6 +40,28 @@ public interface ISpellCastingItem {
@Nonnull
Spell getCurrentSpell(ItemStack stack);
+ /**
+ * Returns the spell equipped in the next slot on the given itemstack. The given itemstack will be of this item.
+ * @param stack The itemstack to query.
+ * @return The next spell, or {@link electroblob.wizardry.registry.Spells#none Spells.none} if no spell is equipped
+ * in the next slot. Returns the current spell by default (useful for items with only one spell).
+ */
+ @Nonnull
+ default Spell getNextSpell(ItemStack stack){
+ return getCurrentSpell(stack);
+ }
+
+ /**
+ * Returns the spell equipped in the previous slot on the given itemstack. The given itemstack will be of this item.
+ * @param stack The itemstack to query.
+ * @return The previous spell, or {@link electroblob.wizardry.registry.Spells#none Spells.none} if no spell is
+ * equipped in the previous slot. Returns the current spell by default (useful for items with only one spell).
+ */
+ @Nonnull
+ default Spell getPreviousSpell(ItemStack stack){
+ return getCurrentSpell(stack);
+ }
+
/**
* Returns all the spells currently bound to the given itemstack. The given itemstack will be of this item.
* @param stack The itemstack to query.
@@ -84,6 +106,24 @@ public interface ISpellCastingItem {
*/
boolean showSpellHUD(EntityPlayer player, ItemStack stack);
+ /**
+ * Returns the current cooldown to display on the spell HUD for the given itemstack.
+ * @param stack The itemstack to query.
+ * @return The current cooldown for the equipped spell.
+ */
+ default int getCurrentCooldown(ItemStack stack){
+ return 0;
+ }
+
+ /**
+ * Returns the max cooldown of the current spell to display on the spell HUD for the given itemstack.
+ * @param stack The itemstack to query.
+ * @return The max cooldown for the equipped spell.
+ */
+ default int getCurrentMaxCooldown(ItemStack stack){
+ return 0;
+ }
+
/**
* Returns whether this item's spells should be displayed in the arcane workbench tooltip. Only called client-side.
* Ignore this method if this item is not an {@link IWorkbenchItem}.
diff --git a/src/main/java/electroblob/wizardry/item/ItemWand.java b/src/main/java/electroblob/wizardry/item/ItemWand.java
index 00412f46..15c1b6f2 100644
--- a/src/main/java/electroblob/wizardry/item/ItemWand.java
+++ b/src/main/java/electroblob/wizardry/item/ItemWand.java
@@ -107,6 +107,16 @@ public class ItemWand extends Item implements IWorkbenchItem, ISpellCastingItem,
return WandHelper.getCurrentSpell(stack);
}
+ @Override
+ public Spell getNextSpell(ItemStack stack){
+ return WandHelper.getNextSpell(stack);
+ }
+
+ @Override
+ public Spell getPreviousSpell(ItemStack stack){
+ return WandHelper.getPreviousSpell(stack);
+ }
+
@Override
public Spell[] getSpells(ItemStack stack){
return WandHelper.getSpells(stack);
@@ -127,6 +137,16 @@ public class ItemWand extends Item implements IWorkbenchItem, ISpellCastingItem,
return WandHelper.selectSpell(stack, index);
}
+ @Override
+ public int getCurrentCooldown(ItemStack stack){
+ return WandHelper.getCurrentCooldown(stack);
+ }
+
+ @Override
+ public int getCurrentMaxCooldown(ItemStack stack){
+ return WandHelper.getCurrentMaxCooldown(stack);
+ }
+
@Override
public boolean showSpellHUD(EntityPlayer player, ItemStack stack){
return true;