package com.pahimar.ee3.exchange; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.Multimap; import com.google.common.collect.TreeMultimap; import com.pahimar.ee3.reference.Comparators; import com.pahimar.ee3.util.LogHelper; import net.minecraft.item.ItemStack; import net.minecraftforge.oredict.OreDictionary; import java.util.*; public class CachedOreDictionary { private static CachedOreDictionary cachedOreDictionary = null; private ImmutableMap idToNameMap; private ImmutableMap> oreNameToItemStackMap; private ImmutableMultimap itemStackToOreNameMap; private CachedOreDictionary() { Map idToOreNameMap = new TreeMap(); Map> nameToStackMap = new TreeMap>(Comparators.stringComparator); Multimap stackToNameMultiMap = TreeMultimap.create(WrappedStack.comparator, Comparators.stringComparator); for (String oreName : OreDictionary.getOreNames()) { idToOreNameMap.put(OreDictionary.getOreID(oreName), oreName); List oreNameItemStacks = OreDictionary.getOres(oreName); nameToStackMap.put(oreName, oreNameItemStacks); for (ItemStack itemStack : oreNameItemStacks) { stackToNameMultiMap.put(WrappedStack.wrap(itemStack), oreName); } } idToNameMap = ImmutableMap.copyOf(idToOreNameMap); oreNameToItemStackMap = ImmutableMap.copyOf(nameToStackMap); itemStackToOreNameMap = ImmutableMultimap.copyOf(stackToNameMultiMap); } public static CachedOreDictionary getInstance() { if (cachedOreDictionary == null) { cachedOreDictionary = new CachedOreDictionary(); } return cachedOreDictionary; } public Set getOreNames() { return oreNameToItemStackMap.keySet(); } public List getItemStacksForOreName(String oreName) { if (oreNameToItemStackMap.containsKey(oreName)) { return oreNameToItemStackMap.get(oreName); } return new ArrayList(); } public List getOreNamesForItemStack(ItemStack itemStack) { List oreNameList = new ArrayList(); WrappedStack wrappedStack = WrappedStack.wrap(itemStack); if (itemStackToOreNameMap.containsKey(wrappedStack)) { for (String oreName : itemStackToOreNameMap.get(wrappedStack)) { oreNameList.add(oreName); } } else { for (WrappedStack wrappedStack1 : itemStackToOreNameMap.keySet()) { } } return oreNameList; } public void dumpCachedOreDictionaryToLog() { for (String oreName : CachedOreDictionary.getInstance().getOreNames()) { LogHelper.info("OreName: {}, ItemStacks: {}", oreName, CachedOreDictionary.getInstance().getItemStacksForOreName(oreName)); } } }