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;
|
|
|
|
import com.google.common.collect.Multimap;
|
2014-07-07 21:31:10 +02:00
|
|
|
import com.pahimar.ee3.exchange.WrappedStack;
|
|
|
|
import com.pahimar.ee3.item.crafting.RecipeAludel;
|
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;
|
|
|
|
|
|
|
|
private RecipeRegistry()
|
|
|
|
{
|
|
|
|
recipeMap = HashMultimap.create();
|
|
|
|
}
|
|
|
|
|
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-06-14 21:40:45 +02:00
|
|
|
private void init()
|
|
|
|
{
|
|
|
|
// Add recipes in the vanilla crafting manager
|
|
|
|
for (WrappedStack outputStack : RecipesVanilla.getVanillaRecipes().keySet())
|
|
|
|
{
|
|
|
|
for (List<WrappedStack> 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<WrappedStack> 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<WrappedStack> inputStacks : RecipesPotions.getPotionRecipes().get(outputStack))
|
|
|
|
{
|
|
|
|
if (!recipeMap.get(outputStack).contains(inputStacks))
|
|
|
|
{
|
|
|
|
recipeMap.put(outputStack, inputStacks);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add Aludel recipes
|
2014-07-06 18:14:45 +02:00
|
|
|
for (RecipeAludel recipeAludel : RecipesAludel.getInstance().getRecipes())
|
|
|
|
{
|
|
|
|
WrappedStack recipeOutput = new WrappedStack(recipeAludel.getRecipeOutput());
|
|
|
|
List<WrappedStack> recipeInputs = recipeAludel.getRecipeInputsAsWrappedStacks();
|
|
|
|
|
|
|
|
if (!recipeMap.get(recipeOutput).contains(recipeInputs))
|
|
|
|
{
|
|
|
|
recipeMap.put(recipeOutput, recipeInputs);
|
|
|
|
}
|
|
|
|
}
|
2014-06-14 21:40:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public Multimap<WrappedStack, List<WrappedStack>> getRecipeMappings()
|
|
|
|
{
|
|
|
|
return recipeRegistry.recipeMap;
|
|
|
|
}
|
|
|
|
}
|