diff --git a/src/dark/api/ProcessorRecipe.java b/src/dark/api/ProcessorRecipe.java new file mode 100644 index 000000000..57fbb9527 --- /dev/null +++ b/src/dark/api/ProcessorRecipe.java @@ -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; + } +} diff --git a/src/dark/api/ProcessorRecipes.java b/src/dark/api/ProcessorRecipes.java index 5b0770d70..74d782e97 100644 --- a/src/dark/api/ProcessorRecipes.java +++ b/src/dark/api/ProcessorRecipes.java @@ -34,11 +34,8 @@ public class ProcessorRecipes CRUSHER(), GRINDER(), PRESS(); - public HashMap, ItemStack> recipes = new HashMap(); - public HashMap, Pair> output = new HashMap(); - public HashMap, Pair> recipesChance = new HashMap(); - public HashMap, Float> recipesChanceSalvage = new HashMap(); - public HashMap, ItemStack> damagedOutput = new HashMap(); + public HashMap, ProcessorRecipe> itemRecipes = new HashMap(); + public HashMap, ItemStack> altOutput = new HashMap(); public List> 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, Block.glass, Block.sand); - ProcessorRecipes.createSalvageDamageOutput(ProcessorType.GRINDER, Block.stone, Block.cobblestone); - ProcessorRecipes.createSalvageDamageOutput(ProcessorType.GRINDER, Block.cobblestoneMossy, Block.cobblestone); - ProcessorRecipes.createSalvageDamageOutput(ProcessorType.GRINDER, Block.glass, Block.sand); - ProcessorRecipes.createSalvageDamageOutput(ProcessorType.CRUSHER, Item.stick, null); + ProcessorRecipes.setAltOutput(ProcessorType.GRINDER, Block.stone, Block.cobblestone); + ProcessorRecipes.setAltOutput(ProcessorType.GRINDER, Block.cobblestoneMossy, Block.cobblestone); + ProcessorRecipes.setAltOutput(ProcessorType.GRINDER, Block.glass, Block.sand); + ProcessorRecipes.setAltOutput(ProcessorType.CRUSHER, Item.stick, null); - ProcessorRecipes.createSalvageDamageOutput(ProcessorType.CRUSHER, Block.stone, Block.cobblestone); - ProcessorRecipes.createSalvageDamageOutput(ProcessorType.CRUSHER, Block.cobblestoneMossy, Block.cobblestone); - ProcessorRecipes.createSalvageDamageOutput(ProcessorType.CRUSHER, Item.stick, null); + ProcessorRecipes.setAltOutput(ProcessorType.CRUSHER, Block.stone, Block.cobblestone); + ProcessorRecipes.setAltOutput(ProcessorType.CRUSHER, Block.cobblestoneMossy, Block.cobblestone); + ProcessorRecipes.setAltOutput(ProcessorType.CRUSHER, Item.stick, null); //TODO replace these with ItemOreDirv - ProcessorRecipes.createSalvageDamageOutput(ProcessorType.CRUSHER, Block.glass, Block.sand); - - markOutputSalavageWithChance(ProcessorType.CRUSHER, new ItemStack(Block.chest, 1), .8f); - markOutputSalavageWithChance(ProcessorType.CRUSHER, new ItemStack(Block.brick, 1), .7f); + ProcessorRecipes.setAltOutput(ProcessorType.CRUSHER, Block.glass, Block.sand); } /** 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 */ 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) @@ -87,84 +81,31 @@ public class ProcessorRecipes { ItemStack input = convert(in); ItemStack output = convert(out); - if (input != null && output != null) + if (input != null && output != null && type.itemRecipes != null) { - HashMap, ItemStack> map = type.recipes; - HashMap, Pair> map2 = type.output; - if (map != null && output != null) + if (min == -1) { - map.put(new Pair(input.itemID, input.getItemDamage()), output); - if (!(min == 1 && max == 1)) - { - map2.put(new Pair(input.itemID, input.getItemDamage()), new Pair(min, max)); - } + min = output.stackSize; } - } - } - } - - /** 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> map = type.recipesChance; - if (map != null && !map.containsKey(new Pair(input.itemID, input.getItemDamage()))) + if (max == -1 || max < min) { - map.put(new Pair(input.itemID, input.getItemDamage()), new Pair(output, chance)); - } - } - } - } - - /** 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, Float> map = type.recipesChanceSalvage; - if (map != null && !map.containsKey(new Pair(input.itemID, input.getItemDamage()))) - { - map.put(new Pair(input.itemID, input.getItemDamage()), chance); + max = output.stackSize; } + type.itemRecipes.put(new Pair(input.itemID, input.getItemDamage()), new ProcessorRecipe(output, min, max)); } } } /** 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) { ItemStack input = convert(in); ItemStack output = convert(out); - if (input != null && output != null) + if (input != null && output != null && type.altOutput != null) { - HashMap, ItemStack> map = type.damagedOutput; - if (map != null) - { - if (!map.containsKey(new Pair(input.itemID, input.getItemDamage()))) - { - map.put(new Pair(input.itemID, input.getItemDamage()), output); - } - else if (map.get(new Pair(input.itemID, input.getItemDamage())) == null) - { - map.put(new Pair(input.itemID, input.getItemDamage()), output); - } - } + type.altOutput.put(new Pair(input.itemID, input.getItemDamage()), output); } } } @@ -220,37 +161,27 @@ public class ProcessorRecipes { return null; } - HashMap, ItemStack> map = type.recipes; - HashMap, Pair> map2 = type.output; - HashMap, Pair> mapChance = type.recipesChance; - HashMap, Float> mapSalvage = type.recipesChanceSalvage; - HashMap, ItemStack> altSalvageMap = type.damagedOutput; Pair blockSet = new Pair(stack.itemID, stack.getItemDamage()); + HashMap, ItemStack> altSalvageMap = type.altOutput; + //Read normal recipe map for outputs - if (map != null) + if (type.itemRecipes != null) { - ItemStack re = map.get(new Pair(stack.itemID, -1)); - Pair range = map2.get(new Pair(stack.itemID, -1)); - if (re != null) + ProcessorRecipe re = type.itemRecipes.get(new Pair(stack.itemID, -1)); + if (re == null || re.output == null) { - ItemStack retm = convert(re); - if (range != null && !(range.left() == 1 && range.right() == 1)) - { - retm.stackSize = range.left() + random.nextInt(range.right()); - } - return new ItemStack[] { retm }; + re = type.itemRecipes.get(new Pair(stack.itemID, stack.getItemDamage())); } - re = map.get(blockSet); - range = map2.get(blockSet); - if (re != null) + if (re != null && re.output != null) { - ItemStack retm = convert(re); - if (range != null && !(range.left() == 1 && range.right() == 1)) + ItemStack output = re.output.copy(); + 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; } + 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) { if (!loadedOres && CoreRecipeLoader.itemMetals instanceof ItemOreDirv) @@ -317,11 +259,11 @@ public class ProcessorRecipes if (mat.shouldCreateItem(EnumOrePart.DUST)) { 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)) { - 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)); } if (mat.shouldCreateItem(EnumOrePart.INGOTS)) @@ -335,14 +277,14 @@ public class ProcessorRecipes { 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)) { 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)) diff --git a/src/dark/core/common/CoreRecipeLoader.java b/src/dark/core/common/CoreRecipeLoader.java index 173fdcd59..8a9eed1dd 100644 --- a/src/dark/core/common/CoreRecipeLoader.java +++ b/src/dark/core/common/CoreRecipeLoader.java @@ -114,11 +114,11 @@ public class CoreRecipeLoader extends RecipeLoader if (itemMetals instanceof ItemOreDirv) { //Alt salvaging item list - ProcessorRecipes.createSalvageDamageOutput(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.wood, EnumMaterial.getStack(EnumMaterial.WOOD, EnumOrePart.DUST, 3)); + 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.createSalvageDamageOutput(ProcessorType.CRUSHER, Block.planks, EnumMaterial.getStack(EnumMaterial.WOOD, EnumOrePart.SCRAPS, 1)); + ProcessorRecipes.setAltOutput(ProcessorType.CRUSHER, Block.wood, EnumMaterial.getStack(EnumMaterial.WOOD, EnumOrePart.SCRAPS, 3)); + ProcessorRecipes.setAltOutput(ProcessorType.CRUSHER, Block.planks, EnumMaterial.getStack(EnumMaterial.WOOD, EnumOrePart.SCRAPS, 1)); //Stone recipes 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.SCRAPS, 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.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.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); 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.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.TUBE, 1), mat.getStack(EnumOrePart.SCRAPS, 1)); }