2016-06-23 03:49:47 +00:00
|
|
|
/*
|
|
|
|
* Minecraft Forge
|
|
|
|
* Copyright (c) 2016.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation version 2.1
|
|
|
|
* of the License.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
2015-05-18 01:11:07 +00:00
|
|
|
package net.minecraftforge.common.brewing;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2016-11-13 22:09:54 +00:00
|
|
|
import net.minecraft.util.NonNullList;
|
|
|
|
|
|
|
|
import javax.annotation.Nonnull;
|
2015-05-18 01:11:07 +00:00
|
|
|
|
|
|
|
public class BrewingRecipeRegistry {
|
|
|
|
|
|
|
|
private static List<IBrewingRecipe> recipes = new ArrayList<IBrewingRecipe>();
|
|
|
|
|
|
|
|
static
|
|
|
|
{
|
|
|
|
addRecipe(new VanillaBrewingRecipe());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a recipe to the registry. Due to the nature of the brewing stand
|
|
|
|
* inputs that stack (a.k.a max stack size > 1) are not allowed.
|
2016-03-08 07:34:40 +00:00
|
|
|
*
|
2015-05-18 01:11:07 +00:00
|
|
|
* @param input
|
|
|
|
* The ItemStack that goes in same slots as the water bottles
|
|
|
|
* would.
|
|
|
|
* @param ingredient
|
|
|
|
* The ItemStack that goes in the same slot as nether wart would.
|
|
|
|
* @param output
|
|
|
|
* The ItemStack that will replace the input once the brewing is
|
|
|
|
* done.
|
|
|
|
* @return true if the recipe was added.
|
|
|
|
*/
|
2016-11-18 21:24:03 +00:00
|
|
|
public static boolean addRecipe(@Nonnull ItemStack input, @Nonnull ItemStack ingredient, @Nonnull ItemStack output)
|
2015-05-18 01:11:07 +00:00
|
|
|
{
|
|
|
|
return addRecipe(new BrewingRecipe(input, ingredient, output));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a recipe to the registry. Due to the nature of the brewing stand
|
|
|
|
* inputs that stack (a.k.a max stack size > 1) are not allowed.
|
2016-03-08 07:34:40 +00:00
|
|
|
*
|
2015-05-18 01:11:07 +00:00
|
|
|
* @param input
|
|
|
|
* The ItemStack that goes in same slots as the water bottles
|
|
|
|
* would.
|
|
|
|
* @param ingredient
|
|
|
|
* The ItemStack that goes in the same slot as nether wart would.
|
|
|
|
* @param output
|
|
|
|
* The ItemStack that will replace the input once the brewing is
|
|
|
|
* done.
|
|
|
|
* @return true if the recipe was added.
|
|
|
|
*/
|
2016-11-18 21:24:03 +00:00
|
|
|
public static boolean addRecipe(@Nonnull ItemStack input, @Nonnull String ingredient, @Nonnull ItemStack output)
|
2015-05-18 01:11:07 +00:00
|
|
|
{
|
|
|
|
return addRecipe(new BrewingOreRecipe(input, ingredient, output));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a recipe to the registry. Due to the nature of the brewing stand
|
|
|
|
* inputs that stack (a.k.a max stack size > 1) are not allowed.
|
|
|
|
*/
|
|
|
|
public static boolean addRecipe(IBrewingRecipe recipe)
|
|
|
|
{
|
|
|
|
return recipes.add(recipe);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the output ItemStack obtained by brewing the passed input and
|
2016-11-18 21:24:03 +00:00
|
|
|
* ingredient.
|
2015-05-18 01:11:07 +00:00
|
|
|
*/
|
2016-11-13 22:09:54 +00:00
|
|
|
@Nonnull
|
2016-11-18 21:24:03 +00:00
|
|
|
public static ItemStack getOutput(@Nonnull ItemStack input, @Nonnull ItemStack ingredient)
|
2015-05-18 01:11:07 +00:00
|
|
|
{
|
2016-12-21 23:52:30 +00:00
|
|
|
if (input.isEmpty() || input.getMaxStackSize() != 1 || input.getCount() != 1) return ItemStack.EMPTY;
|
|
|
|
if (ingredient.isEmpty()) return ItemStack.EMPTY;
|
2015-05-18 01:11:07 +00:00
|
|
|
|
|
|
|
for (IBrewingRecipe recipe : recipes)
|
|
|
|
{
|
|
|
|
ItemStack output = recipe.getOutput(input, ingredient);
|
|
|
|
if (output != null)
|
|
|
|
{
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
}
|
2016-12-21 23:52:30 +00:00
|
|
|
return ItemStack.EMPTY;
|
2015-05-18 01:11:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the passed input and ingredient have an output
|
|
|
|
*/
|
2016-11-18 21:24:03 +00:00
|
|
|
public static boolean hasOutput(@Nonnull ItemStack input, @Nonnull ItemStack ingredient)
|
2015-05-18 01:11:07 +00:00
|
|
|
{
|
2016-12-21 23:52:30 +00:00
|
|
|
return !getOutput(input, ingredient).isEmpty();
|
2015-05-18 01:11:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used by the brewing stand to determine if its contents can be brewed.
|
|
|
|
* Extra parameters exist to allow modders to create bigger brewing stands
|
|
|
|
* without much hassle
|
|
|
|
*/
|
2016-11-13 22:09:54 +00:00
|
|
|
public static boolean canBrew(NonNullList<ItemStack> inputs, @Nonnull ItemStack ingredient, int[] inputIndexes)
|
2015-05-18 01:11:07 +00:00
|
|
|
{
|
2016-12-21 23:52:30 +00:00
|
|
|
if (ingredient.isEmpty()) return false;
|
2015-05-18 01:11:07 +00:00
|
|
|
|
|
|
|
for (int i : inputIndexes)
|
|
|
|
{
|
2016-11-13 22:09:54 +00:00
|
|
|
if (hasOutput(inputs.get(i), ingredient))
|
2015-05-18 01:11:07 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used by the brewing stand to brew its inventory Extra parameters exist to
|
|
|
|
* allow modders to create bigger brewing stands without much hassle
|
|
|
|
*/
|
2016-11-13 22:09:54 +00:00
|
|
|
public static void brewPotions(NonNullList<ItemStack> inputs, @Nonnull ItemStack ingredient, int[] inputIndexes)
|
2015-05-18 01:11:07 +00:00
|
|
|
{
|
|
|
|
for (int i : inputIndexes)
|
|
|
|
{
|
2016-11-13 22:09:54 +00:00
|
|
|
ItemStack output = getOutput(inputs.get(i), ingredient);
|
2016-12-21 23:52:30 +00:00
|
|
|
if (!output.isEmpty())
|
2015-05-18 01:11:07 +00:00
|
|
|
{
|
2016-11-13 22:09:54 +00:00
|
|
|
inputs.set(i, output);
|
2015-05-18 01:11:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the passed ItemStack is a valid ingredient for any of the
|
|
|
|
* recipes in the registry.
|
|
|
|
*/
|
2016-11-13 22:09:54 +00:00
|
|
|
public static boolean isValidIngredient(@Nonnull ItemStack stack)
|
2015-05-18 01:11:07 +00:00
|
|
|
{
|
2016-12-21 23:52:30 +00:00
|
|
|
if (stack.isEmpty()) return false;
|
2015-05-18 01:11:07 +00:00
|
|
|
|
|
|
|
for (IBrewingRecipe recipe : recipes)
|
|
|
|
{
|
|
|
|
if (recipe.isIngredient(stack))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the passed ItemStack is a valid input for any of the
|
|
|
|
* recipes in the registry.
|
|
|
|
*/
|
2016-11-13 22:09:54 +00:00
|
|
|
public static boolean isValidInput(@Nonnull ItemStack stack)
|
2015-05-18 01:11:07 +00:00
|
|
|
{
|
2016-12-21 23:52:30 +00:00
|
|
|
if (stack.getMaxStackSize() != 1 || stack.getCount() != 1) return false;
|
2015-05-18 01:11:07 +00:00
|
|
|
|
|
|
|
for (IBrewingRecipe recipe : recipes)
|
|
|
|
{
|
|
|
|
if (recipe.isInput(stack))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an unmodifiable list containing all the recipes in the registry
|
|
|
|
*/
|
|
|
|
public static List<IBrewingRecipe> getRecipes()
|
|
|
|
{
|
|
|
|
return Collections.unmodifiableList(recipes);
|
|
|
|
}
|
2016-03-08 07:34:40 +00:00
|
|
|
}
|