package com.lothrazar.cyclicmagic.registry;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.lothrazar.cyclicmagic.spell.ISpell;
import com.lothrazar.cyclicmagic.item.tool.ItemCyclicWand;
import com.lothrazar.cyclicmagic.spell.*;
import com.lothrazar.cyclicmagic.util.UtilSpellCaster;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;

public class SpellRegistry {
  public static boolean renderOnLeft;
  private static Map<Integer, ISpell> hashbook;
  public static boolean doParticles;
  public static class Spells {
    // on purpose, not all spells are in here. only ones that needed to be
    // exposed
    public static SpellRangeRotate rotate;
    public static SpellRangePush push;
    public static SpellRangePull pull;
    private static SpellInventory inventory;
    private static SpellRangeBuild reachdown;
    private static SpellRangeBuild reachup;
    private static SpellRangeBuild reachplace;
  }
  public static void register(ItemCyclicWand wand) {
    hashbook = new HashMap<Integer, ISpell>();
    int spellId = -1;// the smallest spell gets id zero
    Spells.inventory = new SpellInventory(++spellId, "inventory");
    registerSpell(Spells.inventory);
    Spells.rotate = new SpellRangeRotate(++spellId, "rotate");
    registerSpell(Spells.rotate);
    Spells.push = new SpellRangePush(++spellId, "push");
    registerSpell(Spells.push);
    Spells.pull = new SpellRangePull(++spellId, "pull");
    registerSpell(Spells.pull);
    Spells.reachup = new SpellRangeBuild(++spellId, "reachup", SpellRangeBuild.PlaceType.UP);
    registerSpell(Spells.reachup);
    Spells.reachplace = new SpellRangeBuild(++spellId, "reachplace", SpellRangeBuild.PlaceType.PLACE);
    registerSpell(Spells.reachplace);
    Spells.reachdown = new SpellRangeBuild(++spellId, "reachdown", SpellRangeBuild.PlaceType.DOWN);
    registerSpell(Spells.reachdown);
    SpellRangeBuild reachleft = new SpellRangeBuild(++spellId, "reachleft", SpellRangeBuild.PlaceType.LEFT);
    registerSpell(reachleft);
    SpellRangeBuild reachright = new SpellRangeBuild(++spellId, "reachright", SpellRangeBuild.PlaceType.RIGHT);
    registerSpell(reachright);
    ArrayList<ISpell> spellbookBuild = new ArrayList<ISpell>();
    spellbookBuild.add(Spells.inventory);
    spellbookBuild.add(Spells.reachup);
    spellbookBuild.add(Spells.reachplace);
    spellbookBuild.add(Spells.reachdown);
    spellbookBuild.add(reachleft);
    spellbookBuild.add(reachright);
    wand.setSpells(spellbookBuild);
  }
  private static void registerSpell(ISpell spell) {
    hashbook.put(spell.getID(), spell);
  }
  public static boolean spellsEnabled(EntityPlayer player) {
    // current requirement is only a wand
    return UtilSpellCaster.getPlayerWandIfHeld(player) != null;
  }
  public static ISpell getSpellFromID(int id) {
    if (hashbook.containsKey(id)) { return hashbook.get(id); }
    return null;
  }
  public static List<ISpell> getSpellbook(ItemStack wand) {
    return ((ItemCyclicWand) wand.getItem()).getSpells();
  }
  public static ISpell next(ItemStack wand, ISpell spell) {
    List<ISpell> book = getSpellbook(wand);
    int indexCurrent = book.indexOf(spell);
    int indexNext = indexCurrent + 1;
    if (indexNext >= book.size()) {
      indexNext = 0;
    }
    return book.get(indexNext);
  }
  public static ISpell prev(ItemStack wand, ISpell spell) {
    List<ISpell> book = getSpellbook(wand);
    int indexCurrent = book.indexOf(spell);
    int indexPrev;
    if (indexCurrent <= 0) // not that it ever WOULD be.. negative.. yeah
      indexPrev = book.size() - 1;
    else
      indexPrev = indexCurrent - 1;
    ISpell ret = book.get(indexPrev);
    return ret;
  }
}

@@ -1002,16 +1002,112 @@
 hplace;%0A
+    private static SpellRangeBuild reachleft ;%0A    private static  SpellRangeBuild reachright ;%0A
   %7D%0A  pu
@@ -1207,62 +1207,230 @@
 );%0A 
+%0A
    
-int spellId = -1;// the smallest spell gets id zero
+ /*%0A SPELL REG 0 Inventory%0A SPELL REG 1 Rotation%0A SPELL REG 2 Push Block%0A SPELL REG 3 Pull Block%0A SPELL REG 4 Build Up%0A SPELL REG 5 Place Block%0A SPELL REG 6 Build Down%0A SPELL REG 7 Build Left%0A SPELL REG 8 Build Right*/
 %0A   
@@ -1468,25 +1468,17 @@
 ventory(
-++spellId
+0
 , %22inven
@@ -1563,25 +1563,17 @@
 eRotate(
-++spellId
+1
 , %22rotat
@@ -1648,25 +1648,17 @@
 ngePush(
-++spellId
+2
 , %22push%22
@@ -1729,25 +1729,17 @@
 ngePull(
-++spellId
+3
 , %22pull%22
@@ -1810,33 +1810,25 @@
 lRangeBuild(
-++spellId
+4
 , %22reachup%22,
@@ -1934,33 +1934,25 @@
 lRangeBuild(
-++spellId
+5
 , %22reachplac
@@ -2066,33 +2066,25 @@
 lRangeBuild(
-++spellId
+6
 , %22reachdown
@@ -2161,35 +2161,26 @@
 );%0A    Spell
-RangeBuild 
+s.
 reachleft = 
@@ -2195,33 +2195,25 @@
 lRangeBuild(
-++spellId
+7
 , %22reachleft
@@ -2262,24 +2262,31 @@
 gisterSpell(
+Spells.
 reachleft);%0A
@@ -2290,35 +2290,26 @@
 );%0A    Spell
-RangeBuild 
+s.
 reachright =
@@ -2333,17 +2333,9 @@
 ild(
-++spellId
+8
 , %22r
@@ -2398,16 +2398,23 @@
 erSpell(
+Spells.
 reachrig
@@ -2668,24 +2668,31 @@
 okBuild.add(
+Spells.
 reachleft);%0A
@@ -2714,16 +2714,23 @@
 ild.add(
+Spells.
 reachrig
@@ -2822,24 +2822,96 @@
 ll spell) %7B%0A
+    System.out.println(%22SPELL REG %22+spell.getID()+%22 %22+spell.getName());%0A
     hashbook

refactor spells: hardcode ids