Package com.pahimar.ee3.recipe

Source Code of com.pahimar.ee3.recipe.RecipeRegistry

package com.pahimar.ee3.recipe;

import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Multimap;
import com.pahimar.ee3.exchange.WrappedStack;

import java.util.ArrayList;
import java.util.List;

public class RecipeRegistry
{
    private static RecipeRegistry recipeRegistry = null;

    private Multimap<WrappedStack, List<WrappedStack>> recipeMap;

    private RecipeRegistry()
    {
        recipeMap = HashMultimap.create();
    }

    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));
        }

        // Add the recipe mapping only if we don't already have it
        if (!recipeMap.get(wrappedRecipeOutput).contains(wrappedRecipeInputList))
        {
            recipeMap.put(wrappedRecipeOutput, wrappedRecipeInputList);
        }
    }

    public void registerVanillaRecipes()
    {
        RecipesVanilla.registerRecipes();
        RecipesFluidContainers.registerRecipes();
        RecipesPotions.registerRecipes();
    }

    public Multimap<WrappedStack, List<WrappedStack>> getRecipeMappings()
    {
        return ImmutableMultimap.copyOf(recipeRegistry.recipeMap);
    }
}
TOP

Related Classes of com.pahimar.ee3.recipe.RecipeRegistry

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.