From ef0fc08f790fa14328a562511d7083dd9c6dcaf3 Mon Sep 17 00:00:00 2001 From: pahimar Date: Sat, 16 Jun 2012 02:10:22 -0400 Subject: [PATCH] Lots of work on dynamic Portable Smelting Recipes and finishing up a lot of Equivalency List Recipes --- ee3_common/ee3/core/RecipesPhilStone.java | 303 +++++++++--------- ee3_common/ee3/lib/Helper.java | 29 ++ .../ee3/lib/TransmuteEquivalencyList.java | 34 +- 3 files changed, 190 insertions(+), 176 deletions(-) create mode 100644 ee3_common/ee3/lib/Helper.java diff --git a/ee3_common/ee3/core/RecipesPhilStone.java b/ee3_common/ee3/core/RecipesPhilStone.java index 9fbfe651..f2a6f915 100644 --- a/ee3_common/ee3/core/RecipesPhilStone.java +++ b/ee3_common/ee3/core/RecipesPhilStone.java @@ -1,12 +1,15 @@ package ee3.core; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import java.util.Map; -import ee3.core.interfaces.ITransmuteStone; import ee3.item.ItemPhilosopherStone; import ee3.item.ItemMiniumStone; import ee3.item.ModItems; -import ee3.lib.TransmuteEquivalencyList; +import ee3.lib.Helper; import net.minecraft.src.Block; import net.minecraft.src.FurnaceRecipes; @@ -16,6 +19,7 @@ import net.minecraft.src.ModLoader; import static net.minecraft.src.Item.*; import static net.minecraft.src.Block.*; +import static ee3.lib.TransmuteEquivalencyList.*; /** * TODO Class Description @@ -32,205 +36,170 @@ public class RecipesPhilStone { private static ItemStack anySandStone = new ItemStack(sandStone, 1, -1); private static ItemStack dyeBoneMeal = new ItemStack(dyePowder, 1, 15); - - public static ArrayList> equivalencyLists = new ArrayList>(); - + private static List transmutationStones = Arrays.asList(miniumStone, philStone); public static void initRecipes() { - //TransmuteEquivalencyList.addObjectToEquivalencyList(dirt, stone); - //TransmuteEquivalencyList.addObjectToEquivalencyList(cobblestone, stone); - //TransmuteEquivalencyList.addObjectToEquivalencyList(dirt, stone); - //TransmuteEquivalencyList.debugPrintEquivalencyList(); + initEquivalencyList(); - initTransmutationRecipes(miniumStone); - initTransmutationRecipes(philStone); - initEquivalenceRecipes(); - initReconstructiveRecipes(); - initDestructorRecipes(); - initPortableSmeltingRecipes(); - } - - public static void initTransmutationRecipes(ItemStack stone) { - if (!(stone.getItem() instanceof ITransmuteStone)) { - return; + for (ItemStack transmutationStone: transmutationStones) { + initTransmutationRecipes(transmutationStone); + initEquivalenceRecipes(transmutationStone); + initReconstructiveRecipes(transmutationStone); + initDestructorRecipes(transmutationStone); + initPortableSmeltingRecipes(transmutationStone); } + //debugPrintEquivalencyList(); + } + + public static void initTransmutationRecipes(ItemStack transmutationStone) { /* 4 Cobble <-> 1 Flint */ - addRecipe(flint, stone, cobblestone, cobblestone, cobblestone, cobblestone); - addRecipe(cobblestone, 4, stone, flint); + addRecipe(flint, transmutationStone, cobblestone, cobblestone, cobblestone, cobblestone); + addRecipe(cobblestone, 4, transmutationStone, flint); /* 4 Dirt <-> 1 Gravel */ - addRecipe(gravel, stone, dirt, dirt, dirt, dirt); - addRecipe(dirt, 4, stone, gravel); + addRecipe(gravel, transmutationStone, dirt, dirt, dirt, dirt); + addRecipe(dirt, 4, transmutationStone, gravel); /* 4 Sand <-> 1 Sandstone */ // Vanilla Recipes exist to make SandStone from 4 Sand - addRecipe(sand, 4, stone, anySandStone); + addRecipe(sand, 4, transmutationStone, anySandStone); /* 2 Sticks -> Wood Plank */ - addRecipe(planks, stone, stick, stick); + addRecipe(planks, transmutationStone, stick, stick); // Vanilla recipe exists to make sticks from planks /* 4 Wood Planks -> Wood Block */ - addRecipe(wood, stone, anyPlank, anyPlank, anyPlank, anyPlank); + addRecipe(wood, transmutationStone, anyPlank, anyPlank, anyPlank, anyPlank); // Vanilla recipes exist to make planks from any wood log /* 4 Gravel/Sandstone/Flint -> 1 Clay Ball, 1 Clay Ball -> 4 Gravel */ - addRecipe(clay, stone, gravel, gravel, gravel, gravel); - addRecipe(clay, stone, anySandStone, anySandStone, anySandStone, anySandStone); - addRecipe(clay, stone, flint, flint, flint, flint); - addRecipe(gravel, 4, stone, clay); + addRecipe(clay, transmutationStone, gravel, gravel, gravel, gravel); + addRecipe(clay, transmutationStone, anySandStone, anySandStone, anySandStone, anySandStone); + addRecipe(clay, transmutationStone, flint, flint, flint, flint); + addRecipe(gravel, 4, transmutationStone, clay); /* 2 Wood Log <-> 1 Obsidian */ - addRecipe(obsidian, stone, anyWood, anyWood); - addRecipe(wood, 2, stone, obsidian); + addRecipe(obsidian, transmutationStone, anyWood, anyWood); + addRecipe(wood, 2, transmutationStone, obsidian); /* 4 Clay Ball <-> 1 Clay Block */ // Vanilla recipe exists to make clay blocks from clay balls - addRecipe(clay, 4, stone, blockClay); + addRecipe(clay, 4, transmutationStone, blockClay); /* 4 Obsidian/Clay Block -> 1 Iron Ingot, Iron Ingot -> Clay Block */ - addRecipe(ingotIron, stone, obsidian, obsidian, obsidian, obsidian); - addRecipe(ingotIron, stone, blockClay, blockClay, blockClay, blockClay); - addRecipe(blockClay, 4, stone, ingotIron); + addRecipe(ingotIron, transmutationStone, obsidian, obsidian, obsidian, obsidian); + addRecipe(ingotIron, transmutationStone, blockClay, blockClay, blockClay, blockClay); + addRecipe(blockClay, 4, transmutationStone, ingotIron); /* 8 Iron Ingot <-> 1 Gold Ingot */ - addRecipe(ingotGold, stone, ingotIron, ingotIron, ingotIron, ingotIron, ingotIron, ingotIron, ingotIron, ingotIron); - addRecipe(ingotIron, 8, stone, ingotGold); + addRecipe(ingotGold, transmutationStone, ingotIron, ingotIron, ingotIron, ingotIron, ingotIron, ingotIron, ingotIron, ingotIron); + addRecipe(ingotIron, 8, transmutationStone, ingotGold); /* 4 Gold Ingot <-> 1 Diamond */ - addRecipe(diamond, stone, ingotGold, ingotGold, ingotGold, ingotGold); - addRecipe(ingotGold, 4, stone, diamond); + addRecipe(diamond, transmutationStone, ingotGold, ingotGold, ingotGold, ingotGold); + addRecipe(ingotGold, 4, transmutationStone, diamond); /* 8 Iron Block <-> 1 Gold Block */ - addRecipe(blockGold, stone, blockSteel, blockSteel, blockSteel, blockSteel, blockSteel, blockSteel, blockSteel, blockSteel); - addRecipe(blockSteel, 8, stone, blockGold); + addRecipe(blockGold, transmutationStone, blockSteel, blockSteel, blockSteel, blockSteel, blockSteel, blockSteel, blockSteel, blockSteel); + addRecipe(blockSteel, 8, transmutationStone, blockGold); /* 4 Gold Block <-> 1 Diamond Block */ - addRecipe(blockDiamond, stone, blockGold, blockGold, blockGold, blockGold); - addRecipe(blockGold, 4, stone, blockDiamond); + addRecipe(blockDiamond, transmutationStone, blockGold, blockGold, blockGold, blockGold); + addRecipe(blockGold, 4, transmutationStone, blockDiamond); /* 1 Ender Pearl <-> 4 Iron Ingot */ - addRecipe(enderPearl, stone, ingotIron, ingotIron, ingotIron, ingotIron); - addRecipe(ingotIron, 4, stone, enderPearl); + addRecipe(enderPearl, transmutationStone, ingotIron, ingotIron, ingotIron, ingotIron); + addRecipe(ingotIron, 4, transmutationStone, enderPearl); } - public static void initEquivalenceRecipes() { - /* Wood Plank Cycle */ - addMetaCycleRecipe(planks, 4); - - /* Wood Log Cycle */ - addMetaCycleRecipe(wood, 4); - - /* Sapling Cycle */ - addMetaCycleRecipe(sapling, 4); - - /* Leaf Cycle */ - addMetaCycleRecipe(leaves, 4); - - /* Tall Grass Cycle */ - addMetaCycleRecipe(tallGrass, 3); - - /* Wool Cycle */ - addMetaCycleRecipe(cloth, 16); - - /* Stone Brick Cycle */ - addMetaCycleRecipe(stoneBrick, 4); - - /* Dye Equivalence Cycle */ - addMetaCycleRecipe(dyePowder, 16, 3, 4, 15); - - /* Dirt -> Cobble -> Sand -> Dirt */ - addRecipe(dirt, philStone, cobblestone); - addRecipe(cobblestone, philStone, sand); - addRecipe(sand, philStone, dirt); - - /* 2 Gravel -> 2 Flint -> 2 Sandstone (Cycles) -> 2 Gravel*/ - addRecipe(flint, 2, philStone, gravel, gravel); - addRecipe(new ItemStack(sandStone, 2, 0), philStone, flint, flint); - addRecipe(new ItemStack(sandStone, 2, 1), philStone, new ItemStack(sandStone, 2, 0), new ItemStack(sandStone, 2, 0)); - addRecipe(new ItemStack(sandStone, 2, 2), philStone, new ItemStack(sandStone, 2, 1), new ItemStack(sandStone, 2, 1)); - addRecipe(gravel, 2, philStone, new ItemStack(sandStone, 2, 2), new ItemStack(sandStone, 2, 2)); - - /* Flower Equivalence Recipes */ - addRecipe(plantYellow, philStone, plantRed); - addRecipe(plantRed, philStone, plantYellow); - // RP2 flower recipe goes here, it SHOULD make them cycle instead of two-way if RP2 is present - - /* Mushroom Equivalence Recipes */ - addRecipe(mushroomRed, philStone, mushroomBrown); - addRecipe(mushroomBrown, philStone, mushroomRed); - - /* Books/ */ - /* Reeds <-> Paper <-> Sugar Equivalence Recipes */ - addRecipe(paper, 3, philStone, book); - addRecipe(Item.reed, 3, philStone, paper, paper, paper); - addRecipe(Item.reed, philStone, sugar); - - /* Melon <-> Pumpkin Equivalence Recipes */ - addRecipe(pumpkinSeeds, philStone, melonSeeds); - addRecipe(melonSeeds, philStone, pumpkinSeeds); - addRecipe(pumpkin, philStone, Block.melon); - addRecipe(Block.melon, philStone, pumpkin); + public static void initEquivalencyList() { + addObjectsToEquivalencyLists(sand, dirt, cobblestone); + addObjectsToEquivalencyLists(plantYellow, plantRed); + addObjectsToEquivalencyLists(mushroomRed, mushroomBrown); + addObjectsToEquivalencyLists(pumpkinSeeds, melonSeeds); + addObjectsToEquivalencyLists(pumpkin, Block.melon); + addObjectsToEquivalencyLists(new ItemStack(paper, 3), new ItemStack(Item.reed, 3)); + addObjectsToEquivalencyLists(new ItemStack(flint, 2), new ItemStack(gravel, 2), new ItemStack(sandStone, 2, 0), new ItemStack(sandStone, 2, 1), new ItemStack(sandStone, 2, 2)); + addObjectsToEquivalencyLists(getMetaCycle(planks, 4)); + addObjectsToEquivalencyLists(getMetaCycle(wood, 4)); + addObjectsToEquivalencyLists(getMetaCycle(sapling, 4)); + addObjectsToEquivalencyLists(getMetaCycle(leaves, 4)); + addObjectsToEquivalencyLists(getMetaCycle(tallGrass, 3)); + addObjectsToEquivalencyLists(getMetaCycle(cloth, 16)); + addObjectsToEquivalencyLists(getMetaCycle(stoneBrick, 4)); + addObjectsToEquivalencyLists(getMetaCycle(dyePowder, 16, 3, 4, 15)); } - public static void initReconstructiveRecipes() { + public static void initEquivalenceRecipes(ItemStack transmutationStone) { + int outputI; + + for (ArrayList itemStackList : equivalencyLists) { + ItemStack[] currentList = new ItemStack[itemStackList.size()]; + currentList = itemStackList.toArray(currentList); + + for(int i = 0; i < currentList.length; i++) { + outputI = (i == currentList.length - 1 ? 0 : i + 1); + + addRecipe(currentList[outputI], Helper.convertSingleStackToPluralStacks(transmutationStone, currentList[i])); + } + } + System.out.println(); + } + + public static void initReconstructiveRecipes(ItemStack stone) { /* 3 Bone Meal --> 1 Bone */ - addRecipe(bone, philStone, dyeBoneMeal, dyeBoneMeal, dyeBoneMeal); + addRecipe(bone, stone, dyeBoneMeal, dyeBoneMeal, dyeBoneMeal); /* 2 Blaze Powder --> 1 Blaze Rod */ - addRecipe(blazeRod, philStone, blazePowder, blazePowder); + addRecipe(blazeRod, stone, blazePowder, blazePowder); } - public static void initDestructorRecipes() { + public static void initDestructorRecipes(ItemStack transmutationStone) { /* Smooth Stone -> Cobble Stone */ - addRecipe(cobblestone, philStone, stone); + addRecipe(cobblestone, transmutationStone, stone); /* Glass -> Sand */ - addRecipe(sand, philStone, glass); + addRecipe(sand, transmutationStone, glass); /* Glowstone Block -> 4 Glowstone Dust */ - addRecipe(lightStoneDust, 4, philStone, glowStone); + addRecipe(lightStoneDust, 4, transmutationStone, glowStone); /* Brick Block -> 4 Bricks */ - addRecipe(Item.brick, 4, philStone, Block.brick); + addRecipe(Item.brick, 4, transmutationStone, Block.brick); } - public static void initPortableSmeltingRecipes() { - /* Smelt cobblestone */ - addSmeltingRecipe(Block.cobblestone); + public static void initPortableSmeltingRecipes(ItemStack transmutationStone) { + Map furnaceMap = FurnaceRecipes.smelting().getSmeltingList(); + Map furnaceMetaMap = ModLoader.getPrivateValue(FurnaceRecipes.class, FurnaceRecipes.smelting(), "metaSmeltingList"); + + Iterator iterFurnaceKeyMap = furnaceMap.keySet().iterator(); + Iterator iterFurnaceMetaKeyMap = furnaceMetaMap.keySet().iterator(); + + Integer furnaceMapKey; + List furnaceMetaMapKey; + + ItemStack unSmeltedStack; + + while (iterFurnaceKeyMap.hasNext()) { + furnaceMapKey = (Integer) iterFurnaceKeyMap.next(); + unSmeltedStack = new ItemStack(furnaceMapKey, 1, 0); - /* Smelt any wood */ - addSmeltingRecipe(anyWood); - - /* Smelt iron ore */ - addSmeltingRecipe(oreIron); + addSmeltingRecipe(unSmeltedStack, transmutationStone); + } - /* Smelt gold ore */ - addSmeltingRecipe(oreGold); - - /* Smelt sand */ - addSmeltingRecipe(sand); - - /* Cook chicken */ - addSmeltingRecipe(chickenRaw); - - /* Cook pork */ - addSmeltingRecipe(porkRaw); - - /* Cook beef */ - addSmeltingRecipe(beefRaw); - - /* Cook fish */ - addSmeltingRecipe(fishRaw); + while (iterFurnaceMetaKeyMap.hasNext()) { + furnaceMetaMapKey = (List)iterFurnaceMetaKeyMap.next(); + unSmeltedStack = new ItemStack((Integer)furnaceMetaMapKey.get(0), 1, (Integer)furnaceMetaMapKey.get(1)); + + addSmeltingRecipe(unSmeltedStack, transmutationStone); + } } - - protected static void addRecipe(ItemStack result, Object ... input) { ModLoader.addShapelessRecipe(result, input); } - + protected static void addRecipe(Block result, Object ... input) { addRecipe(new ItemStack(result), input); } @@ -247,6 +216,43 @@ public class RecipesPhilStone { addRecipe(new ItemStack(result, count), input); } + protected static Object[] getMetaCycle(Object input, int n) { + ArrayList list = new ArrayList(); + + ItemStack stack; + + for (int i = 0; i < n; i++) { + stack = Helper.convertObjectToItemStack(input); + stack.setItemDamage(i); + list.add(stack); + } + + return list.toArray(); + } + + protected static Object[] getMetaCycle(Object input, int n, int ... excludedMeta) { + ArrayList list = new ArrayList(); + + ItemStack stack; + int i = 0; + while (i < n) { + for (int j : excludedMeta) { + if (i == j) + ++i; + } + + if (!(i < n)) + break; + + stack = Helper.convertObjectToItemStack(input); + stack.setItemDamage(i); + list.add(stack); + ++i; + } + + return list.toArray(); + } + /* Pass this a Block, Item or ItemStack and the maximum number of indexes, EXCLUDING zero */ protected static void addMetaCycleRecipe(Object input, int n) { int outputI; @@ -286,27 +292,14 @@ public class RecipesPhilStone { } } - /* No meta, defaults to zero */ - protected static void addSmeltingRecipe(Object input) { - addSmeltingRecipe(input, 0); - } - - /* Includes meta, passes either Block or Item, with meta, to final method as an ItemStack */ - protected static void addSmeltingRecipe(Object input, int i) { - if(input instanceof Item) - addSmeltingRecipe(new ItemStack((Item)input, 1, i)); - else if (input instanceof Block) - addSmeltingRecipe(new ItemStack((Block)input, 1, i)); - } - /* Final method, actually adds the portable smelting recipe */ - protected static void addSmeltingRecipe(ItemStack input) { + protected static void addSmeltingRecipe(ItemStack input, ItemStack transmutationStone) { ItemStack result = FurnaceRecipes.smelting().getSmeltingResult(input); if(result == null) return; Object[] list = new Object[9]; - list[0] = philStone; + list[0] = transmutationStone; list[1] = anyCoal; for(int i = 2; i < 9; i++) diff --git a/ee3_common/ee3/lib/Helper.java b/ee3_common/ee3/lib/Helper.java new file mode 100644 index 00000000..53b79bac --- /dev/null +++ b/ee3_common/ee3/lib/Helper.java @@ -0,0 +1,29 @@ +package ee3.lib; + +import java.util.ArrayList; + +import net.minecraft.src.Block; +import net.minecraft.src.Item; +import net.minecraft.src.ItemStack; + +public class Helper { + + public static ItemStack convertObjectToItemStack(Object obj) { + if (obj instanceof Item) { return new ItemStack((Item)obj); } + else if (obj instanceof Block) { return new ItemStack((Block)obj); } + else if (obj instanceof ItemStack){ return (ItemStack)obj; } + else { return null; } + } + + public static Object[] convertSingleStackToPluralStacks(ItemStack stone, ItemStack stack) { + ArrayList list = new ArrayList(); + ItemStack currentStack; + list.add(stone); + for (int i = 0; i < stack.stackSize; i++) { + currentStack = new ItemStack(stack.itemID, 1, stack.getItemDamage()); + list.add(currentStack); + } + + return list.toArray(); + } +} diff --git a/ee3_common/ee3/lib/TransmuteEquivalencyList.java b/ee3_common/ee3/lib/TransmuteEquivalencyList.java index adff6825..ebd6c018 100644 --- a/ee3_common/ee3/lib/TransmuteEquivalencyList.java +++ b/ee3_common/ee3/lib/TransmuteEquivalencyList.java @@ -2,17 +2,24 @@ package ee3.lib; import java.util.ArrayList; -import net.minecraft.src.Block; -import net.minecraft.src.Item; import net.minecraft.src.ItemStack; public class TransmuteEquivalencyList { public static ArrayList> equivalencyLists = new ArrayList>(); + public static void addObjectsToEquivalencyLists(Object ... objList) { + if (objList.length < 2) + return; + + for (int i = 0; i < objList.length - 1; i++) { + addObjectToEquivalencyList(objList[i], objList[i+1]); + } + } + public static void addObjectToEquivalencyList(Object obj1, Object obj2) { - ItemStack stack1 = convertObjectToItemStack(obj1); - ItemStack stack2 = convertObjectToItemStack(obj2); + ItemStack stack1 = Helper.convertObjectToItemStack(obj1); + ItemStack stack2 = Helper.convertObjectToItemStack(obj2); ArrayList currentList = new ArrayList(); @@ -40,7 +47,7 @@ public class TransmuteEquivalencyList { } public static Integer getEquivalencyIndexForItem(Object obj) { - ItemStack checkStack = convertObjectToItemStack(obj); + ItemStack checkStack = Helper.convertObjectToItemStack(obj); ArrayList currentList; int i = 0; @@ -58,7 +65,7 @@ public class TransmuteEquivalencyList { } public static ArrayList getEquivalencyListForItem(Object obj) { - ItemStack checkStack = convertObjectToItemStack(obj); + ItemStack checkStack = Helper.convertObjectToItemStack(obj); for (ArrayList list : equivalencyLists) { for (ItemStack currentStack : list) { @@ -71,21 +78,6 @@ public class TransmuteEquivalencyList { return null; } - private static ItemStack convertObjectToItemStack(Object obj) { - if (obj instanceof Item) { - return new ItemStack((Item)obj); - } - else if (obj instanceof Block) { - return new ItemStack((Block)obj); - } - else if (obj instanceof ItemStack){ - return (ItemStack)obj; - } - else { - return null; - } - } - public static void debugPrintEquivalencyList() { int i = 0; for (ArrayList list : equivalencyLists) {