forked from mekanism/Mekanism
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Attempt some memoization, please test and report pgatt, judge
- Loading branch information
1 parent
db7d4ad
commit b3f9c48
Showing
5 changed files
with
100 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package mekanism.api; | ||
|
||
import net.minecraft.item.ItemStack; | ||
|
||
public class ItemInfo | ||
{ | ||
public int id; | ||
public int meta; | ||
|
||
public ItemInfo(int i, int j) | ||
{ | ||
id = i; | ||
meta = j; | ||
} | ||
|
||
public static ItemInfo get(ItemStack stack) | ||
{ | ||
return new ItemInfo(stack.itemID, stack.getItemDamage()); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) | ||
{ | ||
return obj instanceof ItemInfo && | ||
((ItemInfo)obj).id == id && | ||
((ItemInfo)obj).meta == meta; | ||
} | ||
|
||
@Override | ||
public int hashCode() | ||
{ | ||
int code = 1; | ||
code = 31 * code + id; | ||
code = 31 * code + meta; | ||
return code; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package mekanism.common; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import mekanism.api.ItemInfo; | ||
import mekanism.common.util.MekanismUtils; | ||
import mekanism.common.util.StackUtils; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraftforge.oredict.OreDictionary; | ||
|
||
public class OreDictCache | ||
{ | ||
public static HashMap<ItemInfo, List<String>> cachedKeys = new HashMap<ItemInfo, List<String>>(); | ||
|
||
public static List<String> getOreDictName(ItemStack check) | ||
{ | ||
ItemInfo info = ItemInfo.get(check); | ||
|
||
if(cachedKeys.get(info) != null) | ||
{ | ||
return cachedKeys.get(info); | ||
} | ||
|
||
List<Integer> idsFound = new ArrayList<Integer>(); | ||
HashMap<Integer, ArrayList<ItemStack>> oreStacks = (HashMap<Integer, ArrayList<ItemStack>>)MekanismUtils.getPrivateValue(null, OreDictionary.class, new String[] {"oreStacks"}); | ||
oreStacks = (HashMap<Integer, ArrayList<ItemStack>>)oreStacks.clone(); | ||
|
||
for(Map.Entry<Integer, ArrayList<ItemStack>> entry : oreStacks.entrySet()) | ||
{ | ||
for(ItemStack stack : entry.getValue()) | ||
{ | ||
if(StackUtils.equalsWildcard(stack, check)) | ||
{ | ||
idsFound.add(entry.getKey()); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
List<String> ret = new ArrayList<String>(); | ||
|
||
for(Integer id : idsFound) | ||
{ | ||
ret.add(OreDictionary.getOreName(id)); | ||
} | ||
|
||
cachedKeys.put(info, ret); | ||
|
||
return ret; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters