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. *