package com.pahimar.ee3.recipe; import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; import com.pahimar.ee3.exchange.WrappedStack; import com.pahimar.ee3.util.LogHelper; import java.util.*; public class RecipeRegistry { private static RecipeRegistry recipeRegistry = null; private Multimap> recipeMap; private List discoveredStacks; private RecipeRegistry() { recipeMap = HashMultimap.create(); discoveredStacks = new ArrayList(); init(); } public static RecipeRegistry getInstance() { if (recipeRegistry == null) { recipeRegistry = new RecipeRegistry(); } return recipeRegistry; } private void init() { // Add recipes in the vanilla crafting manager for (WrappedStack outputStack : RecipesVanilla.getVanillaRecipes().keySet()) { for (List inputStacks : RecipesVanilla.getVanillaRecipes().get(outputStack)) { if (!recipeMap.get(outputStack).contains(inputStacks)) { recipeMap.put(outputStack, inputStacks); } } } // Add fluid container recipes for (WrappedStack outputStack : RecipesFluidContainers.getFluidContainerRecipes().keySet()) { for (List inputStacks : RecipesFluidContainers.getFluidContainerRecipes().get(outputStack)) { if (!recipeMap.get(outputStack).contains(inputStacks)) { recipeMap.put(outputStack, inputStacks); } } } // Add potion recipes for (WrappedStack outputStack : RecipesPotions.getPotionRecipes().keySet()) { for (List inputStacks : RecipesPotions.getPotionRecipes().get(outputStack)) { if (!recipeMap.get(outputStack).contains(inputStacks)) { recipeMap.put(outputStack, inputStacks); } } } // Add Aludel recipes // for (RecipeAludel recipeAludel : RecipesAludel.getInstance().getRecipes()) // { // WrappedStack recipeOutput = new WrappedStack(recipeAludel.getRecipeOutput()); // List recipeInputs = recipeAludel.getRecipeInputsAsWrappedStacks(); // // if (!recipeMap.get(recipeOutput).contains(recipeInputs)) // { // recipeMap.put(recipeOutput, recipeInputs); // } // } // Discover all stacks that we can discoverStacks(); } public Multimap> getRecipeMappings() { return recipeRegistry.recipeMap; } public List getDiscoveredStacks() { return Collections.unmodifiableList(recipeRegistry.discoveredStacks); } private void discoverStacks() { discoveredStacks = new ArrayList(); // Scan stacks from known recipes for (WrappedStack recipeOutput : recipeMap.keySet()) { if (!discoveredStacks.contains(new WrappedStack(recipeOutput.getWrappedStack()))) { discoveredStacks.add(new WrappedStack(recipeOutput.getWrappedStack())); } for (List recipeInputList : recipeMap.get(recipeOutput)) { for (WrappedStack recipeInput : recipeInputList) { if (!discoveredStacks.contains(new WrappedStack(recipeInput.getWrappedStack()))) { discoveredStacks.add(new WrappedStack(recipeInput.getWrappedStack())); } } } } } public void dumpRegistry() { // Sort the keys for output to console SortedSet set = new TreeSet(); set.addAll(recipeMap.keySet()); for (WrappedStack key : set) { Collection> recipeMappings = recipeMap.get(key); for (List recipeList : recipeMappings) { LogHelper.info(String.format("Recipe Output: %s, Recipe Input: %s", key.toString(), recipeList.toString())); } } } }