From 82647f5b669cc6f3947de5f09fa6043e61dd315c Mon Sep 17 00:00:00 2001 From: LexManos Date: Thu, 21 Jan 2016 13:41:26 -0800 Subject: [PATCH] Restore OreDictionary.getOres(String, boolean) and doeOreNameExist(String) functions that went MIA in git merge issue. Original Commit: https://github.com/MinecraftForge/MinecraftForge/commit/cd3bbfb02c9fcd4ce4bbf00f460dfdd6a386d107 --- .../minecraftforge/oredict/OreDictionary.java | 42 ++++++++++++++++++- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/minecraftforge/oredict/OreDictionary.java b/src/main/java/net/minecraftforge/oredict/OreDictionary.java index b8e880cc6..520217244 100644 --- a/src/main/java/net/minecraftforge/oredict/OreDictionary.java +++ b/src/main/java/net/minecraftforge/oredict/OreDictionary.java @@ -35,10 +35,10 @@ public class OreDictionary { private static boolean hasInit = false; private static List idToName = new ArrayList(); - private static Map nameToId = new HashMap(); + private static Map nameToId = new HashMap(128); private static List> idToStack = Lists.newArrayList(); private static List> idToStackUn = Lists.newArrayList(); - private static Map> stackToId = Maps.newHashMap(); + private static Map> stackToId = Maps.newHashMapWithExpectedSize((int)(128 * 0.75)); public static final ImmutableList EMPTY_LIST = ImmutableList.of(); /** @@ -364,6 +364,44 @@ public class OreDictionary return getOres(getOreID(name)); } + /** + * Retrieves the List of items that are registered to this ore type at this instant. + * If the flag is TRUE, then it will create the list as empty if it did not exist. + * + * This option should be used by modders who are doing blanket scans in postInit. + * It greatly reduces clutter in the OreDictionary is the responsible and proper + * way to use the dictionary in a large number of cases. + * + * The other function above is utilized in OreRecipe and is required for the + * operation of that code. + * + * @param name The ore name, directly calls getOreID if the flag is TRUE + * @param alwaysCreateEntry Flag - should a new entry be created if empty + * @return An arraylist containing ItemStacks registered for this ore + */ + public static List getOres(String name, boolean alwaysCreateEntry) + { + if (alwaysCreateEntry) { + return getOres(getOreID(name)); + } + return nameToId.get(name) != null ? getOres(getOreID(name)) : EMPTY_LIST; + } + + /** + * Returns whether or not an oreName exists in the dictionary. + * This function can be used to safely query the Ore Dictionary without + * adding needless clutter to the underlying map structure. + * + * Please use this when possible and appropriate. + * + * @param name The ore name + * @return Whether or not that name is in the Ore Dictionary. + */ + public static boolean doesOreNameExist(String name) + { + return nameToId.get(name) != null; + } + /** * Retrieves a list of all unique ore names that are already registered. *