From 45642e44bf1348f52ddbc044b7ea43cd511f579d Mon Sep 17 00:00:00 2001
From: WayofTime <wtime@live.ca>
Date: Fri, 24 Apr 2015 07:56:46 -0400
Subject: [PATCH] Implemented guide pages

---
 .../api/guide/PageAltarRecipe.java            | 69 ++++++++++++++++
 .../api/guide/PageOrbRecipe.java              | 78 +++++++++++++++++++
 .../api/spell/APISpellHelper.java             | 15 ++++
 3 files changed, 162 insertions(+)
 create mode 100644 src/main/java/WayofTime/alchemicalWizardry/api/guide/PageAltarRecipe.java
 create mode 100644 src/main/java/WayofTime/alchemicalWizardry/api/guide/PageOrbRecipe.java

diff --git a/src/main/java/WayofTime/alchemicalWizardry/api/guide/PageAltarRecipe.java b/src/main/java/WayofTime/alchemicalWizardry/api/guide/PageAltarRecipe.java
new file mode 100644
index 00000000..7f334f06
--- /dev/null
+++ b/src/main/java/WayofTime/alchemicalWizardry/api/guide/PageAltarRecipe.java
@@ -0,0 +1,69 @@
+package WayofTime.alchemicalWizardry.api.guide;
+
+
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.FontRenderer;
+import net.minecraft.init.Blocks;
+import net.minecraft.item.Item;
+import net.minecraft.item.ItemStack;
+import net.minecraft.util.ResourceLocation;
+import net.minecraft.util.StatCollector;
+import WayofTime.alchemicalWizardry.api.altarRecipeRegistry.AltarRecipe;
+import amerifrance.guideapi.api.abstraction.CategoryAbstract;
+import amerifrance.guideapi.api.abstraction.EntryAbstract;
+import amerifrance.guideapi.api.base.Book;
+import amerifrance.guideapi.api.base.PageBase;
+import amerifrance.guideapi.api.util.GuiHelper;
+import amerifrance.guideapi.gui.GuiBase;
+import cpw.mods.fml.relauncher.Side;
+import cpw.mods.fml.relauncher.SideOnly;
+
+public class PageAltarRecipe extends PageBase {
+
+    public ItemStack input;
+    public ItemStack output;
+    public int tier;
+    public int bloodRequired;
+
+    public PageAltarRecipe(AltarRecipe recipe) {
+        this.input = recipe.getRequiredItem();
+        this.output = recipe.getResult();
+        this.tier = recipe.getMinTier();
+        this.bloodRequired = recipe.getLiquidRequired();
+    }
+
+    @Override
+    @SideOnly(Side.CLIENT)
+    public void draw(Book book, CategoryAbstract category, EntryAbstract entry, int guiLeft, int guiTop, int mouseX, int mouseY, GuiBase guiBase, FontRenderer fontRenderer) {
+
+        Minecraft.getMinecraft().getTextureManager().bindTexture(new ResourceLocation("alchemicalwizardry" + ":textures/gui/guide/altar.png"));
+        guiBase.drawTexturedModalRect(guiLeft + 42, guiTop + 53, 0, 87, 146, 104);
+
+        guiBase.drawCenteredString(fontRenderer, StatCollector.translateToLocal("text.recipe.altar"), guiLeft + guiBase.xSize / 2, guiTop + 12, 0);
+
+        int inputX = (1 + 1) * 20 + (guiLeft + guiBase.xSize / 7);
+        int inputY = (1 * 20) + (guiTop + guiBase.ySize / 5);
+        GuiHelper.drawItemStack(input, inputX, inputY);
+        if (GuiHelper.isMouseBetween(mouseX, mouseY, inputX, inputY, 15, 15)) {
+            guiBase.renderToolTip(input, mouseX, mouseY);
+        }
+
+        if (output == null) {
+            output = new ItemStack(Blocks.fire);
+        }
+        int outputX = (5 * 20) + (guiLeft + guiBase.xSize / 7);
+        int outputY = (1 * 20) + (guiTop + guiBase.xSize / 5);
+        GuiHelper.drawItemStack(output, outputX, outputY);
+        if (GuiHelper.isMouseBetween(mouseX, mouseY, outputX, outputY, 15, 15)) {
+            guiBase.renderToolTip(output, outputX, outputY);
+        }
+
+        if (output.getItem() == Item.getItemFromBlock(Blocks.fire)) {
+            guiBase.drawCenteredString(fontRenderer, StatCollector.translateToLocal("text.furnace.error"), guiLeft + guiBase.xSize / 2, guiTop + 4 * guiBase.ySize / 6, 0xED073D);
+            guiBase.drawCenteredString(fontRenderer, StatCollector.translateToLocal("bm.string.tier") + ": " + String.valueOf(tier), guiLeft + guiBase.xSize / 2, guiTop + 4 * guiBase.ySize / 6 + 15, 0);
+            guiBase.drawCenteredString(fontRenderer, "LP: " + String.valueOf(bloodRequired), guiLeft + guiBase.xSize / 2, guiTop + 4 * guiBase.ySize / 6 + 30, 0);
+        }
+        guiBase.drawCenteredString(fontRenderer, String.format(StatCollector.translateToLocal("text.recipe.altar.tier"), String.valueOf(tier)), guiLeft + guiBase.xSize / 2, guiTop + 4 * guiBase.ySize / 6, 0);
+        guiBase.drawCenteredString(fontRenderer, String.format(StatCollector.translateToLocal("text.recipe.altar.bloodRequired"), String.valueOf(bloodRequired)), guiLeft + guiBase.xSize / 2, guiTop + 4 * guiBase.ySize / 6 + 15, 0);
+    }
+}
diff --git a/src/main/java/WayofTime/alchemicalWizardry/api/guide/PageOrbRecipe.java b/src/main/java/WayofTime/alchemicalWizardry/api/guide/PageOrbRecipe.java
new file mode 100644
index 00000000..7c78eb73
--- /dev/null
+++ b/src/main/java/WayofTime/alchemicalWizardry/api/guide/PageOrbRecipe.java
@@ -0,0 +1,78 @@
+package WayofTime.alchemicalWizardry.api.guide;
+
+import java.util.ArrayList;
+
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.FontRenderer;
+import net.minecraft.item.ItemStack;
+import net.minecraft.item.crafting.IRecipe;
+import net.minecraft.util.ResourceLocation;
+import net.minecraft.util.StatCollector;
+import WayofTime.alchemicalWizardry.api.items.ShapedBloodOrbRecipe;
+import WayofTime.alchemicalWizardry.api.spell.APISpellHelper;
+import amerifrance.guideapi.ModInformation;
+import amerifrance.guideapi.api.abstraction.CategoryAbstract;
+import amerifrance.guideapi.api.abstraction.EntryAbstract;
+import amerifrance.guideapi.api.base.Book;
+import amerifrance.guideapi.api.util.GuiHelper;
+import amerifrance.guideapi.gui.GuiBase;
+import amerifrance.guideapi.pages.PageIRecipe;
+import cpw.mods.fml.relauncher.ReflectionHelper;
+import cpw.mods.fml.relauncher.Side;
+import cpw.mods.fml.relauncher.SideOnly;
+
+public class PageOrbRecipe extends PageIRecipe {
+
+    /**
+     * @param recipe - Recipe to draw
+     */
+    public PageOrbRecipe(IRecipe recipe) 
+    {
+        super(recipe);
+    }
+
+    @Override
+    @SideOnly(Side.CLIENT)
+    public void draw(Book book, CategoryAbstract category, EntryAbstract entry, int guiLeft, int guiTop, int mouseX, int mouseY, GuiBase guiBase, FontRenderer fontRenderer) {
+
+        Minecraft.getMinecraft().getTextureManager().bindTexture(new ResourceLocation(ModInformation.GUITEXLOC + "recipe_elements.png"));
+        guiBase.drawTexturedModalRect(guiLeft + 42, guiTop + 53, 0, 0, 105, 65);
+
+        guiBase.drawCenteredString(fontRenderer, StatCollector.translateToLocal("text.recipe.shapedOrb"), guiLeft + guiBase.xSize / 2, guiTop + 12, 0);
+        ShapedBloodOrbRecipe shapedBloodOrbRecipe = (ShapedBloodOrbRecipe) recipe;
+        int width = ReflectionHelper.getPrivateValue(ShapedBloodOrbRecipe.class, shapedBloodOrbRecipe, 4);
+        int height = ReflectionHelper.getPrivateValue(ShapedBloodOrbRecipe.class, shapedBloodOrbRecipe, 5);
+        for (int y = 0; y < height; y++) {
+            for (int x = 0; x < width; x++) {
+                int stackX = (x + 1) * 20 + (guiLeft + guiBase.xSize / 7);
+                int stackY = (y + 1) * 20 + (guiTop + guiBase.ySize / 5);
+                Object component = shapedBloodOrbRecipe.getInput()[y * width + x];
+                if (component != null) {
+                    if (component instanceof ItemStack) {
+                        GuiHelper.drawItemStack((ItemStack) component, stackX, stackY);
+                        if (GuiHelper.isMouseBetween(mouseX, mouseY, stackX, stackY, 15, 15)) {
+                            guiBase.renderToolTip((ItemStack) component, stackX, stackY);
+                        }
+                    } else if (component instanceof Integer) {
+                        GuiHelper.drawItemStack(APISpellHelper.getOrbForLevel((Integer) component), stackX, stackY);
+                        if (GuiHelper.isMouseBetween(mouseX, mouseY, stackX, stackY, 15, 15)) {
+                            guiBase.renderToolTip(APISpellHelper.getOrbForLevel((Integer) component), stackX, stackY);
+                        }
+                    } else {
+                        if (((ArrayList<ItemStack>) component).isEmpty()) return;
+                        GuiHelper.drawItemStack(((ArrayList<ItemStack>) component).get(0), stackX, stackY);
+                        if (GuiHelper.isMouseBetween(mouseX, mouseY, stackX, stackY, 15, 15)) {
+                            guiBase.renderToolTip(((ArrayList<ItemStack>) component).get(0), stackX, stackY);
+                        }
+                    }
+                }
+            }
+        }
+        int outputX = (5 * 20) + (guiLeft + guiBase.xSize / 7);
+        int outputY = (2 * 20) + (guiTop + guiBase.xSize / 5);
+        GuiHelper.drawItemStack(shapedBloodOrbRecipe.getRecipeOutput(), outputX, outputY);
+        if (GuiHelper.isMouseBetween(mouseX, mouseY, outputX, outputY, 15, 15)) {
+            guiBase.renderToolTip(shapedBloodOrbRecipe.getRecipeOutput(), outputX, outputY);
+        }
+    }
+}
diff --git a/src/main/java/WayofTime/alchemicalWizardry/api/spell/APISpellHelper.java b/src/main/java/WayofTime/alchemicalWizardry/api/spell/APISpellHelper.java
index 19a324c9..7884a043 100644
--- a/src/main/java/WayofTime/alchemicalWizardry/api/spell/APISpellHelper.java
+++ b/src/main/java/WayofTime/alchemicalWizardry/api/spell/APISpellHelper.java
@@ -19,6 +19,8 @@ import net.minecraft.util.Vec3;
 import net.minecraft.world.World;
 import WayofTime.alchemicalWizardry.api.alchemy.energy.Reagent;
 import WayofTime.alchemicalWizardry.api.alchemy.energy.ReagentRegistry;
+import WayofTime.alchemicalWizardry.api.items.interfaces.IBloodOrb;
+import WayofTime.alchemicalWizardry.client.nei.NEIConfig;
 import cpw.mods.fml.common.registry.GameRegistry;
 
 public class APISpellHelper 
@@ -181,6 +183,19 @@ public class APISpellHelper
 		data.setInteger("BM:ReagentRegenCooldown", amount);
 	}
 	
+	public static ItemStack getOrbForLevel(int level)
+	{
+		for (Item item : NEIConfig.bloodOrbs) 
+		{
+			if (((IBloodOrb) item).getOrbLevel() == level) 
+			{
+				return new ItemStack(item);
+			}
+		}
+		
+		return null;
+	}
+	
 	public static MovingObjectPosition raytraceFromEntity(World world, Entity player, boolean par3, double range)
     {
         float f = 1.0F;