Removing the use of the recipe loader for small items

It seems the recipe loader is defective for recipes under a set size. I
can't pin down what is wrong so for the moment i am switching some
recipes back to the old Mc system. This way i know they function and
don't have to worry about them.
This commit is contained in:
DarkGuardsman 2013-10-28 17:17:19 -04:00
parent 0afd6d0fba
commit ae4e57c6e5
4 changed files with 204 additions and 109 deletions

View file

@ -5,7 +5,7 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemTool; import net.minecraft.item.ItemTool;
import net.minecraft.item.crafting.FurnaceRecipes; import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraftforge.oredict.OreDictionary; import net.minecraftforge.oredict.ShapedOreRecipe;
import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.GameRegistry;
import dark.api.ColorCode; import dark.api.ColorCode;
import dark.api.ProcessorRecipes; import dark.api.ProcessorRecipes;
@ -16,6 +16,7 @@ import dark.core.common.blocks.BlockOre.OreData;
import dark.core.common.items.EnumMaterial; import dark.core.common.items.EnumMaterial;
import dark.core.common.items.EnumOrePart; import dark.core.common.items.EnumOrePart;
import dark.core.common.items.EnumTool; import dark.core.common.items.EnumTool;
import dark.core.common.items.ItemCommonTool;
import dark.core.common.items.ItemOreDirv; import dark.core.common.items.ItemOreDirv;
import dark.core.common.items.ItemParts; import dark.core.common.items.ItemParts;
import dark.core.common.items.ItemParts.Parts; import dark.core.common.items.ItemParts.Parts;
@ -43,6 +44,7 @@ public class CoreRecipeLoader extends RecipeLoader
public static ItemStack unfinishedTank; public static ItemStack unfinishedTank;
public static Item itemGlowingSand; public static Item itemGlowingSand;
public static Item itemDiggingTool; public static Item itemDiggingTool;
public static boolean debugOreItems = true;
@Override @Override
public void loadRecipes() public void loadRecipes()
@ -64,6 +66,19 @@ public class CoreRecipeLoader extends RecipeLoader
{ {
new RecipeGrid(new ItemStack(blockWire, 1, 0), 3, 3).setRowOne(Block.cloth, Block.cloth, Block.cloth).setRowTwo(copper, copper, copper).setRowThree(Block.cloth, Block.cloth, Block.cloth).RegisterRecipe(); new RecipeGrid(new ItemStack(blockWire, 1, 0), 3, 3).setRowOne(Block.cloth, Block.cloth, Block.cloth).setRowTwo(copper, copper, copper).setRowThree(Block.cloth, Block.cloth, Block.cloth).RegisterRecipe();
} }
if (itemDiggingTool instanceof ItemCommonTool)
{
for (EnumMaterial mat : EnumMaterial.values())
{
if (mat.shouldCreateTool())
{
new RecipeGrid(mat.getTool(EnumTool.PICKAX)).setRowOne(mat.getStack(EnumOrePart.INGOTS, 1), mat.getStack(EnumOrePart.INGOTS, 1), mat.getStack(EnumOrePart.INGOTS, 1)).setRowTwo(null, Item.stick, null).setRowThree(null, Item.stick, null).RegisterRecipe();
new RecipeGrid(mat.getTool(EnumTool.AX)).setRowOne(mat.getStack(EnumOrePart.INGOTS, 1), mat.getStack(EnumOrePart.INGOTS, 1), null).setRowTwo(mat.getStack(EnumOrePart.INGOTS, 1), Item.stick, null).setRowThree(null, Item.stick, null).RegisterRecipe();
new RecipeGrid(mat.getTool(EnumTool.HOE)).setRowOne(mat.getStack(EnumOrePart.INGOTS, 1), mat.getStack(EnumOrePart.INGOTS, 1), null).setRowTwo(null, Item.stick, null).setRowThree(null, Item.stick, null).RegisterRecipe();
new RecipeGrid(mat.getTool(EnumTool.SPADE)).setRowOne(null, mat.getStack(EnumOrePart.INGOTS, 1), null).setRowTwo(null, Item.stick, null).setRowThree(null, Item.stick, null).RegisterRecipe();
}
}
}
this.loadParts(); this.loadParts();
} }
@ -77,7 +92,7 @@ public class CoreRecipeLoader extends RecipeLoader
unfinishedTank = new ItemStack(itemParts, 1, Parts.Tank.ordinal()); unfinishedTank = new ItemStack(itemParts, 1, Parts.Tank.ordinal());
// seal // seal
new RecipeGrid(this.setStackSize(leatherSeal, 16), 2, 2).setRowOne(Item.leather, Item.leather).setRowTwo(Item.leather, Item.leather).RegisterRecipe(); GameRegistry.addRecipe(new ShapedOreRecipe(this.setStackSize(leatherSeal, 16), new Object[] { "LL","LL", 'L', Item.leather }));
// slime steal // slime steal
new RecipeGrid(this.setStackSize(slimeSeal, 4)).setRowOne(null, leatherSeal, null).setRowTwo(leatherSeal, Item.slimeBall, leatherSeal).setRowThree(null, leatherSeal, null).RegisterRecipe(); new RecipeGrid(this.setStackSize(slimeSeal, 4)).setRowOne(null, leatherSeal, null).setRowTwo(leatherSeal, Item.slimeBall, leatherSeal).setRowThree(null, leatherSeal, null).RegisterRecipe();
// part valve // part valve
@ -117,16 +132,25 @@ public class CoreRecipeLoader extends RecipeLoader
GameRegistry.addShapelessRecipe(EnumMaterial.getStack(EnumMaterial.STEEL, EnumOrePart.DUST, 1), new Object[] { EnumMaterial.getStack(EnumMaterial.IRON, EnumOrePart.DUST, 1), new ItemStack(Item.coal, 1, 1), new ItemStack(Item.coal, 1, 0) }); GameRegistry.addShapelessRecipe(EnumMaterial.getStack(EnumMaterial.STEEL, EnumOrePart.DUST, 1), new Object[] { EnumMaterial.getStack(EnumMaterial.IRON, EnumOrePart.DUST, 1), new ItemStack(Item.coal, 1, 1), new ItemStack(Item.coal, 1, 0) });
GameRegistry.addShapelessRecipe(EnumMaterial.getStack(EnumMaterial.BRONZE, EnumOrePart.DUST, 4), new Object[] { EnumMaterial.getStack(EnumMaterial.COPPER, EnumOrePart.DUST, 1), EnumMaterial.getStack(EnumMaterial.COPPER, EnumOrePart.DUST, 1), EnumMaterial.getStack(EnumMaterial.COPPER, EnumOrePart.DUST, 1), EnumMaterial.getStack(EnumMaterial.TIN, EnumOrePart.DUST, 1) }); GameRegistry.addShapelessRecipe(EnumMaterial.getStack(EnumMaterial.BRONZE, EnumOrePart.DUST, 4), new Object[] { EnumMaterial.getStack(EnumMaterial.COPPER, EnumOrePart.DUST, 1), EnumMaterial.getStack(EnumMaterial.COPPER, EnumOrePart.DUST, 1), EnumMaterial.getStack(EnumMaterial.COPPER, EnumOrePart.DUST, 1), EnumMaterial.getStack(EnumMaterial.TIN, EnumOrePart.DUST, 1) });
if (debugOreItems)
{
System.out.println("\n\nTesting material part returns");
for (EnumMaterial mat : EnumMaterial.values())
{
System.out.println("\n-Material-> " + mat.simpleName);
for (EnumOrePart part : EnumOrePart.values())
{
if (mat.shouldCreateItem(part))
{
System.out.println("--Part-> " + part.simpleName);
System.out.println("----ItemStack-> " + mat.getStack(part, 1).toString());
}
}
}
}
//Ore material recipe loop //Ore material recipe loop
for (EnumMaterial mat : EnumMaterial.values()) for (EnumMaterial mat : EnumMaterial.values())
{ {
if (mat.shouldCreateTool())
{
new RecipeGrid(mat.getTool(EnumTool.PICKAX)).setRowOne(mat.getStack(EnumOrePart.INGOTS, 1), mat.getStack(EnumOrePart.INGOTS, 1), mat.getStack(EnumOrePart.INGOTS, 1)).setRowTwo(null, Item.stick, null).setRowThree(null, Item.stick, null).RegisterRecipe();
new RecipeGrid(mat.getTool(EnumTool.AX)).setRowOne(mat.getStack(EnumOrePart.INGOTS, 1), mat.getStack(EnumOrePart.INGOTS, 1), null).setRowTwo(mat.getStack(EnumOrePart.INGOTS, 1), Item.stick, null).setRowThree(null, Item.stick, null).RegisterRecipe();
new RecipeGrid(mat.getTool(EnumTool.HOE)).setRowOne(mat.getStack(EnumOrePart.INGOTS, 1), mat.getStack(EnumOrePart.INGOTS, 1), null).setRowTwo(null, Item.stick, null).setRowThree(null, Item.stick, null).RegisterRecipe();
new RecipeGrid(mat.getTool(EnumTool.SPADE)).setRowOne(null, mat.getStack(EnumOrePart.INGOTS, 1), null).setRowTwo(null, Item.stick, null).setRowThree(null, Item.stick, null).RegisterRecipe();
}
//Dust recipes //Dust recipes
if (mat.shouldCreateItem(EnumOrePart.DUST)) if (mat.shouldCreateItem(EnumOrePart.DUST))
{ {
@ -155,17 +179,20 @@ public class CoreRecipeLoader extends RecipeLoader
} }
if (mat.shouldCreateItem(EnumOrePart.TUBE)) if (mat.shouldCreateItem(EnumOrePart.TUBE))
{ {
new RecipeGrid(mat.getStack(EnumOrePart.TUBE, 1), 3, 1).setRowOne(mat.getStack(EnumOrePart.INGOTS, 1), mat.getStack(EnumOrePart.INGOTS, 1), mat.getStack(EnumOrePart.INGOTS, 1)).RegisterRecipe(); GameRegistry.addRecipe(new ShapedOreRecipe(mat.getStack(EnumOrePart.TUBE, 6), new Object[] { "III", 'I', mat.simpleName + "ingot" }));
new RecipeGrid(mat.getStack(EnumOrePart.TUBE, 1), 1, 1).setRowOne(mat.getStack(EnumOrePart.ROD, 1)).RegisterRecipe(); GameRegistry.addRecipe(new ShapedOreRecipe(mat.getStack(EnumOrePart.TUBE, 6), new Object[] { "III", 'I', "ingot" + mat.simpleName }));
GameRegistry.addRecipe(new ShapedOreRecipe(mat.getStack(EnumOrePart.TUBE, 1), new Object[] { "I", 'I', "rod" + mat.simpleName }));
GameRegistry.addRecipe(new ShapedOreRecipe(mat.getStack(EnumOrePart.TUBE, 1), new Object[] { "I", 'I', mat.simpleName + "rod" }));
} }
if (mat.shouldCreateItem(EnumOrePart.ROD)) if (mat.shouldCreateItem(EnumOrePart.ROD))
{ {
new RecipeGrid(mat.getStack(EnumOrePart.ROD, 1), 2, 1).setRowOne(mat.getStack(EnumOrePart.INGOTS, 1), mat.getStack(EnumOrePart.INGOTS, 1)).RegisterRecipe(); GameRegistry.addRecipe(new ShapedOreRecipe(mat.getStack(EnumOrePart.ROD, 4), new Object[] { "II", 'I', mat.simpleName + "rod" }));
GameRegistry.addRecipe(new ShapedOreRecipe(mat.getStack(EnumOrePart.ROD, 4), new Object[] { "II", 'I', "rod" + mat.simpleName }));
} }
if (mat.shouldCreateItem(EnumOrePart.PLATES)) if (mat.shouldCreateItem(EnumOrePart.PLATES))
{ {
new RecipeGrid(mat.getStack(EnumOrePart.PLATES, 1), 2, 2).setRowOne(mat.getStack(EnumOrePart.INGOTS, 1), mat.getStack(EnumOrePart.INGOTS, 1)).setRowTwo(mat.getStack(EnumOrePart.INGOTS, 1), mat.getStack(EnumOrePart.INGOTS, 1)).RegisterRecipe(); GameRegistry.addRecipe(new ShapedOreRecipe(mat.getStack(EnumOrePart.PLATES, 1), new Object[] { "II", "II", 'I', mat.simpleName + "ingot" }));
GameRegistry.addRecipe(new ShapedOreRecipe(mat.getStack(EnumOrePart.PLATES, 1), new Object[] { "II", "II", 'I', "ingot" + mat.simpleName }));
} }
if (mat.shouldCreateItem(EnumOrePart.GEARS)) if (mat.shouldCreateItem(EnumOrePart.GEARS))
{ {

View file

@ -142,66 +142,50 @@ public class DarkMain extends ModPrefab
} }
} }
} }
if (CoreRecipeLoader.blockWire instanceof BlockWire)
{
OreDictionary.registerOre("copperwire", new ItemStack(CoreRecipeLoader.blockWire, 1, 0));
OreDictionary.registerOre("wirecopper", new ItemStack(CoreRecipeLoader.blockWire, 1, 0));
}
if (CoreRecipeLoader.itemMetals instanceof ItemOreDirv) if (CoreRecipeLoader.itemMetals instanceof ItemOreDirv)
{ {
//Ore material recipe loop //Ore material recipe loop
for (EnumMaterial mat : EnumMaterial.values()) for (EnumMaterial mat : EnumMaterial.values())
{ {
ItemStack dust = EnumMaterial.getStack(mat, EnumOrePart.DUST, 1);
ItemStack ingot = EnumMaterial.getStack(mat, EnumOrePart.INGOTS, 1);
ItemStack scraps = EnumMaterial.getStack(mat, EnumOrePart.SCRAPS, 1);
ItemStack plates = EnumMaterial.getStack(mat, EnumOrePart.PLATES, 1);
ItemStack rubble = EnumMaterial.getStack(mat, EnumOrePart.RUBBLE, 1);
ItemStack rod = EnumMaterial.getStack(mat, EnumOrePart.ROD, 1);
ItemStack tube = EnumMaterial.getStack(mat, EnumOrePart.TUBE, 1);
if (mat.shouldCreateItem(EnumOrePart.INGOTS)) if (mat.shouldCreateItem(EnumOrePart.INGOTS))
{ {
OreDictionary.registerOre(mat.simpleName + "ingot", ingot); OreDictionary.registerOre(mat.simpleName + "ingot", mat.getStack(EnumOrePart.INGOTS, 1));
OreDictionary.registerOre("ingot" + mat.simpleName, ingot); OreDictionary.registerOre("ingot" + mat.simpleName, mat.getStack(EnumOrePart.INGOTS, 1));
} }
if (mat.shouldCreateItem(EnumOrePart.RUBBLE)) if (mat.shouldCreateItem(EnumOrePart.RUBBLE))
{ {
OreDictionary.registerOre(mat.simpleName + "rubble", rubble); OreDictionary.registerOre(mat.simpleName + "rubble", mat.getStack(EnumOrePart.RUBBLE, 1));
OreDictionary.registerOre("rubble" + mat.simpleName, rubble); OreDictionary.registerOre("rubble" + mat.simpleName, mat.getStack(EnumOrePart.RUBBLE, 1));
} }
//Dust recipes //Dust recipes
if (mat.shouldCreateItem(EnumOrePart.DUST)) if (mat.shouldCreateItem(EnumOrePart.DUST))
{ {
OreDictionary.registerOre(mat.simpleName + "dust", dust); OreDictionary.registerOre(mat.simpleName + "dust", mat.getStack(EnumOrePart.DUST, 1));
OreDictionary.registerOre("dust" + mat.simpleName, dust); OreDictionary.registerOre("dust" + mat.simpleName, mat.getStack(EnumOrePart.DUST, 1));
} }
// Salvaging recipe // Salvaging recipe
if (mat.shouldCreateItem(EnumOrePart.SCRAPS)) if (mat.shouldCreateItem(EnumOrePart.SCRAPS))
{ {
OreDictionary.registerOre(mat.simpleName + "scraps", scraps); OreDictionary.registerOre(mat.simpleName + "scraps", mat.getStack(EnumOrePart.SCRAPS, 1));
OreDictionary.registerOre("scraps" + mat.simpleName, scraps); OreDictionary.registerOre("scraps" + mat.simpleName, mat.getStack(EnumOrePart.SCRAPS, 1));
} }
ingot.stackSize = 1;
if (mat.shouldCreateItem(EnumOrePart.TUBE)) if (mat.shouldCreateItem(EnumOrePart.TUBE))
{ {
OreDictionary.registerOre(mat.simpleName + "tube", tube); OreDictionary.registerOre(mat.simpleName + "tube", mat.getStack(EnumOrePart.TUBE, 1));
OreDictionary.registerOre("tube" + mat.simpleName, tube); OreDictionary.registerOre("tube" + mat.simpleName, mat.getStack(EnumOrePart.TUBE, 1));
} }
if (mat.shouldCreateItem(EnumOrePart.ROD)) if (mat.shouldCreateItem(EnumOrePart.ROD))
{ {
OreDictionary.registerOre(mat.simpleName + "rod", rod); OreDictionary.registerOre(mat.simpleName + "rod", mat.getStack(EnumOrePart.ROD, 1));
OreDictionary.registerOre("rod" + mat.simpleName, rod); OreDictionary.registerOre("rod" + mat.simpleName, mat.getStack(EnumOrePart.ROD, 1));
} }
if (mat.shouldCreateItem(EnumOrePart.PLATES)) if (mat.shouldCreateItem(EnumOrePart.PLATES))
{ {
OreDictionary.registerOre(mat.simpleName + "plate", plates); OreDictionary.registerOre(mat.simpleName + "plate", mat.getStack(EnumOrePart.PLATES, 1));
OreDictionary.registerOre("plate" + mat.simpleName, plates); OreDictionary.registerOre("plate" + mat.simpleName, mat.getStack(EnumOrePart.PLATES, 1));
} }
if (mat.shouldCreateItem(EnumOrePart.GEARS)) if (mat.shouldCreateItem(EnumOrePart.GEARS))
{ {

View file

@ -10,9 +10,10 @@ import com.builtbroken.common.Pair;
import com.builtbroken.common.Triple; import com.builtbroken.common.Triple;
import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.GameRegistry;
import dark.core.prefab.helpers.AutoCraftingManager;
/** Recipe system to make it easier to load recipes for a mod /** Recipe system to make it easier to load recipes for a mod
* *
* @author DarkGuardsman */ * @author DarkGuardsman */
public abstract class RecipeLoader public abstract class RecipeLoader
{ {
@ -97,19 +98,20 @@ public abstract class RecipeLoader
} }
/** An easier to read recipe system for the basic minecraft recipes /** An easier to read recipe system for the basic minecraft recipes
* *
* @author DarkGaurdsman */ * @author DarkGaurdsman */
@Deprecated
public static class RecipeGrid public static class RecipeGrid
{ {
Object[] rl = new Object[9]; Object[] items = new Object[9];
Object out; Object output;
int width = 3; int width = 3;
int hight = 3; int hight = 3;
/** @param stack - output item */ /** @param stack - output item */
public RecipeGrid(Object stack) public RecipeGrid(Object stack)
{ {
out = stack; output = stack;
} }
/** @param stack - output item /** @param stack - output item
@ -123,7 +125,7 @@ public abstract class RecipeLoader
/** 3x3 Crafting grid. Each Triple is a row. Input for the triples should be any of { Item, /** 3x3 Crafting grid. Each Triple is a row. Input for the triples should be any of { Item,
* Block, ItemStack, String} * Block, ItemStack, String}
* *
* @param one - top row * @param one - top row
* @param two - middle row * @param two - middle row
* @param three - bottom row */ * @param three - bottom row */
@ -137,7 +139,7 @@ public abstract class RecipeLoader
/** 2x2 Crafting grid. Each Pair is a row. Input for the pairs should be any of { Item, /** 2x2 Crafting grid. Each Pair is a row. Input for the pairs should be any of { Item,
* Block, ItemStack, String} * Block, ItemStack, String}
* *
* @param one - top row * @param one - top row
* @param two - middle row */ * @param two - middle row */
public RecipeGrid(Object stack, Pair one, Pair two) public RecipeGrid(Object stack, Pair one, Pair two)
@ -160,7 +162,7 @@ public abstract class RecipeLoader
/** Sets the grid recipe output */ /** Sets the grid recipe output */
public RecipeGrid setOutput(Object stack) public RecipeGrid setOutput(Object stack)
{ {
out = stack; output = stack;
return this; return this;
} }
@ -168,14 +170,14 @@ public abstract class RecipeLoader
{ {
if (objects != null) if (objects != null)
{ {
this.rl[0] = objects[0]; this.items[0] = objects[0];
if (objects.length > 1) if (objects.length > 1)
{ {
this.rl[1] = objects[1]; this.items[1] = objects[1];
} }
if (objects.length > 2) if (objects.length > 2)
{ {
this.rl[2] = objects[2]; this.items[2] = objects[2];
} }
} }
return this; return this;
@ -185,14 +187,14 @@ public abstract class RecipeLoader
{ {
if (objects != null) if (objects != null)
{ {
this.rl[3] = objects[0]; this.items[3] = objects[0];
if (objects.length > 1) if (objects.length > 1)
{ {
this.rl[4] = objects[1]; this.items[4] = objects[1];
} }
if (objects.length > 2) if (objects.length > 2)
{ {
this.rl[5] = objects[2]; this.items[5] = objects[2];
} }
} }
return this; return this;
@ -202,14 +204,14 @@ public abstract class RecipeLoader
{ {
if (objects != null) if (objects != null)
{ {
this.rl[6] = objects[0]; this.items[6] = objects[0];
if (objects.length > 1) if (objects.length > 1)
{ {
this.rl[7] = objects[1]; this.items[7] = objects[1];
} }
if (objects.length > 2) if (objects.length > 2)
{ {
this.rl[8] = objects[2]; this.items[8] = objects[2];
} }
} }
return this; return this;
@ -226,90 +228,105 @@ public abstract class RecipeLoader
public void RegisterRecipe() public void RegisterRecipe()
{ {
ShapedOreRecipe receipe = this.getShapedRecipe(); ShapedOreRecipe shapedOreRecipe = null;
if (receipe != null)
{
GameRegistry.addRecipe(receipe);
}
}
public ShapedOreRecipe getShapedRecipe()
{
//TODO convert items to their ore names
ShapedOreRecipe re = null;
Object[] recipe = null; Object[] recipe = null;
String[] r = { "A", "B", "C", "D", "E", "F", "G", "H", "I" }; String[] slots = { "A", "B", "C", "D", "E", "F", "G", "H", "I" };
for (int i = 0; i < r.length; i++) for (int i = 0; i < slots.length; i++)
{ {
if (this.rl[i] == null || this.rl[i] instanceof String && ((String) this.rl[i]).isEmpty()) if (this.items[i] == null || this.items[i] instanceof String && ((String) this.items[i]).isEmpty())
{ {
r[i] = " "; slots[i] = " ";
this.rl[i] = ""; this.items[i] = "";
} }//TODO include normal items and blocks
else if (this.rl[i] instanceof ItemStack) else if (this.items[i] instanceof ItemStack)
{ {
//Automatically converts an itemstack to its orename so that recipes are more mod compatible //Automatically converts an itemstack to its orename so that recipes are more mod compatible
String s = OreDictionary.getOreName(OreDictionary.getOreID((ItemStack) this.rl[i])); String s = OreDictionary.getOreName(OreDictionary.getOreID((ItemStack) this.items[i]));
if (s != null) if (s != null && !s.equals("Unknown"))
{ {
this.rl[i] = s; this.items[i] = s;
} }
} }
} }
if (width == 3 && hight == 3) if (width == 3 && hight == 3)
{ {
recipe = new Object[] { r[0] + r[1] + r[2], r[3] + r[4] + r[5], r[6] + r[7] + r[8], 'A', rl[0], 'B', rl[1], 'C', rl[2], 'D', rl[3], 'E', rl[4], 'F', rl[5], 'G', rl[6], 'H', rl[7], 'I', rl[8] }; recipe = new Object[] { slots[0] + slots[1] + slots[2], slots[3] + slots[4] + slots[5], slots[6] + slots[7] + slots[8], 'A', items[0], 'B', items[1], 'C', items[2], 'D', items[3], 'E', items[4], 'F', items[5], 'G', items[6], 'H', items[7], 'I', items[8] };
} }
else if (width == 2 && hight == 3) else if (width == 2 && hight == 3)
{ {
recipe = new Object[] { r[0] + r[1], r[3] + r[4], r[6] + r[7], 'A', rl[0], 'B', rl[1], 'D', rl[3], 'E', rl[4], 'G', rl[6], 'H', rl[7] }; recipe = new Object[] { slots[0] + slots[1], slots[3] + slots[4], slots[6] + slots[7], 'A', items[0], 'B', items[1], 'D', items[3], 'E', items[4], 'G', items[6], 'H', items[7] };
} }
else if (width == 3 && hight == 2) else if (width == 3 && hight == 2)
{ {
recipe = new Object[] { r[0] + r[1] + r[2], r[3] + r[4] + r[5], 'A', rl[0], 'B', rl[1], 'C', rl[2], 'D', rl[3], 'E', rl[4], 'F', rl[5] }; recipe = new Object[] { slots[0] + slots[1] + slots[2], slots[3] + slots[4] + slots[5], 'A', items[0], 'B', items[1], 'C', items[2], 'D', items[3], 'E', items[4], 'F', items[5] };
} }
else if (width == 1 && hight == 3) else if (width == 1 && hight == 3)
{ {
recipe = new Object[] { r[0], r[3], r[6], 'A', rl[0], 'D', rl[3], 'G', rl[6] }; recipe = new Object[] { slots[0], slots[3], slots[6], 'A', items[0], 'D', items[3], 'G', items[6] };
} }
else if (width == 3 && hight == 1) else if (width == 3 && hight == 1)
{ {
recipe = new Object[] { r[0] + r[1] + r[2], 'A', rl[0], 'B', rl[1], 'C', rl[2] }; recipe = new Object[] { slots[0] + slots[1] + slots[2], 'A', items[0], 'B', items[1], 'C', items[2] };
} }
else if (width == 2 && hight == 2) else if (width == 2 && hight == 2)
{ {
recipe = new Object[] { r[0] + r[1], r[3] + r[4], 'A', rl[0], 'B', rl[1], 'D', rl[2], 'E', rl[4] }; recipe = new Object[] { slots[0] + slots[1], slots[3] + slots[4], 'A', items[0], 'B', items[1], 'D', items[2], 'E', items[4] };
} }
else if (width == 1 && hight == 2) else if (width == 1 && hight == 2)
{ {
recipe = new Object[] { r[0], r[3], 'A', rl[0], 'D', rl[3], }; recipe = new Object[] { slots[0], slots[3], 'A', items[0], 'D', items[3], };
} }
else if (width == 2 && hight == 1) else if (width == 2 && hight == 1)
{ {
recipe = new Object[] { r[0] + r[1], 'A', rl[0], 'B', rl[1], }; recipe = new Object[] { slots[0] + slots[1], 'A', items[0], 'B', items[1], };
} }
else if (width == 1 && hight == 1) else if (width == 1 && hight == 1)
{ {
recipe = new Object[] { r[0], 'A', rl[0] }; recipe = new Object[] { slots[0], 'A', items[0] };
}
else
{
System.out.println("Recipe was created with an out of bounds size");
System.out.println(this.toString());
} }
if (recipe != null) if (recipe != null)
{ {
if (out instanceof Block) if (output instanceof Block)
{ {
re = new ShapedOreRecipe(((Block) out), recipe); shapedOreRecipe = new ShapedOreRecipe(((Block) output), recipe);
} }
else if (out instanceof Item) else if (output instanceof Item)
{ {
re = new ShapedOreRecipe(((Item) out), recipe); shapedOreRecipe = new ShapedOreRecipe(((Item) output), recipe);
} }
else if (out instanceof ItemStack) else if (output instanceof ItemStack)
{ {
re = new ShapedOreRecipe(((ItemStack) out), recipe); shapedOreRecipe = new ShapedOreRecipe(((ItemStack) output), recipe);
}
else
{
System.out.println("Recipe was created with a null output");
System.out.println(this.toString());
} }
} }
return re; if (CoreRecipeLoader.debugOreItems)
{
System.out.println("\nRecipe created");
System.out.println(this.toString());
AutoCraftingManager.printRecipes(shapedOreRecipe.getRecipeOutput());
}
if (shapedOreRecipe != null)
{
GameRegistry.addRecipe(shapedOreRecipe);
}
}
@Override
public String toString()
{
return "RecipeGrid[Out: " + (output != null ? output.toString() : "null") + "\n In: " + " " + items[0] + "| " + items[1] + "| " + items[2] + "\n " + items[3] + "| " + items[4] + "| " + items[5] + "\n " + items[6] + "| " + items[7] + "| " + items[8];
} }
} }
} }

View file

@ -23,7 +23,7 @@ import com.builtbroken.common.Pair;
import cpw.mods.fml.relauncher.ReflectionHelper; import cpw.mods.fml.relauncher.ReflectionHelper;
/** Rewrite of the imprinter crafting system into its own manageable class /** Rewrite of the imprinter crafting system into its own manageable class
* *
* @author DarkGuardsman */ * @author DarkGuardsman */
public class AutoCraftingManager public class AutoCraftingManager
{ {
@ -59,8 +59,75 @@ public class AutoCraftingManager
} }
} }
public static void printRecipe(Object[] objects)
{
//TODO format and make it look nice
for (Object obj : objects)
{
System.out.println(obj);
}
}
@SuppressWarnings("unchecked")
public static void printRecipes(ItemStack stack)
{
List<IRecipe> recipes = getRecipes(stack);
for (IRecipe recipe : recipes)
{
if (recipe.getRecipeOutput() != null)
{
if (AutoCraftingManager.areStacksEqual(recipe.getRecipeOutput(), stack))
{
if (recipe instanceof ShapedRecipes)
{
printRecipe(((ShapedRecipes) recipe).recipeItems);
}
else if (recipe instanceof ShapelessRecipes)
{
printRecipe(((ShapelessRecipes) recipe).recipeItems.toArray(new Object[1]));
}
else if (recipe instanceof ShapedOreRecipe)
{
ShapedOreRecipe oreRecipe = (ShapedOreRecipe) recipe;
printRecipe((Object[]) ReflectionHelper.getPrivateValue(ShapedOreRecipe.class, oreRecipe, "input"));
}
else if (recipe instanceof ShapelessOreRecipe)
{
ShapelessOreRecipe oreRecipe = (ShapelessOreRecipe) recipe;
ArrayList oreRecipeInput = (ArrayList) ReflectionHelper.getPrivateValue(ShapelessOreRecipe.class, oreRecipe, "input");
for(Object obj : oreRecipeInput)
{
System.out.println(obj);
}
}
}
}
}
}
/** Grabs a list of recipes that can be used to create the given item */
public static List<IRecipe> getRecipes(ItemStack stack)
{
List<IRecipe> recipes = new ArrayList<IRecipe>();
for (Object object : CraftingManager.getInstance().getRecipeList())
{
if (object instanceof IRecipe)
{
if (((IRecipe) object).getRecipeOutput() != null)
{
if (AutoCraftingManager.areStacksEqual(stack, ((IRecipe) object).getRecipeOutput()))
{
recipes.add((IRecipe) object);
}
}
}
}
return recipes;
}
/** Does this player's inventory contain the required resources to craft this item? /** Does this player's inventory contain the required resources to craft this item?
* *
* @return Required items to make the desired item. */ * @return Required items to make the desired item. */
public Pair<ItemStack, ItemStack[]> getIdealRecipe(ItemStack outputItem) public Pair<ItemStack, ItemStack[]> getIdealRecipe(ItemStack outputItem)
{ {
@ -194,7 +261,7 @@ public class AutoCraftingManager
} }
/** Gets the itemStacks in the inv based on slots /** Gets the itemStacks in the inv based on slots
* *
* @param inv - @IInventory instance * @param inv - @IInventory instance
* @param slots - slot # to be used * @param slots - slot # to be used
* @return array of itemStack the same size as the slots input array */ * @return array of itemStack the same size as the slots input array */
@ -214,7 +281,7 @@ public class AutoCraftingManager
} }
/** Returns if the following inventory has the following resource required. /** Returns if the following inventory has the following resource required.
* *
* @param recipeItems - The items to be checked for the recipes. */ * @param recipeItems - The items to be checked for the recipes. */
public ArrayList<ItemStack> hasResource(Object[] recipeItems) public ArrayList<ItemStack> hasResource(Object[] recipeItems)
{ {
@ -302,7 +369,7 @@ public class AutoCraftingManager
} }
/** Decreases the stack by a set amount /** Decreases the stack by a set amount
* *
* @param stack - starting stack * @param stack - starting stack
* @param amount - amount of items * @param amount - amount of items
* @return the edited stack */ * @return the edited stack */
@ -333,7 +400,7 @@ public class AutoCraftingManager
} }
/** Checks if an item exist within the inv array /** Checks if an item exist within the inv array
* *
* @param recipeItem - itemstack being searched for * @param recipeItem - itemstack being searched for
* @param containingItems - inv array containing the search bounds * @param containingItems - inv array containing the search bounds
* @return the point in the array the item was found -1 = the item was null or not valid -2 = * @return the point in the array the item was found -1 = the item was null or not valid -2 =
@ -365,14 +432,14 @@ public class AutoCraftingManager
/** Checks if itemstack are equal based on crafting result rather than normal itemstack this is /** Checks if itemstack are equal based on crafting result rather than normal itemstack this is
* done so that if the itemstack returns with * done so that if the itemstack returns with
* *
* @param recipeItem - itemstack being compared * @param recipeItem - itemstack being compared
* @param checkStack - itemstack being comparted * @param checkStack - itemstack being comparted
* @return true if the items are a match for each other * @return true if the items are a match for each other
* *
* If the item can't be stack and is able to take damage the item will be check on damaged * If the item can't be stack and is able to take damage the item will be check on damaged
* status * status
* *
* If the item's meta data is not normal or in other words equals 32767 the meta data will be * If the item's meta data is not normal or in other words equals 32767 the meta data will be
* ignored */ * ignored */
public static boolean areStacksEqual(ItemStack recipeItem, ItemStack checkStack) public static boolean areStacksEqual(ItemStack recipeItem, ItemStack checkStack)
@ -393,7 +460,7 @@ public class AutoCraftingManager
} }
/** Consumes an item checking for extra conditions like container items /** Consumes an item checking for extra conditions like container items
* *
* @param stack - starting itemStack * @param stack - starting itemStack
* @param ammount - amount to consume * @param ammount - amount to consume
* @return what is left of the itemStack if any */ * @return what is left of the itemStack if any */
@ -438,7 +505,7 @@ public class AutoCraftingManager
} }
/** Used to automatically remove selected items from crafting inv /** Used to automatically remove selected items from crafting inv
* *
* @param requiredItems - items that are to be removed */ * @param requiredItems - items that are to be removed */
public void consumeItems(ItemStack... requiredItems) public void consumeItems(ItemStack... requiredItems)
{ {