mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-22 13:09:42 +00:00
Cleanup of all the recipe systems to use both ItemStack and Ore Dictionary names, for more compatibility.
This commit is contained in:
1 parent
2710ecfadd
commit
18edc3a42d
7 files changed
+152
-53
No files matched your search
@@ -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) {
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* This class was created by <cpw>. 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);
|
||||
}
|
||||
}
|
||||
@@ -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<Integer> colors = new ArrayList();
|
||||
List<Object> 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<Object> 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<Integer> colorsMissing = new ArrayList(colors);
|
||||
List<Object> 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() {
|
||||
|
||||
@@ -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<String> 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<String> 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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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<RecipePetals> recipes;
|
||||
int ticksElapsed = 0;
|
||||
int recipeAt = 0;
|
||||
|
||||
public PagePetalRecipe(String unlocalizedName, List<RecipePetals> 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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user