From dd5b51aac122baf148400ed93e374d2aee8237a2 Mon Sep 17 00:00:00 2001 From: Lex Manos Date: Wed, 11 Jun 2014 10:27:28 -0700 Subject: [PATCH] Fixed missed metadata offset, and now cache return values of getOres for speed. --- .../java/net/minecraftforge/oredict/OreDictionary.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/minecraftforge/oredict/OreDictionary.java b/src/main/java/net/minecraftforge/oredict/OreDictionary.java index 856391053f..6fa0e24561 100644 --- a/src/main/java/net/minecraftforge/oredict/OreDictionary.java +++ b/src/main/java/net/minecraftforge/oredict/OreDictionary.java @@ -36,7 +36,9 @@ public class OreDictionary private static List idToName = new ArrayList(); private static Map nameToId = new HashMap(); private static List> idToStack = Lists.newArrayList(); //ToDo: Unqualify to List when possible {1.8} + private static List> idToStackUn = Lists.newArrayList(); //ToDo: Unqualify to List when possible {1.8} private static Map> stackToId = Maps.newHashMap(); + public static final ArrayList EMPTY_LIST = new UnmodifiableArrayList(Lists.newArrayList()); //ToDo: Unqualify to List when possible {1.8} /** * Minecraft changed from -1 to Short.MAX_VALUE in 1.5 release for the "block wildcard". Use this in case it @@ -267,6 +269,7 @@ public class OreDictionary val = idToName.size() - 1; //0 indexed nameToId.put(name, val); idToStack.add(new ArrayList()); + idToStackUn.add(new UnmodifiableArrayList(idToStack.get(val))); } return val; } @@ -319,7 +322,7 @@ public class OreDictionary int id = Item.getIdFromItem(stack.getItem()); List ids = stackToId.get(id); if (ids != null) set.addAll(ids); - ids = stackToId.get(id | (stack.getItemDamage() << 16)); + ids = stackToId.get(id | ((stack.getItemDamage() + 1) << 16)); if (ids != null) set.addAll(ids); Integer[] tmp = set.toArray(new Integer[set.size()]); @@ -379,8 +382,9 @@ public class OreDictionary idToName.add(name); nameToId.put(name, idToName.size() - 1); //0 indexed idToStack.add(null); + idToStackUn.add(EMPTY_LIST); } - return new UnmodifiableArrayList(idToStack.size() > id ? idToStack.get(id) : new ArrayList()); + return idToStackUn.size() > id ? idToStackUn.get(id) : EMPTY_LIST; } private static boolean containsMatch(boolean strict, ItemStack[] inputs, ItemStack... targets)