diff --git a/MODSRC/vazkii/botania/api/BotaniaAPI.java b/MODSRC/vazkii/botania/api/BotaniaAPI.java index 38a319a00..aecf6b8da 100644 --- a/MODSRC/vazkii/botania/api/BotaniaAPI.java +++ b/MODSRC/vazkii/botania/api/BotaniaAPI.java @@ -54,12 +54,12 @@ public final class BotaniaAPI { /** * Registers a Petal Recipe. * @param output The ItemStack to craft. - * @param colors The required metadata petals for this recipe to be accept. - * Eg: 0, 0, 1 is White, White, Orange + * @param inputs The objects for crafting. Can be ItemStack, MappableStackWrapper + * or String (case for Ore Dictionary) * @return The recipe created. */ - public static RecipePetals registerPetalRecipe(ItemStack output, int... colors) { - RecipePetals recipe = new RecipePetals(output, colors); + public static RecipePetals registerPetalRecipe(ItemStack output, Object... inputs) { + RecipePetals recipe = new RecipePetals(output, inputs); petalRecipes.add(recipe); return recipe; } @@ -67,11 +67,12 @@ public final class BotaniaAPI { /** * Registers a Rune Altar * @param output The ItemStack to craft. - * @param mana The amount of mana required. - * @param inputs The ore dictionary names of the items required for crafting. + * @param mana The amount of mana required. Don't go over 100000! + * @param inputs The objects for crafting. Can be ItemStack, MappableStackWrapper + * or String (case for Ore Dictionary) * @return The recipe created. */ - public static RecipeRuneAltar registerRuneAltarRecipe(ItemStack output, int mana, String... inputs) { + public static RecipeRuneAltar registerRuneAltarRecipe(ItemStack output, int mana, Object... inputs) { RecipeRuneAltar recipe = new RecipeRuneAltar(output, mana, inputs); runeAltarRecipes.add(recipe); return recipe; @@ -81,6 +82,7 @@ public final class BotaniaAPI { * Registers a Mana Infusion Recipe (throw an item in a mana pool) * @param output The ItemStack to craft * @param input The input item, be it an ItemStack or an ore dictionary entry String. + * @param mana The amount of mana required. Don't go over 100000! * @return The recipe created. */ public static RecipeManaInfusion registerManaInfusionRecipe(ItemStack output, Object input, int mana) { diff --git a/MODSRC/vazkii/botania/api/internal/MappableStackWrapper.java b/MODSRC/vazkii/botania/api/internal/MappableStackWrapper.java new file mode 100644 index 000000000..a04eb78ae --- /dev/null +++ b/MODSRC/vazkii/botania/api/internal/MappableStackWrapper.java @@ -0,0 +1,41 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under a + * Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License + * (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB) + * + * File Created @ [? (GMT)] + */ +package vazkii.botania.api.internal; + +import net.minecraft.item.ItemStack; + +public class MappableStackWrapper { + + private ItemStack wrap; + + public MappableStackWrapper(ItemStack toWrap) + { + wrap = toWrap; + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof MappableStackWrapper)) + return false; + + MappableStackWrapper isw = (MappableStackWrapper) obj; + if (wrap.getHasSubtypes()) + return isw.wrap.isItemEqual(wrap); + + else return isw.wrap == wrap; + } + + @Override + public int hashCode() { + return System.identityHashCode(wrap); + } +} diff --git a/MODSRC/vazkii/botania/api/recipe/RecipePetals.java b/MODSRC/vazkii/botania/api/recipe/RecipePetals.java index 37880256d..75dc3dde1 100644 --- a/MODSRC/vazkii/botania/api/recipe/RecipePetals.java +++ b/MODSRC/vazkii/botania/api/recipe/RecipePetals.java @@ -14,36 +14,52 @@ package vazkii.botania.api.recipe; import java.util.ArrayList; import java.util.List; +import vazkii.botania.api.internal.MappableStackWrapper; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; +import net.minecraftforge.oredict.OreDictionary; public class RecipePetals { ItemStack output; - List colors = new ArrayList(); + List inputs; - public RecipePetals(ItemStack output, int... colors) { + public RecipePetals(ItemStack output, Object... inputs) { this.output = output; - for(int c : colors) - this.colors.add(c); + + List inputsToSet = new ArrayList(); + for(Object obj : inputs) { + if(obj instanceof String) + inputsToSet.add(obj); + else if(obj instanceof MappableStackWrapper) + inputsToSet.add(obj); + else if(obj instanceof ItemStack) + inputsToSet.add(new MappableStackWrapper((ItemStack) obj)); + else throw new IllegalArgumentException("Invalid input"); + } + + this.inputs = inputsToSet; } public boolean matches(IInventory inv) { - List colorsMissing = new ArrayList(colors); + List inputsMissing = new ArrayList(inputs); for(int i = 0; i < inv.getSizeInventory(); i++) { ItemStack stack = inv.getStackInSlot(i); if(stack == null) break; - int color = stack.getItemDamage(); - - if(!colorsMissing.contains(color)) + String oredict = OreDictionary.getOreName(OreDictionary.getOreID(stack)); + + if(!inputsMissing.contains(stack) && !inputsMissing.contains(oredict)) return false; - colorsMissing.remove((Integer) color); + + if(inputsMissing.contains(stack)) + inputsMissing.remove(stack); + else inputsMissing.remove(oredict); } - return colorsMissing.isEmpty(); + return inputsMissing.isEmpty(); } public ItemStack getOutput() { diff --git a/MODSRC/vazkii/botania/api/recipe/RecipeRuneAltar.java b/MODSRC/vazkii/botania/api/recipe/RecipeRuneAltar.java index bc050bff2..cd1a3019e 100644 --- a/MODSRC/vazkii/botania/api/recipe/RecipeRuneAltar.java +++ b/MODSRC/vazkii/botania/api/recipe/RecipeRuneAltar.java @@ -11,48 +11,18 @@ */ package vazkii.botania.api.recipe; -import java.util.ArrayList; -import java.util.List; - -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; -import net.minecraftforge.oredict.OreDictionary; -public class RecipeRuneAltar { +public class RecipeRuneAltar extends RecipePetals { ItemStack output; - List inputs = new ArrayList(); int mana; - public RecipeRuneAltar(ItemStack output, int mana, String... inputs) { + public RecipeRuneAltar(ItemStack output, int mana, Object... inputs) { + super(output, inputs); this.output = output; - for(String i : inputs) - this.inputs.add(i); this.mana = mana; } - - public boolean matches(IInventory inv) { - List inputsMissing = new ArrayList(inputs); - - for(int i = 0; i < inv.getSizeInventory(); i++) { - ItemStack stack = inv.getStackInSlot(i); - if(stack == null) - break; - - String ore = OreDictionary.getOreName(OreDictionary.getOreID(stack)); - - if(!inputsMissing.contains(ore)) - return false; - - inputsMissing.remove(ore); - } - - return inputsMissing.isEmpty(); - } - - public ItemStack getOutput() { - return output; - } public int getManaUsage() { return mana; diff --git a/MODSRC/vazkii/botania/common/crafting/ModPetalRecipes.java b/MODSRC/vazkii/botania/common/crafting/ModPetalRecipes.java index c6f72d6bc..1d9daf352 100644 --- a/MODSRC/vazkii/botania/common/crafting/ModPetalRecipes.java +++ b/MODSRC/vazkii/botania/common/crafting/ModPetalRecipes.java @@ -7,7 +7,7 @@ * Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License * (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB) * - * File Created @ [Jan 22, 2014, 2:22:21 PM (GMT)] + * File Created @ [Jan 22], 2014], 2:22:21 PM (GMT)] */ package vazkii.botania.common.crafting; @@ -15,10 +15,11 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import vazkii.botania.api.BotaniaAPI; import vazkii.botania.api.recipe.RecipePetals; +import vazkii.botania.common.lib.LibOreDict; public final class ModPetalRecipes { - public static final int white = 0, orange = 1, magenta = 2, lightBlue = 3, yellow = 4, lime = 5, pink = 6, gray = 7, lightGray = 8, cyan = 9, purple = 10, blue = 11, brown = 12, green = 13, red = 14, black = 15; + public static final String white = LibOreDict.PETAL[0], orange = LibOreDict.PETAL[1], magenta = LibOreDict.PETAL[2], lightBlue = LibOreDict.PETAL[3], yellow = LibOreDict.PETAL[4], lime = LibOreDict.PETAL[5], pink = LibOreDict.PETAL[6], gray = LibOreDict.PETAL[7], lightGray = LibOreDict.PETAL[8], cyan = LibOreDict.PETAL[9], purple = LibOreDict.PETAL[10], blue = LibOreDict.PETAL[11], brown = LibOreDict.PETAL[12], green = LibOreDict.PETAL[13], red = LibOreDict.PETAL[14], black = LibOreDict.PETAL[15]; public static RecipePetals testRecipe; diff --git a/MODSRC/vazkii/botania/common/lexicon/page/PagePetalRecipe.java b/MODSRC/vazkii/botania/common/lexicon/page/PagePetalRecipe.java index 68f13295a..9a742422f 100644 --- a/MODSRC/vazkii/botania/common/lexicon/page/PagePetalRecipe.java +++ b/MODSRC/vazkii/botania/common/lexicon/page/PagePetalRecipe.java @@ -11,6 +11,57 @@ */ package vazkii.botania.common.lexicon.page; -public class PagePetalRecipe { +import java.util.Arrays; +import java.util.List; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.renderer.texture.TextureManager; +import net.minecraft.item.ItemStack; +import vazkii.botania.api.internal.IGuiLexiconEntry; +import vazkii.botania.api.recipe.RecipePetals; +import vazkii.botania.common.block.ModBlocks; + +public class PagePetalRecipe extends PageRecipe { + + List recipes; + int ticksElapsed = 0; + int recipeAt = 0; + + public PagePetalRecipe(String unlocalizedName, List recipes) { + super(unlocalizedName); + this.recipes = recipes; + } + + public PagePetalRecipe(String unlocalizedName, RecipePetals recipe) { + this(unlocalizedName, Arrays.asList(recipe)); + } + + @Override + public void renderRecipe(IGuiLexiconEntry gui, int mx, int my) { + RecipePetals recipe = recipes.get(recipeAt); + + renderItemAtGridPos(gui, 2, 0, recipe.getOutput(), false); + renderItemAtGridPos(gui, 2, 1, new ItemStack(ModBlocks.altar), false); + +// GL11.glEnable(GL11.GL_BLEND); +// GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); +// String manaUsage = StatCollector.translateToLocal("botaniamisc.manaUsage"); +// font.drawString(manaUsage, gui.getLeft() + gui.getWidth() / 2 - font.getStringWidth(manaUsage) / 2, gui.getTop() + 105, 0x66000000); +// +// HUDHandler.renderManaBar(gui.getLeft() + gui.getWidth() / 2 - 50, gui.getTop() + 115, 0x0000FF, 0.75F, recipe.getManaToConsume(), TilePool.MAX_MANA / 10); +// GL11.glDisable(GL11.GL_BLEND); + } + + @Override + public void updateScreen() { + if(ticksElapsed % 20 == 0) { + recipeAt++; + + if(recipeAt == recipes.size()) + recipeAt = 0; + } + ++ticksElapsed; + } } diff --git a/MODSRC/vazkii/botania/common/lexicon/page/PageRecipe.java b/MODSRC/vazkii/botania/common/lexicon/page/PageRecipe.java index 3aa8a2e01..d2c4c4358 100644 --- a/MODSRC/vazkii/botania/common/lexicon/page/PageRecipe.java +++ b/MODSRC/vazkii/botania/common/lexicon/page/PageRecipe.java @@ -69,6 +69,24 @@ public class PageRecipe extends LexiconPage { // NO-OP } + public void renderItemAtAngle(IGuiLexiconEntry gui, int angle, ItemStack stack) { + if(stack == null || stack.getItem() == null) + return; + stack = stack.copy(); + + if(stack.getItemDamage() == Short.MAX_VALUE) + stack.setItemDamage(0); + + angle -= 90; + int xPos = gui.getLeft() + (int) (Math.cos(angle) * 12) + gui.getWidth() / 2; + int yPos = gui.getTop() + (int) (Math.sin(angle) * 12) + 25; + ItemStack stack1 = stack.copy(); + if(stack1.getItemDamage() == -1) + stack1.setItemDamage(0); + + renderItem(gui, xPos, yPos, stack1, false); + } + public void renderItemAtGridPos(IGuiLexiconEntry gui, int x, int y, ItemStack stack, boolean accountForContainer) { if(stack == null || stack.getItem() == null) return;