From c0276a63f73d84a7be2677f37f7fb60a01f9d286 Mon Sep 17 00:00:00 2001 From: Xhamolk_ Date: Mon, 26 Nov 2012 21:22:11 -0600 Subject: [PATCH] OreDictionary addition: getOreID(ItemStack) Allow getting the oreID from a ItemStack, as an alternative from getOreID(String). Now is easier to exchange items for their equivalencies through the OreDictionary. --- .../minecraftforge/oredict/OreDictionary.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/common/net/minecraftforge/oredict/OreDictionary.java b/common/net/minecraftforge/oredict/OreDictionary.java index ee5d8aa0fb..a93875bb4e 100644 --- a/common/net/minecraftforge/oredict/OreDictionary.java +++ b/common/net/minecraftforge/oredict/OreDictionary.java @@ -169,6 +169,29 @@ public class OreDictionary return "Unknown"; } + /** + * Gets the integer ID for the specified item stack. + * If the item stack is not linked to any ore, this will return -1 and no new entry will be created. + * + * @param itemStack The item stack of the ore. + * @return A number representing the ID for this ore type, or -1 if couldn't find it. + */ + public static int getOreID(ItemStack itemStack) + { + if( itemStack == null ) + return -1; + + for(int oreID : oreStacks.keySet()) + { + for(ItemStack target : oreStacks.get(oreID)) + { + if(itemStack.itemID == target.itemID && (target.getItemDamage() == -1 || itemStack.getItemDamage() == target.getItemDamage())) + return oreID; + } + } + return -1; // didn't find it. + } + /** * Retrieves the ArrayList of items that are registered to this ore type. * Creates the list as empty if it did not exist.