Working on correcting issues with processor recipes

This commit is contained in:
DarkGuardsman 2013-11-04 07:55:27 -05:00
parent df5cd16a8e
commit 21af3b9d6d
3 changed files with 77 additions and 113 deletions

View file

@ -0,0 +1,22 @@
package dark.api;
import net.minecraft.item.ItemStack;
/** Processor Recipe output Container. Input is controlled by the processor recipes class. */
public class ProcessorRecipe
{
/** Output of the recipe */
public ItemStack output;
/** Chance per item after the stack size has been calculated from min and max size */
public float chancePerItem = 1.0f;
/** Min the recipe can output */
public int minItemsOut = -1;
/** Max the recipe can output */
public int maxItemsOut = -1;
public ProcessorRecipe(ItemStack output, int min, int max)
{
this.output = output;
this.minItemsOut = min;
this.maxItemsOut = max;
}
}

View file

@ -34,11 +34,8 @@ public class ProcessorRecipes
CRUSHER(), CRUSHER(),
GRINDER(), GRINDER(),
PRESS(); PRESS();
public HashMap<Pair<Integer, Integer>, ItemStack> recipes = new HashMap(); public HashMap<Pair<Integer, Integer>, ProcessorRecipe> itemRecipes = new HashMap();
public HashMap<Pair<Integer, Integer>, Pair<Integer, Integer>> output = new HashMap(); public HashMap<Pair<Integer, Integer>, ItemStack> altOutput = new HashMap();
public HashMap<Pair<Integer, Integer>, Pair<ItemStack, Float>> recipesChance = new HashMap();
public HashMap<Pair<Integer, Integer>, Float> recipesChanceSalvage = new HashMap();
public HashMap<Pair<Integer, Integer>, ItemStack> damagedOutput = new HashMap();
public List<Pair<Integer, Integer>> canSalvage = new ArrayList(); public List<Pair<Integer, Integer>> canSalvage = new ArrayList();
} }
@ -54,20 +51,17 @@ public class ProcessorRecipes
createRecipe(ProcessorType.GRINDER, new ItemStack(Block.cobblestone.blockID, 1, 0), new ItemStack(Block.sand.blockID, 1, 0)); createRecipe(ProcessorType.GRINDER, new ItemStack(Block.cobblestone.blockID, 1, 0), new ItemStack(Block.sand.blockID, 1, 0));
createRecipe(ProcessorType.GRINDER, Block.glass, Block.sand); createRecipe(ProcessorType.GRINDER, Block.glass, Block.sand);
ProcessorRecipes.createSalvageDamageOutput(ProcessorType.GRINDER, Block.stone, Block.cobblestone); ProcessorRecipes.setAltOutput(ProcessorType.GRINDER, Block.stone, Block.cobblestone);
ProcessorRecipes.createSalvageDamageOutput(ProcessorType.GRINDER, Block.cobblestoneMossy, Block.cobblestone); ProcessorRecipes.setAltOutput(ProcessorType.GRINDER, Block.cobblestoneMossy, Block.cobblestone);
ProcessorRecipes.createSalvageDamageOutput(ProcessorType.GRINDER, Block.glass, Block.sand); ProcessorRecipes.setAltOutput(ProcessorType.GRINDER, Block.glass, Block.sand);
ProcessorRecipes.createSalvageDamageOutput(ProcessorType.CRUSHER, Item.stick, null); ProcessorRecipes.setAltOutput(ProcessorType.CRUSHER, Item.stick, null);
ProcessorRecipes.createSalvageDamageOutput(ProcessorType.CRUSHER, Block.stone, Block.cobblestone); ProcessorRecipes.setAltOutput(ProcessorType.CRUSHER, Block.stone, Block.cobblestone);
ProcessorRecipes.createSalvageDamageOutput(ProcessorType.CRUSHER, Block.cobblestoneMossy, Block.cobblestone); ProcessorRecipes.setAltOutput(ProcessorType.CRUSHER, Block.cobblestoneMossy, Block.cobblestone);
ProcessorRecipes.createSalvageDamageOutput(ProcessorType.CRUSHER, Item.stick, null); ProcessorRecipes.setAltOutput(ProcessorType.CRUSHER, Item.stick, null);
//TODO replace these with ItemOreDirv //TODO replace these with ItemOreDirv
ProcessorRecipes.createSalvageDamageOutput(ProcessorType.CRUSHER, Block.glass, Block.sand); ProcessorRecipes.setAltOutput(ProcessorType.CRUSHER, Block.glass, Block.sand);
markOutputSalavageWithChance(ProcessorType.CRUSHER, new ItemStack(Block.chest, 1), .8f);
markOutputSalavageWithChance(ProcessorType.CRUSHER, new ItemStack(Block.brick, 1), .7f);
} }
/** Creates a simple one itemStack in one ItemStack out. Itemstack output can actual have a stack /** Creates a simple one itemStack in one ItemStack out. Itemstack output can actual have a stack
@ -78,7 +72,7 @@ public class ProcessorRecipes
* @param out - ouput item */ * @param out - ouput item */
public static void createRecipe(ProcessorType type, Object in, Object out) public static void createRecipe(ProcessorType type, Object in, Object out)
{ {
createRecipe(type, in, out, 1, 1); createRecipe(type, in, out, -1, -1);
} }
public static void createRecipe(ProcessorType type, Object in, Object out, int min, int max) public static void createRecipe(ProcessorType type, Object in, Object out, int min, int max)
@ -87,84 +81,31 @@ public class ProcessorRecipes
{ {
ItemStack input = convert(in); ItemStack input = convert(in);
ItemStack output = convert(out); ItemStack output = convert(out);
if (input != null && output != null) if (input != null && output != null && type.itemRecipes != null)
{ {
HashMap<Pair<Integer, Integer>, ItemStack> map = type.recipes; if (min == -1)
HashMap<Pair<Integer, Integer>, Pair<Integer, Integer>> map2 = type.output;
if (map != null && output != null)
{ {
map.put(new Pair<Integer, Integer>(input.itemID, input.getItemDamage()), output); min = output.stackSize;
if (!(min == 1 && max == 1))
{
map2.put(new Pair<Integer, Integer>(input.itemID, input.getItemDamage()), new Pair<Integer, Integer>(min, max));
}
} }
} if (max == -1 || max < min)
}
}
/** Creates a recipe that has a chance of failing
*
* @param type - processor type
* @param in - input item stack, stack size is ignored
* @param out - output item stack, stack size is used
* @param chance - chance to fail with 1 being zero chance and zero being 100% chance */
public static void createRecipeWithChance(ProcessorType type, Object in, Object out, float chance)
{
if (in != null && out != null && type != null)
{
ItemStack input = convert(in);
ItemStack output = convert(out);
if (input != null && output != null)
{
HashMap<Pair<Integer, Integer>, Pair<ItemStack, Float>> map = type.recipesChance;
if (map != null && !map.containsKey(new Pair<Integer, Integer>(input.itemID, input.getItemDamage())))
{ {
map.put(new Pair<Integer, Integer>(input.itemID, input.getItemDamage()), new Pair<ItemStack, Float>(output, chance)); max = output.stackSize;
}
}
}
}
/** Not so much of a recipe but it applies a change on the item. TODO improve and control actual
* output of the recipe */
public static void markOutputSalavageWithChance(ProcessorType type, Object in, float chance)
{
if (in != null && type != null)
{
ItemStack input = convert(in);
if (input != null && input != null)
{
HashMap<Pair<Integer, Integer>, Float> map = type.recipesChanceSalvage;
if (map != null && !map.containsKey(new Pair<Integer, Integer>(input.itemID, input.getItemDamage())))
{
map.put(new Pair<Integer, Integer>(input.itemID, input.getItemDamage()), chance);
} }
type.itemRecipes.put(new Pair<Integer, Integer>(input.itemID, input.getItemDamage()), new ProcessorRecipe(output, min, max));
} }
} }
} }
/** Used to track items that should be converted to different items during salvaging. */ /** Used to track items that should be converted to different items during salvaging. */
public static void createSalvageDamageOutput(ProcessorType type, Object in, Object out) public static void setAltOutput(ProcessorType type, Object in, Object out)
{ {
if (in != null && out != null && type != null) if (in != null && out != null && type != null)
{ {
ItemStack input = convert(in); ItemStack input = convert(in);
ItemStack output = convert(out); ItemStack output = convert(out);
if (input != null && output != null) if (input != null && output != null && type.altOutput != null)
{ {
HashMap<Pair<Integer, Integer>, ItemStack> map = type.damagedOutput; type.altOutput.put(new Pair<Integer, Integer>(input.itemID, input.getItemDamage()), output);
if (map != null)
{
if (!map.containsKey(new Pair<Integer, Integer>(input.itemID, input.getItemDamage())))
{
map.put(new Pair<Integer, Integer>(input.itemID, input.getItemDamage()), output);
}
else if (map.get(new Pair<Integer, Integer>(input.itemID, input.getItemDamage())) == null)
{
map.put(new Pair<Integer, Integer>(input.itemID, input.getItemDamage()), output);
}
}
} }
} }
} }
@ -220,37 +161,27 @@ public class ProcessorRecipes
{ {
return null; return null;
} }
HashMap<Pair<Integer, Integer>, ItemStack> map = type.recipes;
HashMap<Pair<Integer, Integer>, Pair<Integer, Integer>> map2 = type.output;
HashMap<Pair<Integer, Integer>, Pair<ItemStack, Float>> mapChance = type.recipesChance;
HashMap<Pair<Integer, Integer>, Float> mapSalvage = type.recipesChanceSalvage;
HashMap<Pair<Integer, Integer>, ItemStack> altSalvageMap = type.damagedOutput;
Pair<Integer, Integer> blockSet = new Pair<Integer, Integer>(stack.itemID, stack.getItemDamage()); Pair<Integer, Integer> blockSet = new Pair<Integer, Integer>(stack.itemID, stack.getItemDamage());
HashMap<Pair<Integer, Integer>, ItemStack> altSalvageMap = type.altOutput;
//Read normal recipe map for outputs //Read normal recipe map for outputs
if (map != null) if (type.itemRecipes != null)
{ {
ItemStack re = map.get(new Pair<Integer, Integer>(stack.itemID, -1)); ProcessorRecipe re = type.itemRecipes.get(new Pair<Integer, Integer>(stack.itemID, -1));
Pair<Integer, Integer> range = map2.get(new Pair<Integer, Integer>(stack.itemID, -1)); if (re == null || re.output == null)
if (re != null)
{ {
ItemStack retm = convert(re); re = type.itemRecipes.get(new Pair<Integer, Integer>(stack.itemID, stack.getItemDamage()));
if (range != null && !(range.left() == 1 && range.right() == 1))
{
retm.stackSize = range.left() + random.nextInt(range.right());
}
return new ItemStack[] { retm };
} }
re = map.get(blockSet); if (re != null && re.output != null)
range = map2.get(blockSet);
if (re != null)
{ {
ItemStack retm = convert(re); ItemStack output = re.output.copy();
if (range != null && !(range.left() == 1 && range.right() == 1)) output.stackSize = Math.min(re.maxItemsOut, re.minItemsOut + random.nextInt(re.minItemsOut));
if (re.chancePerItem < 1.0f)
{ {
retm.stackSize = range.left() + random.nextInt(range.right());
} }
return new ItemStack[] { retm }; return new ItemStack[] { output };
} }
} }
@ -287,6 +218,17 @@ public class ProcessorRecipes
return reList; return reList;
} }
public static ItemStack[] getOuputNormal(ProcessorType type, ItemStack stack, boolean damageSalvage)
{
if (stack == null || type == null || stack.getItem() == null)
{
return null;
}
ItemStack[] reList = null;
return reList;
}
public static void parseOreNames(Configuration config) public static void parseOreNames(Configuration config)
{ {
if (!loadedOres && CoreRecipeLoader.itemMetals instanceof ItemOreDirv) if (!loadedOres && CoreRecipeLoader.itemMetals instanceof ItemOreDirv)
@ -317,11 +259,11 @@ public class ProcessorRecipes
if (mat.shouldCreateItem(EnumOrePart.DUST)) if (mat.shouldCreateItem(EnumOrePart.DUST))
{ {
ProcessorRecipes.createRecipe(ProcessorType.GRINDER, ing, mat.getStack(EnumOrePart.DUST, 1)); ProcessorRecipes.createRecipe(ProcessorType.GRINDER, ing, mat.getStack(EnumOrePart.DUST, 1));
ProcessorRecipes.createSalvageDamageOutput(ProcessorType.GRINDER, ing, mat.getStack(EnumOrePart.DUST, 1)); ProcessorRecipes.setAltOutput(ProcessorType.GRINDER, ing, mat.getStack(EnumOrePart.DUST, 1));
} }
if (mat.shouldCreateItem(EnumOrePart.SCRAPS)) if (mat.shouldCreateItem(EnumOrePart.SCRAPS))
{ {
ProcessorRecipes.createSalvageDamageOutput(ProcessorType.CRUSHER, ing, mat.getStack(EnumOrePart.SCRAPS, 1)); ProcessorRecipes.setAltOutput(ProcessorType.CRUSHER, ing, mat.getStack(EnumOrePart.SCRAPS, 1));
ProcessorRecipes.createRecipe(ProcessorType.CRUSHER, ing, mat.getStack(EnumOrePart.SCRAPS, 1)); ProcessorRecipes.createRecipe(ProcessorType.CRUSHER, ing, mat.getStack(EnumOrePart.SCRAPS, 1));
} }
if (mat.shouldCreateItem(EnumOrePart.INGOTS)) if (mat.shouldCreateItem(EnumOrePart.INGOTS))
@ -335,14 +277,14 @@ public class ProcessorRecipes
{ {
ProcessorRecipes.createRecipe(ProcessorType.GRINDER, pla, mat.getStack(EnumOrePart.DUST, 1)); ProcessorRecipes.createRecipe(ProcessorType.GRINDER, pla, mat.getStack(EnumOrePart.DUST, 1));
ProcessorRecipes.createSalvageDamageOutput(ProcessorType.GRINDER, pla, mat.getStack(EnumOrePart.DUST, 1)); ProcessorRecipes.setAltOutput(ProcessorType.GRINDER, pla, mat.getStack(EnumOrePart.DUST, 1));
} }
if (mat.shouldCreateItem(EnumOrePart.SCRAPS)) if (mat.shouldCreateItem(EnumOrePart.SCRAPS))
{ {
ProcessorRecipes.createRecipe(ProcessorType.CRUSHER, pla, mat.getStack(EnumOrePart.SCRAPS, 1)); ProcessorRecipes.createRecipe(ProcessorType.CRUSHER, pla, mat.getStack(EnumOrePart.SCRAPS, 1));
ProcessorRecipes.createSalvageDamageOutput(ProcessorType.CRUSHER, pla, mat.getStack(EnumOrePart.SCRAPS, 1)); ProcessorRecipes.setAltOutput(ProcessorType.CRUSHER, pla, mat.getStack(EnumOrePart.SCRAPS, 1));
} }
if (mat.shouldCreateItem(EnumOrePart.PLATES)) if (mat.shouldCreateItem(EnumOrePart.PLATES))

View file

@ -114,11 +114,11 @@ public class CoreRecipeLoader extends RecipeLoader
if (itemMetals instanceof ItemOreDirv) if (itemMetals instanceof ItemOreDirv)
{ {
//Alt salvaging item list //Alt salvaging item list
ProcessorRecipes.createSalvageDamageOutput(ProcessorType.GRINDER, Block.wood, EnumMaterial.getStack(EnumMaterial.WOOD, EnumOrePart.DUST, 3)); ProcessorRecipes.setAltOutput(ProcessorType.GRINDER, Block.wood, EnumMaterial.getStack(EnumMaterial.WOOD, EnumOrePart.DUST, 3));
ProcessorRecipes.createSalvageDamageOutput(ProcessorType.GRINDER, Block.planks, EnumMaterial.getStack(EnumMaterial.WOOD, EnumOrePart.DUST, 1)); ProcessorRecipes.setAltOutput(ProcessorType.GRINDER, Block.planks, EnumMaterial.getStack(EnumMaterial.WOOD, EnumOrePart.DUST, 1));
ProcessorRecipes.createSalvageDamageOutput(ProcessorType.CRUSHER, Block.wood, EnumMaterial.getStack(EnumMaterial.WOOD, EnumOrePart.SCRAPS, 3)); ProcessorRecipes.setAltOutput(ProcessorType.CRUSHER, Block.wood, EnumMaterial.getStack(EnumMaterial.WOOD, EnumOrePart.SCRAPS, 3));
ProcessorRecipes.createSalvageDamageOutput(ProcessorType.CRUSHER, Block.planks, EnumMaterial.getStack(EnumMaterial.WOOD, EnumOrePart.SCRAPS, 1)); ProcessorRecipes.setAltOutput(ProcessorType.CRUSHER, Block.planks, EnumMaterial.getStack(EnumMaterial.WOOD, EnumOrePart.SCRAPS, 1));
//Stone recipes //Stone recipes
ProcessorRecipes.createRecipe(ProcessorType.GRINDER, Block.stone, EnumMaterial.getStack(EnumMaterial.STONE, EnumOrePart.DUST, 1)); ProcessorRecipes.createRecipe(ProcessorType.GRINDER, Block.stone, EnumMaterial.getStack(EnumMaterial.STONE, EnumOrePart.DUST, 1));
@ -167,9 +167,9 @@ public class CoreRecipeLoader extends RecipeLoader
ProcessorRecipes.createRecipe(ProcessorType.GRINDER, mat.getStack(EnumOrePart.RUBBLE, 1), mat.getStack(EnumOrePart.DUST, 1), 1, 4); ProcessorRecipes.createRecipe(ProcessorType.GRINDER, mat.getStack(EnumOrePart.RUBBLE, 1), mat.getStack(EnumOrePart.DUST, 1), 1, 4);
ProcessorRecipes.createRecipe(ProcessorType.GRINDER, mat.getStack(EnumOrePart.SCRAPS, 1), mat.getStack(EnumOrePart.DUST, 1)); ProcessorRecipes.createRecipe(ProcessorType.GRINDER, mat.getStack(EnumOrePart.SCRAPS, 1), mat.getStack(EnumOrePart.DUST, 1));
ProcessorRecipes.createRecipe(ProcessorType.GRINDER, mat.getStack(EnumOrePart.INGOTS, 1), mat.getStack(EnumOrePart.DUST, 1)); ProcessorRecipes.createRecipe(ProcessorType.GRINDER, mat.getStack(EnumOrePart.INGOTS, 1), mat.getStack(EnumOrePart.DUST, 1));
ProcessorRecipes.createSalvageDamageOutput(ProcessorType.GRINDER, mat.getStack(EnumOrePart.INGOTS, 1), mat.getStack(EnumOrePart.DUST, 1)); ProcessorRecipes.setAltOutput(ProcessorType.GRINDER, mat.getStack(EnumOrePart.INGOTS, 1), mat.getStack(EnumOrePart.DUST, 1));
ProcessorRecipes.createRecipe(ProcessorType.GRINDER, mat.getStack(EnumOrePart.PLATES, 1), mat.getStack(EnumOrePart.DUST, 1), 2, 4); ProcessorRecipes.createRecipe(ProcessorType.GRINDER, mat.getStack(EnumOrePart.PLATES, 1), mat.getStack(EnumOrePart.DUST, 1), 2, 4);
ProcessorRecipes.createSalvageDamageOutput(ProcessorType.GRINDER, mat.getStack(EnumOrePart.PLATES, 1), mat.getStack(EnumOrePart.DUST, 3)); ProcessorRecipes.setAltOutput(ProcessorType.GRINDER, mat.getStack(EnumOrePart.PLATES, 1), mat.getStack(EnumOrePart.DUST, 3));
ProcessorRecipes.createRecipe(ProcessorType.GRINDER, mat.getStack(EnumOrePart.ROD, 1), mat.getStack(EnumOrePart.DUST, 1)); ProcessorRecipes.createRecipe(ProcessorType.GRINDER, mat.getStack(EnumOrePart.ROD, 1), mat.getStack(EnumOrePart.DUST, 1));
ProcessorRecipes.createRecipe(ProcessorType.GRINDER, mat.getStack(EnumOrePart.TUBE, 1), mat.getStack(EnumOrePart.DUST, 1)); ProcessorRecipes.createRecipe(ProcessorType.GRINDER, mat.getStack(EnumOrePart.TUBE, 1), mat.getStack(EnumOrePart.DUST, 1));
} }
@ -180,9 +180,9 @@ public class CoreRecipeLoader extends RecipeLoader
{ {
FurnaceRecipes.smelting().addSmelting(mat.getStack(EnumOrePart.SCRAPS, 1).itemID, mat.getStack(EnumOrePart.SCRAPS, 1).getItemDamage(), mat.getStack(EnumOrePart.INGOTS, 1), 0.6f); FurnaceRecipes.smelting().addSmelting(mat.getStack(EnumOrePart.SCRAPS, 1).itemID, mat.getStack(EnumOrePart.SCRAPS, 1).getItemDamage(), mat.getStack(EnumOrePart.INGOTS, 1), 0.6f);
ProcessorRecipes.createRecipe(ProcessorType.CRUSHER, mat.getStack(EnumOrePart.PLATES, 1), mat.getStack(EnumOrePart.SCRAPS, 3)); ProcessorRecipes.createRecipe(ProcessorType.CRUSHER, mat.getStack(EnumOrePart.PLATES, 1), mat.getStack(EnumOrePart.SCRAPS, 3));
ProcessorRecipes.createSalvageDamageOutput(ProcessorType.CRUSHER, mat.getStack(EnumOrePart.PLATES, 1), mat.getStack(EnumOrePart.SCRAPS, 3)); ProcessorRecipes.setAltOutput(ProcessorType.CRUSHER, mat.getStack(EnumOrePart.PLATES, 1), mat.getStack(EnumOrePart.SCRAPS, 3));
ProcessorRecipes.createRecipe(ProcessorType.CRUSHER, mat.getStack(EnumOrePart.RUBBLE, 1), mat.getStack(EnumOrePart.SCRAPS, 1), 1, 5); ProcessorRecipes.createRecipe(ProcessorType.CRUSHER, mat.getStack(EnumOrePart.RUBBLE, 1), mat.getStack(EnumOrePart.SCRAPS, 1), 1, 5);
ProcessorRecipes.createSalvageDamageOutput(ProcessorType.CRUSHER, mat.getStack(EnumOrePart.INGOTS, 1), mat.getStack(EnumOrePart.SCRAPS, 1)); ProcessorRecipes.setAltOutput(ProcessorType.CRUSHER, mat.getStack(EnumOrePart.INGOTS, 1), mat.getStack(EnumOrePart.SCRAPS, 1));
ProcessorRecipes.createRecipe(ProcessorType.CRUSHER, mat.getStack(EnumOrePart.ROD, 1), mat.getStack(EnumOrePart.SCRAPS, 1)); ProcessorRecipes.createRecipe(ProcessorType.CRUSHER, mat.getStack(EnumOrePart.ROD, 1), mat.getStack(EnumOrePart.SCRAPS, 1));
ProcessorRecipes.createRecipe(ProcessorType.CRUSHER, mat.getStack(EnumOrePart.TUBE, 1), mat.getStack(EnumOrePart.SCRAPS, 1)); ProcessorRecipes.createRecipe(ProcessorType.CRUSHER, mat.getStack(EnumOrePart.TUBE, 1), mat.getStack(EnumOrePart.SCRAPS, 1));
} }