2014-07-07 21:31:10 +02:00
|
|
|
package com.pahimar.ee3.recipe;
|
2014-06-14 21:40:45 +02:00
|
|
|
|
|
|
|
import com.google.common.collect.HashMultimap;
|
2014-07-24 22:01:42 +02:00
|
|
|
import com.google.common.collect.ImmutableMultimap;
|
2014-06-14 21:40:45 +02:00
|
|
|
import com.google.common.collect.Multimap;
|
2014-07-07 21:31:10 +02:00
|
|
|
import com.pahimar.ee3.exchange.WrappedStack;
|
2015-03-22 21:52:48 +01:00
|
|
|
import com.pahimar.ee3.util.LogHelper;
|
2014-06-14 21:40:45 +02:00
|
|
|
|
2014-07-22 21:56:39 +02:00
|
|
|
import java.util.ArrayList;
|
2014-06-19 20:39:46 +02:00
|
|
|
import java.util.List;
|
2014-06-14 21:40:45 +02:00
|
|
|
|
|
|
|
public class RecipeRegistry
|
|
|
|
{
|
|
|
|
private static RecipeRegistry recipeRegistry = null;
|
|
|
|
|
|
|
|
private Multimap<WrappedStack, List<WrappedStack>> recipeMap;
|
2015-02-02 04:17:51 +01:00
|
|
|
private ImmutableMultimap<WrappedStack, List<WrappedStack>> immutableRecipeMap;
|
2014-06-14 21:40:45 +02:00
|
|
|
|
|
|
|
private RecipeRegistry()
|
|
|
|
{
|
2015-04-09 18:40:19 +02:00
|
|
|
recipeMap = HashMultimap.create(); // TODO Switch this to a TreeMultimap
|
2014-06-14 21:40:45 +02:00
|
|
|
}
|
|
|
|
|
2014-07-22 21:56:39 +02:00
|
|
|
public static RecipeRegistry getInstance()
|
|
|
|
{
|
|
|
|
if (recipeRegistry == null)
|
|
|
|
{
|
|
|
|
recipeRegistry = new RecipeRegistry();
|
|
|
|
}
|
|
|
|
|
|
|
|
return recipeRegistry;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void addRecipe(Object recipeOutput, List<?> recipeInputList)
|
|
|
|
{
|
|
|
|
// Verify that the recipe output object can be wrapped
|
|
|
|
if (!WrappedStack.canBeWrapped(recipeOutput))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify that every recipe input object can be wrapped
|
|
|
|
for (Object recipeInputObject : recipeInputList)
|
|
|
|
{
|
|
|
|
if (!WrappedStack.canBeWrapped(recipeInputObject))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wrap the recipe output
|
|
|
|
WrappedStack wrappedRecipeOutput = new WrappedStack(recipeOutput);
|
|
|
|
List<WrappedStack> wrappedRecipeInputList = new ArrayList<WrappedStack>();
|
|
|
|
for (Object recipeInputObject : recipeInputList)
|
|
|
|
{
|
|
|
|
wrappedRecipeInputList.add(new WrappedStack(recipeInputObject));
|
|
|
|
}
|
2014-07-23 04:12:04 +02:00
|
|
|
|
|
|
|
// Add the recipe mapping only if we don't already have it
|
|
|
|
if (!recipeMap.get(wrappedRecipeOutput).contains(wrappedRecipeInputList))
|
|
|
|
{
|
|
|
|
recipeMap.put(wrappedRecipeOutput, wrappedRecipeInputList);
|
|
|
|
}
|
2014-07-22 21:56:39 +02:00
|
|
|
}
|
|
|
|
|
2014-07-24 22:01:42 +02:00
|
|
|
public void registerVanillaRecipes()
|
2014-06-14 21:40:45 +02:00
|
|
|
{
|
2014-07-24 22:01:42 +02:00
|
|
|
RecipesVanilla.registerRecipes();
|
|
|
|
RecipesFluidContainers.registerRecipes();
|
|
|
|
RecipesPotions.registerRecipes();
|
2014-06-14 21:40:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public Multimap<WrappedStack, List<WrappedStack>> getRecipeMappings()
|
|
|
|
{
|
2015-02-02 04:17:51 +01:00
|
|
|
if (immutableRecipeMap == null)
|
|
|
|
{
|
2015-03-05 05:31:43 +01:00
|
|
|
immutableRecipeMap = ImmutableMultimap.copyOf(recipeRegistry.recipeMap);
|
2015-02-02 04:17:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return immutableRecipeMap;
|
2014-06-14 21:40:45 +02:00
|
|
|
}
|
2015-03-22 21:52:48 +01:00
|
|
|
|
|
|
|
public void dumpRecipeRegistryToLog()
|
|
|
|
{
|
2015-04-09 18:40:19 +02:00
|
|
|
for (WrappedStack wrappedStack : getRecipeMappings().keySet())
|
2015-03-22 21:52:48 +01:00
|
|
|
{
|
|
|
|
StringBuilder stringBuilder = new StringBuilder();
|
2015-04-14 20:45:16 +02:00
|
|
|
stringBuilder.append(String.format("Output: %s, Inputs: ", wrappedStack.toString()));
|
2015-04-09 18:40:19 +02:00
|
|
|
for (List<WrappedStack> listStacks : getRecipeMappings().get(wrappedStack))
|
2015-03-22 21:52:48 +01:00
|
|
|
{
|
|
|
|
for (WrappedStack listStack : listStacks)
|
|
|
|
{
|
|
|
|
stringBuilder.append(listStack.toString() + " ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LogHelper.info(stringBuilder.toString());
|
|
|
|
}
|
|
|
|
}
|
2014-06-14 21:40:45 +02:00
|
|
|
}
|