Fix @WayofTime using the shaped/shapeless in the joshie folder, when he should be using the ones in the api folder.

Repackage the NEI stuff to the main folder, I was being egotistical.
Also Includes @Tonius changes for adding a recipe button to the alchemical chemistry set for the nei handler.
And adds some checks, to the recipes, as sometimes they crash when adding/removing any.
This commit is contained in:
joshiejack 2014-10-16 05:27:37 +01:00
parent 772bcf1ee6
commit d0e974ddef
9 changed files with 208 additions and 545 deletions

View file

@ -6,6 +6,8 @@ import WayofTime.alchemicalWizardry.api.alchemy.energy.ReagentRegistry;
import WayofTime.alchemicalWizardry.api.altarRecipeRegistry.AltarRecipeRegistry;
import WayofTime.alchemicalWizardry.api.bindingRegistry.BindingRegistry;
import WayofTime.alchemicalWizardry.api.harvest.HarvestRegistry;
import WayofTime.alchemicalWizardry.api.items.ShapedBloodOrbRecipe;
import WayofTime.alchemicalWizardry.api.items.ShapelessBloodOrbRecipe;
import WayofTime.alchemicalWizardry.api.rituals.Rituals;
import WayofTime.alchemicalWizardry.api.summoningRegistry.SummoningRegistry;
import WayofTime.alchemicalWizardry.common.*;
@ -41,8 +43,6 @@ import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.EntityRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import joshie.alchemicalWizardy.ShapedBloodOrbRecipe;
import joshie.alchemicalWizardy.ShapelessBloodOrbRecipe;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;

View file

@ -0,0 +1,179 @@
package WayofTime.alchemicalWizardry.client.nei;
import static WayofTime.alchemicalWizardry.client.nei.NEIConfig.bloodOrbs;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import WayofTime.alchemicalWizardry.api.alchemy.AlchemyRecipe;
import WayofTime.alchemicalWizardry.api.alchemy.AlchemyRecipeRegistry;
import WayofTime.alchemicalWizardry.api.items.interfaces.IBloodOrb;
import WayofTime.alchemicalWizardry.common.tileEntity.gui.GuiWritingTable;
import codechicken.nei.ItemList;
import codechicken.nei.NEIServerUtils;
import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.TemplateRecipeHandler;
/**
* NEI Alchemy Recipe Handler by joshie *
*/
public class NEIAlchemyRecipeHandler extends TemplateRecipeHandler {
public class CachedAlchemyRecipe extends CachedRecipe {
public class BloodOrbs {
public PositionedStack stack;
public BloodOrbs(ItemStack orb) {
this.stack = new PositionedStack(orb, 136, 47, false);
}
}
ArrayList<BloodOrbs> orbs;
PositionedStack output;
List<PositionedStack> inputs;
int lp;
public CachedAlchemyRecipe(AlchemyRecipe recipe, ItemStack orb) {
this(recipe);
this.orbs = new ArrayList<BloodOrbs>();
orbs.add(new BloodOrbs(orb));
}
public CachedAlchemyRecipe(AlchemyRecipe recipe) {
List<PositionedStack> inputs = new ArrayList<PositionedStack>();
ItemStack[] stacks = recipe.getRecipe();
if (stacks.length > 0) inputs.add(new PositionedStack(stacks[0], 76, 3));
if (stacks.length > 1) inputs.add(new PositionedStack(stacks[1], 51, 19));
if (stacks.length > 2) inputs.add(new PositionedStack(stacks[2], 101, 19));
if (stacks.length > 3) inputs.add(new PositionedStack(stacks[3], 64, 47));
if (stacks.length > 4) inputs.add(new PositionedStack(stacks[4], 88, 47));
this.inputs = inputs;
this.output = new PositionedStack(recipe.getResult(), 76, 25);
this.lp = recipe.getAmountNeeded() * 100;
this.orbs = new ArrayList<BloodOrbs>();
for (Item orb : bloodOrbs) {
if (((IBloodOrb) orb).getOrbLevel() >= recipe.getOrbLevel()) {
orbs.add(new BloodOrbs(new ItemStack(orb)));
}
}
}
@Override
public List<PositionedStack> getIngredients() {
return inputs;
}
@Override
public PositionedStack getResult() {
return output;
}
@Override
public PositionedStack getOtherStack() {
if (orbs == null || orbs.size() <= 0) return null;
return orbs.get((cycleticks / 48) % orbs.size()).stack;
}
}
@Override
public TemplateRecipeHandler newInstance() {
for (ItemStack item : ItemList.items) {
if (item != null && item.getItem() instanceof IBloodOrb) {
bloodOrbs.add(item.getItem());
}
}
return super.newInstance();
}
@Override
public String getOverlayIdentifier() {
return "alchemicalwizardry.alchemy";
}
@Override
public void loadTransferRects() {
transferRects.add(new RecipeTransferRect(new Rectangle(134, 22, 16, 24), "alchemicalwizardry.alchemy"));
}
@Override
public Class<? extends GuiContainer> getGuiClass() {
return GuiWritingTable.class;
}
@Override
public void loadCraftingRecipes(String outputId, Object... results) {
if (outputId.equals("alchemicalwizardry.alchemy") && getClass() == NEIAlchemyRecipeHandler.class) {
for (AlchemyRecipe recipe : AlchemyRecipeRegistry.recipes) {
if (recipe.getResult() != null) arecipes.add(new CachedAlchemyRecipe(recipe));
}
} else {
super.loadCraftingRecipes(outputId, results);
}
}
@Override
public void loadCraftingRecipes(ItemStack result) {
for (AlchemyRecipe recipe : AlchemyRecipeRegistry.recipes) {
if (recipe == null) continue;
ItemStack output = recipe.getResult();
if (NEIServerUtils.areStacksSameTypeCrafting(result, recipe.getResult())) {
arecipes.add(new CachedAlchemyRecipe(recipe));
}
}
}
@Override
public void loadUsageRecipes(ItemStack ingredient) {
if (ingredient.getItem() instanceof IBloodOrb) {
for (AlchemyRecipe recipe : AlchemyRecipeRegistry.recipes) {
if (recipe == null) continue;
if (((IBloodOrb) ingredient.getItem()).getOrbLevel() >= recipe.getOrbLevel()) {
arecipes.add(new CachedAlchemyRecipe(recipe, ingredient));
}
}
} else {
for (AlchemyRecipe recipe : AlchemyRecipeRegistry.recipes) {
if (recipe == null) continue;
ItemStack[] stacks = recipe.getRecipe();
for (ItemStack stack : stacks) {
if (NEIServerUtils.areStacksSameTypeCrafting(stack, ingredient)) {
arecipes.add(new CachedAlchemyRecipe(recipe));
break;
}
}
}
}
}
@Override
public void drawExtras(int id) {
CachedAlchemyRecipe cache = (CachedAlchemyRecipe) arecipes.get(id);
Minecraft.getMinecraft().fontRenderer.drawString("\u00a77" + cache.lp + "LP", getLPX(cache.lp), 34, 0);
}
public int getLPX(int lp) {
if (lp < 10) return 122;
else if (lp < 100) return 122;
else if (lp < 1000) return 130;
else if (lp < 10000) return 127;
else if (lp < 100000) return 124;
return 122;
}
@Override
public String getRecipeName() {
return StatCollector.translateToLocal("tile.blockWritingTable.name");
}
@Override
public String getGuiTexture() {
return new ResourceLocation("alchemicalwizardry", "gui/nei/alchemy.png").toString();
}
}

View file

@ -1,4 +1,4 @@
package joshie.alchemicalWizardy.nei;
package WayofTime.alchemicalWizardry.client.nei;
import java.awt.Dimension;
import java.awt.Point;
@ -21,6 +21,9 @@ import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.GuiRecipe;
import codechicken.nei.recipe.TemplateRecipeHandler;
/**
* NEI Altar Recipe Handler by joshie *
*/
public class NEIAltarRecipeHandler extends TemplateRecipeHandler {
public class CachedAltarRecipe extends CachedRecipe {
PositionedStack input;
@ -49,9 +52,9 @@ public class NEIAltarRecipeHandler extends TemplateRecipeHandler {
@Override
public void loadCraftingRecipes(String outputId, Object... results) {
if (outputId.equals("altarrecipes") && getClass() == NEIAltarRecipeHandler.class) {
if (outputId.equals("alchemicalwizardry.altar") && getClass() == NEIAltarRecipeHandler.class) {
for(AltarRecipe recipe: AltarRecipeRegistry.altarRecipes) {
if(recipe.result != null) arecipes.add(new CachedAltarRecipe(recipe));
if(recipe != null && recipe.result != null) arecipes.add(new CachedAltarRecipe(recipe));
}
} else {
super.loadCraftingRecipes(outputId, results);
@ -62,7 +65,7 @@ public class NEIAltarRecipeHandler extends TemplateRecipeHandler {
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));
if(recipe != null && recipe.result != null) arecipes.add(new CachedAltarRecipe(recipe));
}
}
}
@ -71,7 +74,7 @@ public class NEIAltarRecipeHandler extends TemplateRecipeHandler {
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));
if(recipe != null && recipe.result != null) arecipes.add(new CachedAltarRecipe(recipe));
}
}
}
@ -150,7 +153,7 @@ public class NEIAltarRecipeHandler extends TemplateRecipeHandler {
@Override
public void loadTransferRects() {
transferRects.add(new RecipeTransferRect(new Rectangle(90, 32, 22, 16), "altarrecipes"));
transferRects.add(new RecipeTransferRect(new Rectangle(90, 32, 22, 16), "alchemicalwizardry.altar"));
}
@Override

View file

@ -1,21 +1,23 @@
package joshie.alchemicalWizardy.nei;
package WayofTime.alchemicalWizardry.client.nei;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.List;
import joshie.alchemicalWizardy.ShapedBloodOrbRecipe;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.util.StatCollector;
import WayofTime.alchemicalWizardry.api.items.ShapedBloodOrbRecipe;
import WayofTime.alchemicalWizardry.api.items.interfaces.IBloodOrb;
import codechicken.nei.NEIServerUtils;
import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.ShapedRecipeHandler;
/** Extended from the default recipe handler **/
/**
* NEI Blood Orb Shaped Recipe Handler by joshie *
*/
public class NEIBloodOrbShapedHandler extends ShapedRecipeHandler {
public class CachedBloodOrbRecipe extends CachedShapedRecipe {
public CachedBloodOrbRecipe(int width, int height, Object[] items, ItemStack out) {
@ -53,7 +55,7 @@ public class NEIBloodOrbShapedHandler extends ShapedRecipeHandler {
@Override
public void loadCraftingRecipes(String outputId, Object... results) {
if (outputId.equals("orbCrafting") && getClass() == NEIBloodOrbShapedHandler.class) {
if (outputId.equals("crafting") && getClass() == NEIBloodOrbShapedHandler.class) {
for (IRecipe irecipe : (List<IRecipe>) CraftingManager.getInstance().getRecipeList()) {
if (irecipe instanceof ShapedBloodOrbRecipe) {
CachedBloodOrbRecipe recipe = forgeShapedRecipe((ShapedBloodOrbRecipe) irecipe);
@ -124,12 +126,12 @@ public class NEIBloodOrbShapedHandler extends ShapedRecipeHandler {
@Override
public void loadTransferRects() {
transferRects.add(new RecipeTransferRect(new Rectangle(84, 23, 24, 18), "orbCrafting"));
transferRects.add(new RecipeTransferRect(new Rectangle(84, 23, 24, 18), "crafting"));
}
@Override
public String getOverlayIdentifier() {
return "orbCrafting";
return "crafting";
}
@Override

View file

@ -1,23 +1,23 @@
package joshie.alchemicalWizardy.nei;
package WayofTime.alchemicalWizardry.client.nei;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.List;
import joshie.alchemicalWizardy.ShapelessBloodOrbRecipe;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.ShapelessRecipes;
import net.minecraft.util.StatCollector;
import net.minecraftforge.oredict.ShapelessOreRecipe;
import WayofTime.alchemicalWizardry.api.items.ShapelessBloodOrbRecipe;
import WayofTime.alchemicalWizardry.api.items.interfaces.IBloodOrb;
import codechicken.nei.NEIServerUtils;
import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.ShapelessRecipeHandler;
import codechicken.nei.recipe.ShapelessRecipeHandler.CachedShapelessRecipe;
/**
* NEI Blood Orb Shapeless Recipe Handler by joshie *
*/
public class NEIBloodOrbShapelessHandler extends ShapelessRecipeHandler {
public class CachedBloodOrbRecipe extends CachedShapelessRecipe {
public CachedBloodOrbRecipe(ArrayList<Object> items, ItemStack recipeOutput) {
@ -51,7 +51,7 @@ public class NEIBloodOrbShapelessHandler extends ShapelessRecipeHandler {
@Override
public void loadCraftingRecipes(String outputId, Object... results) {
if (outputId.equals("orbCrafting") && getClass() == NEIBloodOrbShapelessHandler.class) {
if (outputId.equals("crafting") && getClass() == NEIBloodOrbShapelessHandler.class) {
List<IRecipe> allrecipes = CraftingManager.getInstance().getRecipeList();
for (IRecipe irecipe : allrecipes) {
CachedBloodOrbRecipe recipe = null;
@ -115,12 +115,12 @@ public class NEIBloodOrbShapelessHandler extends ShapelessRecipeHandler {
@Override
public void loadTransferRects() {
transferRects.add(new RecipeTransferRect(new Rectangle(84, 23, 24, 18), "orbCrafting"));
transferRects.add(new RecipeTransferRect(new Rectangle(84, 23, 24, 18), "crafting"));
}
@Override
public String getOverlayIdentifier() {
return "orbCrafting";
return "crafting";
}
@Override

View file

@ -1,4 +1,4 @@
package joshie.alchemicalWizardy.nei;
package WayofTime.alchemicalWizardry.client.nei;
import java.util.ArrayList;
@ -28,6 +28,6 @@ public class NEIConfig implements IConfigureNEI {
@Override
public String getVersion() {
return "1.2";
return "1.3";
}
}

View file

@ -1,227 +0,0 @@
package joshie.alchemicalWizardy;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import net.minecraft.block.Block;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.ShapedRecipes;
import net.minecraft.world.World;
import net.minecraftforge.oredict.OreDictionary;
import WayofTime.alchemicalWizardry.api.items.interfaces.IBloodOrb;
/** Shaped Blood Orb Recipe Handler by joshie **/
public class ShapedBloodOrbRecipe implements IRecipe {
private static final int MAX_CRAFT_GRID_WIDTH = 3;
private static final int MAX_CRAFT_GRID_HEIGHT = 3;
private ItemStack output = null;
private Object[] input = null;
public int width = 0;
public int height = 0;
private boolean mirrored = true;
public ShapedBloodOrbRecipe(Block result, Object... recipe) {
this(new ItemStack(result), recipe);
}
public ShapedBloodOrbRecipe(Item result, Object... recipe) {
this(new ItemStack(result), recipe);
}
public ShapedBloodOrbRecipe(ItemStack result, Object... recipe) {
output = result.copy();
String shape = "";
int idx = 0;
if (recipe[idx] instanceof Boolean) {
mirrored = (Boolean) recipe[idx];
if (recipe[idx + 1] instanceof Object[]) {
recipe = (Object[]) recipe[idx + 1];
} else {
idx = 1;
}
}
if (recipe[idx] instanceof String[]) {
String[] parts = ((String[]) recipe[idx++]);
for (String s : parts) {
width = s.length();
shape += s;
}
height = parts.length;
} else {
while (recipe[idx] instanceof String) {
String s = (String) recipe[idx++];
shape += s;
width = s.length();
height++;
}
}
if (width * height != shape.length()) {
String ret = "Invalid shaped ore recipe: ";
for (Object tmp : recipe) {
ret += tmp + ", ";
}
ret += output;
throw new RuntimeException(ret);
}
HashMap<Character, Object> itemMap = new HashMap<Character, Object>();
for (; idx < recipe.length; idx += 2) {
Character chr = (Character) recipe[idx];
Object in = recipe[idx + 1];
if (in instanceof IBloodOrb || (in instanceof ItemStack && ((ItemStack)in).getItem() instanceof IBloodOrb)) { //If the item is an instanceof IBloodOrb then save the level of the orb
if(in instanceof ItemStack) itemMap.put(chr, (Integer)(((IBloodOrb)((ItemStack)in).getItem()).getOrbLevel()));
else itemMap.put(chr, (Integer)(((IBloodOrb)in).getOrbLevel()));
} else if (in instanceof ItemStack) {
itemMap.put(chr, ((ItemStack) in).copy());
} else if (in instanceof Item) {
itemMap.put(chr, new ItemStack((Item) in));
} else if (in instanceof Block) {
itemMap.put(chr, new ItemStack((Block) in, 1, OreDictionary.WILDCARD_VALUE));
} else if (in instanceof String) {
itemMap.put(chr, OreDictionary.getOres((String) in));
} else {
String ret = "Invalid shaped ore recipe: ";
for (Object tmp : recipe) {
ret += tmp + ", ";
}
ret += output;
throw new RuntimeException(ret);
}
}
input = new Object[width * height];
int x = 0;
for (char chr : shape.toCharArray()) {
input[x++] = itemMap.get(chr);
}
}
ShapedBloodOrbRecipe(ShapedRecipes recipe, Map<ItemStack, String> replacements) {
output = recipe.getRecipeOutput();
width = recipe.recipeWidth;
height = recipe.recipeHeight;
input = new Object[recipe.recipeItems.length];
for (int i = 0; i < input.length; i++) {
ItemStack ingred = recipe.recipeItems[i];
if (ingred == null)
continue;
input[i] = recipe.recipeItems[i];
for (Entry<ItemStack, String> replace : replacements.entrySet()) {
if (OreDictionary.itemMatches(replace.getKey(), ingred, true)) {
input[i] = OreDictionary.getOres(replace.getValue());
break;
}
}
}
}
@Override
public ItemStack getCraftingResult(InventoryCrafting var1) {
return output.copy();
}
@Override
public int getRecipeSize() {
return input.length;
}
@Override
public ItemStack getRecipeOutput() {
return output;
}
@Override
public boolean matches(InventoryCrafting inv, World world) {
for (int x = 0; x <= MAX_CRAFT_GRID_WIDTH - width; x++) {
for (int y = 0; y <= MAX_CRAFT_GRID_HEIGHT - height; ++y) {
if (checkMatch(inv, x, y, false)) {
return true;
}
if (mirrored && checkMatch(inv, x, y, true)) {
return true;
}
}
}
return false;
}
@SuppressWarnings("unchecked")
private boolean checkMatch(InventoryCrafting inv, int startX, int startY, boolean mirror) {
for (int x = 0; x < MAX_CRAFT_GRID_WIDTH; x++) {
for (int y = 0; y < MAX_CRAFT_GRID_HEIGHT; y++) {
int subX = x - startX;
int subY = y - startY;
Object target = null;
if (subX >= 0 && subY >= 0 && subX < width && subY < height) {
if (mirror) {
target = input[width - subX - 1 + subY * width];
} else {
target = input[subX + subY * width];
}
}
ItemStack slot = inv.getStackInRowAndColumn(x, y);
//If target is integer, then we should be check the blood orb value of the item instead
if(target instanceof Integer) {
if(slot != null && slot.getItem() instanceof IBloodOrb) {
IBloodOrb orb = (IBloodOrb) slot.getItem();
if(orb.getOrbLevel() < (Integer)target) {
return false;
}
} else return false;
} else if (target instanceof ItemStack) {
if (!OreDictionary.itemMatches((ItemStack) target, slot, false)) {
return false;
}
} else if (target instanceof ArrayList) {
boolean matched = false;
Iterator<ItemStack> itr = ((ArrayList<ItemStack>) target).iterator();
while (itr.hasNext() && !matched) {
matched = OreDictionary.itemMatches(itr.next(), slot, false);
}
if (!matched) {
return false;
}
} else if (target == null && slot != null) {
return false;
}
}
}
return true;
}
public ShapedBloodOrbRecipe setMirrored(boolean mirror) {
mirrored = mirror;
return this;
}
public Object[] getInput() {
return this.input;
}
}

View file

@ -1,140 +0,0 @@
package joshie.alchemicalWizardy;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import net.minecraft.block.Block;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.ShapelessRecipes;
import net.minecraft.world.World;
import net.minecraftforge.oredict.OreDictionary;
import WayofTime.alchemicalWizardry.api.items.interfaces.IBloodOrb;
/** Shapeless Blood Orb Recipe Handler by joshie **/
public class ShapelessBloodOrbRecipe implements IRecipe {
private ItemStack output = null;
private ArrayList<Object> input = new ArrayList<Object>();
public ShapelessBloodOrbRecipe(Block result, Object... recipe) {
this(new ItemStack(result), recipe);
}
public ShapelessBloodOrbRecipe(Item result, Object... recipe) {
this(new ItemStack(result), recipe);
}
public ShapelessBloodOrbRecipe(ItemStack result, Object... recipe) {
output = result.copy();
for (Object in : recipe) {
if (in instanceof ItemStack) {
input.add(((ItemStack) in).copy());
} else if (in instanceof IBloodOrb) { //If the item is an instanceof IBloodOrb then save the level of the orb
input.add((Integer)(((IBloodOrb)in).getOrbLevel()));
} else if (in instanceof Item) {
input.add(new ItemStack((Item) in));
} else if (in instanceof Block) {
input.add(new ItemStack((Block) in));
} else if (in instanceof String) {
input.add(OreDictionary.getOres((String) in));
} else {
String ret = "Invalid shapeless ore recipe: ";
for (Object tmp : recipe) {
ret += tmp + ", ";
}
ret += output;
throw new RuntimeException(ret);
}
}
}
@SuppressWarnings("unchecked")
ShapelessBloodOrbRecipe(ShapelessRecipes recipe, Map<ItemStack, String> replacements) {
output = recipe.getRecipeOutput();
for (ItemStack ingred : ((List<ItemStack>) recipe.recipeItems)) {
Object finalObj = ingred;
for (Entry<ItemStack, String> replace : replacements.entrySet()) {
if (OreDictionary.itemMatches(replace.getKey(), ingred, false)) {
finalObj = OreDictionary.getOres(replace.getValue());
break;
}
}
input.add(finalObj);
}
}
@Override
public int getRecipeSize() {
return input.size();
}
@Override
public ItemStack getRecipeOutput() {
return output;
}
@Override
public ItemStack getCraftingResult(InventoryCrafting var1) {
return output.copy();
}
@SuppressWarnings("unchecked")
@Override
public boolean matches(InventoryCrafting var1, World world) {
ArrayList<Object> required = new ArrayList<Object>(input);
for (int x = 0; x < var1.getSizeInventory(); x++) {
ItemStack slot = var1.getStackInSlot(x);
if (slot != null) {
boolean inRecipe = false;
Iterator<Object> req = required.iterator();
while (req.hasNext()) {
boolean match = false;
Object next = req.next();
//If target is integer, then we should be check the blood orb value of the item instead
if(next instanceof Integer) {
if(slot != null && slot.getItem() instanceof IBloodOrb) {
IBloodOrb orb = (IBloodOrb) slot.getItem();
if(orb.getOrbLevel() < (Integer)next) {
return false;
}
} else return false;
} else if (next instanceof ItemStack) {
match = OreDictionary.itemMatches((ItemStack) next, slot, false);
} else if (next instanceof ArrayList) {
Iterator<ItemStack> itr = ((ArrayList<ItemStack>) next).iterator();
while (itr.hasNext() && !match) {
match = OreDictionary.itemMatches(itr.next(), slot, false);
}
}
if (match) {
inRecipe = true;
required.remove(next);
break;
}
}
if (!inRecipe) {
return false;
}
}
}
return required.isEmpty();
}
public ArrayList<Object> getInput() {
return this.input;
}
}

View file

@ -1,154 +0,0 @@
package joshie.alchemicalWizardy.nei;
import static joshie.alchemicalWizardy.nei.NEIConfig.bloodOrbs;
import java.util.ArrayList;
import java.util.List;
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.api.alchemy.AlchemyRecipe;
import WayofTime.alchemicalWizardry.api.alchemy.AlchemyRecipeRegistry;
import WayofTime.alchemicalWizardry.api.items.interfaces.IBloodOrb;
import codechicken.nei.ItemList;
import codechicken.nei.NEIServerUtils;
import codechicken.nei.PositionedStack;
import codechicken.nei.recipe.TemplateRecipeHandler;
import codechicken.nei.recipe.TemplateRecipeHandler.CachedRecipe;
public class NEIAlchemyRecipeHandler extends TemplateRecipeHandler {
public class CachedAlchemyRecipe extends CachedRecipe {
public class BloodOrbs {
public PositionedStack stack;
public BloodOrbs(ItemStack orb) {
this.stack = new PositionedStack(orb, 136, 47, false);
}
}
ArrayList<BloodOrbs> orbs;
PositionedStack output;
List<PositionedStack> inputs;
int lp;
public CachedAlchemyRecipe(AlchemyRecipe recipe, ItemStack orb) {
this(recipe);
this.orbs = new ArrayList<BloodOrbs>();
orbs.add(new BloodOrbs(orb));
}
public CachedAlchemyRecipe(AlchemyRecipe recipe) {
List<PositionedStack> inputs = new ArrayList<PositionedStack>();
ItemStack[] stacks = recipe.getRecipe();
if(stacks.length > 0)
inputs.add(new PositionedStack(stacks[0], 76, 3));
if(stacks.length > 1)
inputs.add(new PositionedStack(stacks[1], 51, 19));
if(stacks.length > 2)
inputs.add(new PositionedStack(stacks[2], 101, 19));
if(stacks.length > 3)
inputs.add(new PositionedStack(stacks[3], 64, 47));
if(stacks.length > 4)
inputs.add(new PositionedStack(stacks[4], 88, 47));
this.inputs = inputs;
this.output = new PositionedStack(recipe.getResult(), 76, 25);
this.lp = recipe.getAmountNeeded() * 100;
this.orbs = new ArrayList<BloodOrbs>();
for(Item orb: bloodOrbs) {
if(((IBloodOrb)orb).getOrbLevel() >= recipe.getOrbLevel()) {
orbs.add(new BloodOrbs(new ItemStack(orb)));
}
}
}
@Override
public List<PositionedStack> getIngredients() {
return inputs;
}
@Override
public PositionedStack getResult() {
return output;
}
@Override
public PositionedStack getOtherStack() {
if(orbs == null || orbs.size() <= 0) return null;
return orbs.get((cycleticks/48) % orbs.size()).stack;
}
}
@Override
public TemplateRecipeHandler newInstance() {
for(ItemStack item : ItemList.items) {
if(item != null && item.getItem() instanceof IBloodOrb) {
bloodOrbs.add(item.getItem());
}
}
return super.newInstance();
}
@Override
public void loadCraftingRecipes(ItemStack result) {
for(AlchemyRecipe recipe: AlchemyRecipeRegistry.recipes) {
ItemStack output = recipe.getResult();
if(NEIServerUtils.areStacksSameTypeCrafting(result, recipe.getResult())) {
arecipes.add(new CachedAlchemyRecipe(recipe));
}
}
}
@Override
public void loadUsageRecipes(ItemStack ingredient) {
if(ingredient.getItem() instanceof IBloodOrb) {
for(AlchemyRecipe recipe: AlchemyRecipeRegistry.recipes) {
if(((IBloodOrb)ingredient.getItem()).getOrbLevel() >= recipe.getOrbLevel()) {
arecipes.add(new CachedAlchemyRecipe(recipe, ingredient));
}
}
} else {
for(AlchemyRecipe recipe: AlchemyRecipeRegistry.recipes) {
ItemStack[] stacks = recipe.getRecipe();
for(ItemStack stack: stacks) {
if(NEIServerUtils.areStacksSameTypeCrafting(stack, ingredient)) {
arecipes.add(new CachedAlchemyRecipe(recipe));
break;
}
}
}
}
}
@Override
public void drawExtras(int id) {
CachedAlchemyRecipe cache = (CachedAlchemyRecipe) arecipes.get(id);
Minecraft.getMinecraft().fontRenderer.drawString("\u00a77" + cache.lp + "LP", getLPX(cache.lp), 34, 0);
}
public int getLPX(int lp) {
if(lp < 10)
return 122;
else if (lp < 100)
return 122;
else if (lp < 1000)
return 130;
else if (lp < 10000)
return 127;
else if (lp < 100000)
return 124;
return 122;
}
@Override
public String getRecipeName() {
return StatCollector.translateToLocal("tile.blockWritingTable.name");
}
@Override
public String getGuiTexture() {
return new ResourceLocation("alchemicalwizardry", "gui/nei/alchemy.png").toString();
}
}