From 2d5cafc1853bdfbe2ad943dda68ccd6ec2e2f176 Mon Sep 17 00:00:00 2001 From: joshiejack Date: Wed, 19 Mar 2014 01:39:49 +0000 Subject: [PATCH] Blood Altar NEI Integration --- .../nei/NEIAlchemyRecipeHandler.java | 3 +- .../nei/NEIAltarRecipeHandler.java | 161 ++++++++++++++++++ .../alchemicalWizardy/nei/NEIConfig.java | 4 +- .../alchemicalwizardry/gui/nei/altar.png | Bin 0 -> 4204 bytes .../assets/alchemicalwizardry/lang/en_US.lang | 7 +- 5 files changed, 172 insertions(+), 3 deletions(-) create mode 100644 BM_src/joshie/alchemicalWizardy/nei/NEIAltarRecipeHandler.java create mode 100644 resources/assets/alchemicalwizardry/gui/nei/altar.png diff --git a/BM_src/joshie/alchemicalWizardy/nei/NEIAlchemyRecipeHandler.java b/BM_src/joshie/alchemicalWizardy/nei/NEIAlchemyRecipeHandler.java index c869c093..4e8750d6 100644 --- a/BM_src/joshie/alchemicalWizardy/nei/NEIAlchemyRecipeHandler.java +++ b/BM_src/joshie/alchemicalWizardy/nei/NEIAlchemyRecipeHandler.java @@ -7,6 +7,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; +import net.minecraft.util.StatCollector; import WayofTime.alchemicalWizardry.common.alchemy.AlchemyRecipe; import WayofTime.alchemicalWizardry.common.alchemy.AlchemyRecipeRegistry; import codechicken.nei.NEIServerUtils; @@ -120,7 +121,7 @@ public class NEIAlchemyRecipeHandler extends TemplateRecipeHandler { @Override public String getRecipeName() { - return "Alchemic Chemistry Set"; + return StatCollector.translateToLocal("tile.blockWritingTable.name"); } @Override diff --git a/BM_src/joshie/alchemicalWizardy/nei/NEIAltarRecipeHandler.java b/BM_src/joshie/alchemicalWizardy/nei/NEIAltarRecipeHandler.java new file mode 100644 index 00000000..9ca77ec5 --- /dev/null +++ b/BM_src/joshie/alchemicalWizardy/nei/NEIAltarRecipeHandler.java @@ -0,0 +1,161 @@ +package joshie.alchemicalWizardy.nei; + +import java.awt.Point; +import java.awt.Rectangle; +import java.lang.reflect.Field; +import java.util.List; + +import net.minecraft.client.Minecraft; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.StatCollector; +import WayofTime.alchemicalWizardry.common.altarRecipeRegistry.AltarRecipe; +import WayofTime.alchemicalWizardry.common.altarRecipeRegistry.AltarRecipeRegistry; +import codechicken.core.gui.GuiDraw; +import codechicken.nei.NEIServerUtils; +import codechicken.nei.PositionedStack; +import codechicken.nei.recipe.GuiRecipe; +import codechicken.nei.recipe.TemplateRecipeHandler; + +public class NEIAltarRecipeHandler extends TemplateRecipeHandler { + public class CachedAltarRecipe extends CachedRecipe { + PositionedStack input; + PositionedStack output; + int tier, lp_amount, consumption, drain; + + public CachedAltarRecipe(AltarRecipe recipe) { + input = new PositionedStack(recipe.requiredItem, 38, 2, false); + output = new PositionedStack(recipe.result, 132, 32, false); + tier = recipe.minTier; + lp_amount = recipe.liquidRequired; + consumption = recipe.consumptionRate; + drain = recipe.drainRate; + } + + @Override + public PositionedStack getIngredient() { + return input; + } + + @Override + public PositionedStack getResult() { + return output; + } + } + + @Override + public void loadCraftingRecipes(String outputId, Object... results) { + if (outputId.equals("altarrecipes") && getClass() == NEIAltarRecipeHandler.class) { + for(AltarRecipe recipe: AltarRecipeRegistry.altarRecipes) { + if(recipe.result != null) arecipes.add(new CachedAltarRecipe(recipe)); + } + } else { + super.loadCraftingRecipes(outputId, results); + } + } + + @Override + public void loadCraftingRecipes(ItemStack result) { + for(AltarRecipe recipe: AltarRecipeRegistry.altarRecipes) { + if(NEIServerUtils.areStacksSameTypeCrafting(recipe.result, result)) { + if(recipe.result != null) arecipes.add(new CachedAltarRecipe(recipe)); + } + } + } + + @Override + public void loadUsageRecipes(ItemStack ingredient) { + for(AltarRecipe recipe: AltarRecipeRegistry.altarRecipes) { + if(NEIServerUtils.areStacksSameTypeCrafting(recipe.requiredItem, ingredient)) { + if(recipe.result != null) arecipes.add(new CachedAltarRecipe(recipe)); + } + } + } + + //Mouse Position helper + public Point getMouse(int width, int height) { + Point mousepos = GuiDraw.getMousePosition(); + int guiLeft = (width - 176) / 2; + int guiTop = (height - 166) / 2; + Point relMouse = new Point(mousepos.x - guiLeft, mousepos.y - guiTop); + return relMouse; + } + + //width helper, getting width normal way hates me on compile + public int getGuiWidth(GuiRecipe gui) { + try { + Field f = gui.getClass().getField("width"); + return (Integer) f.get(gui); + } catch (NoSuchFieldException e) { + try { + Field f = gui.getClass().getField("field_73880_f"); + return (Integer) f.get(gui); + } catch (Exception e2) { + return 0; + } + } catch (Exception e) { + e.printStackTrace(); + return 0; + } + } + + //height helper, getting height normal way hates me on compile + public int getGuiHeight(GuiRecipe gui) { + try { + Field f = gui.getClass().getField("height"); + return (Integer) f.get(gui); + } catch (NoSuchFieldException e) { + try { + Field f = gui.getClass().getField("field_73881_g"); + return (Integer) f.get(gui); + } catch (Exception e2) { + return 0; + } + } catch (Exception e) { + e.printStackTrace(); + return 0; + } + } + + @Override + public void drawExtras(int id) { + CachedAltarRecipe recipe = (CachedAltarRecipe) arecipes.get(id); + Minecraft.getMinecraft().fontRenderer.drawString("\u00a77" + StatCollector.translateToLocal("bm.string.tier") + ": " + recipe.tier, 78, 5, 0); + Minecraft.getMinecraft().fontRenderer.drawString("\u00a77" + "LP: " + recipe.lp_amount, 78, 15, 0); + } + + @Override + public List handleTooltip(GuiRecipe gui, List currenttip, int id) { + currenttip = super.handleTooltip(gui, currenttip, id); + Point mouse = getMouse(getGuiWidth(gui), getGuiHeight(gui)); + CachedAltarRecipe recipe = (CachedAltarRecipe) arecipes.get(id); + int yLow = id % 2 == 0 ? 38 : 102; + int yHigh = id % 2 == 0 ? 72 : 136; + if(mouse.x >= 19 && mouse.x <= 80 && mouse.y >= yLow && mouse.y <= yHigh) { + currenttip.add(StatCollector.translateToLocal("bm.string.consume") + ": " + recipe.consumption + "LP/t"); + currenttip.add(StatCollector.translateToLocal("bm.string.drain") + ": " + recipe.drain + "LP/t"); + } + + return currenttip; + } + + @Override + public String getOverlayIdentifier() { + return "altarrecipes"; + } + + @Override + public void loadTransferRects() { + transferRects.add(new RecipeTransferRect(new Rectangle(90, 32, 22, 16), "altarrecipes")); + } + + @Override + public String getRecipeName() { + return " " + StatCollector.translateToLocal("tile.bloodAltar.name"); + } + + @Override + public String getGuiTexture() { + return new ResourceLocation("alchemicalwizardry", "gui/nei/altar.png").toString(); + } +} diff --git a/BM_src/joshie/alchemicalWizardy/nei/NEIConfig.java b/BM_src/joshie/alchemicalWizardy/nei/NEIConfig.java index 3d2c3726..e4dcdf36 100644 --- a/BM_src/joshie/alchemicalWizardy/nei/NEIConfig.java +++ b/BM_src/joshie/alchemicalWizardy/nei/NEIConfig.java @@ -12,6 +12,8 @@ public class NEIConfig implements IConfigureNEI { public void loadConfig() { API.registerRecipeHandler(new NEIAlchemyRecipeHandler()); API.registerUsageHandler(new NEIAlchemyRecipeHandler()); + API.registerRecipeHandler(new NEIAltarRecipeHandler()); + API.registerUsageHandler(new NEIAltarRecipeHandler()); NEIAlchemyRecipeHandler.bloodOrbs = new ArrayList(); NEIAlchemyRecipeHandler.bloodOrbs.add(ModItems.weakBloodOrb); @@ -28,6 +30,6 @@ public class NEIConfig implements IConfigureNEI { @Override public String getVersion() { - return "1.0"; + return "1.1"; } } diff --git a/resources/assets/alchemicalwizardry/gui/nei/altar.png b/resources/assets/alchemicalwizardry/gui/nei/altar.png new file mode 100644 index 0000000000000000000000000000000000000000..b1de616ac851daf73b82273aca4dbc6db7331e48 GIT binary patch literal 4204 zcmd^DcT^K=-X0L?DEAu5rR$|z2r4Qd2qHp&4JDyTmnNY}LhqnP1w=s*kfL-GB%ugM zD8b96E1@GuQR&?f2tpv)alh}Lv%BZ+x8K=+cg~qJ^P8FXd4K(VpLu8oHxS?z;{^af z0A_g20sz>+TQ-236TH}?UwMER4$M^;k{diCx!oRsGS6*8TMYO;@yE$_mAs$~K9mU5 zw+Te}djy8Kpx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