ActuallyAdditions/src/main/java/ellpeck/actuallyadditions/recipe/CrusherRecipeManualRegistry.java

103 lines
4.6 KiB
Java
Raw Normal View History

2015-03-07 12:51:28 +01:00
package ellpeck.actuallyadditions.recipe;
import ellpeck.actuallyadditions.config.values.ConfigBoolValues;
import ellpeck.actuallyadditions.util.ModUtil;
import ellpeck.actuallyadditions.util.Util;
import net.minecraft.item.ItemStack;
2015-05-07 16:36:29 +02:00
import net.minecraftforge.oredict.OreDictionary;
import java.util.ArrayList;
public class CrusherRecipeManualRegistry{
public static ArrayList<CrusherRecipe> recipes = new ArrayList<CrusherRecipe>();
public static void registerRecipe(ItemStack input, ItemStack outputOne, ItemStack outputTwo, int secondChance){
if(!hasRecipe(input, outputOne)){
recipes.add(new CrusherRecipe(input, outputOne, outputTwo, secondChance));
}
}
public static void registerRecipe(String input, String outputOne, int outputOneAmount){
registerRecipe(input, outputOne, "", 0, outputOneAmount, 0);
}
public static void registerRecipe(String input, String outputOne, String outputTwo, int secondChance, int outputOneAmount, int outputTwoAmount){
2015-06-21 02:28:49 +02:00
ArrayList<ItemStack> inputStacks = (ArrayList<ItemStack>)OreDictionary.getOres(input, false);
ArrayList<ItemStack> outputOneStacks = (ArrayList<ItemStack>)OreDictionary.getOres(outputOne, false);
2015-07-01 21:32:48 +02:00
ArrayList<ItemStack> outputTwoStacks = (outputTwo == null || outputTwo.isEmpty()) ? null : (ArrayList<ItemStack>)OreDictionary.getOres(outputTwo, false);
2015-05-07 16:36:29 +02:00
if(inputStacks != null && !inputStacks.isEmpty()){
2015-05-24 13:58:34 +02:00
for(ItemStack anInput : inputStacks){
ItemStack theInput = anInput.copy();
2015-05-07 16:36:29 +02:00
if(outputOneStacks != null && !outputOneStacks.isEmpty()){
2015-05-24 13:58:34 +02:00
for(ItemStack anOutputOne : outputOneStacks){
ItemStack theOutputOne = anOutputOne.copy();
theOutputOne.stackSize = outputOneAmount;
2015-05-07 16:36:29 +02:00
if(outputTwoStacks != null && !outputTwoStacks.isEmpty()){
2015-05-24 13:58:34 +02:00
for(ItemStack anOutputTwo : outputTwoStacks){
ItemStack theOutputTwo = anOutputTwo.copy();
theOutputTwo.stackSize = outputTwoAmount;
2015-06-21 02:28:49 +02:00
registerRecipe(theInput, theOutputOne, theOutputTwo, secondChance);
2015-05-07 16:36:29 +02:00
}
}
2015-06-21 02:28:49 +02:00
else registerRecipe(theInput, theOutputOne, null, 0);
2015-05-07 16:36:29 +02:00
}
}
else{
if(ConfigBoolValues.DO_CRUSHER_SPAM.isEnabled())
2015-07-01 18:14:21 +02:00
ModUtil.LOGGER.warn("Couldn't register Crusher Recipe! An Item with OreDictionary Registry '" + outputOne + "' doesn't exist! It should be the output of '" + input + "'!");
}
2015-05-07 16:36:29 +02:00
}
}
else{
if(ConfigBoolValues.DO_CRUSHER_SPAM.isEnabled())
2015-07-01 18:14:21 +02:00
ModUtil.LOGGER.warn("Couldn't register Crusher Recipe! Didn't find Items registered as '"+input+"'!");
}
2015-05-07 16:36:29 +02:00
}
2015-06-21 02:28:49 +02:00
public static void registerRecipe(ItemStack input, ItemStack outputOne){
registerRecipe(input, outputOne, null, 0);
2015-05-07 16:36:29 +02:00
}
2015-06-21 02:28:49 +02:00
public static ItemStack getOutput(ItemStack input, boolean wantSecond){
for(CrusherRecipe recipe : recipes){
if(recipe.input.isItemEqual(input) || (recipe.input.getItem() == input.getItem() && recipe.input.getItemDamage() == Util.WILDCARD)){
return wantSecond ? recipe.secondOutput : recipe.firstOutput;
}
}
return null;
}
2015-06-21 02:28:49 +02:00
public static boolean hasRecipe(ItemStack input, ItemStack outputOne){
for(CrusherRecipe recipe : recipes){
if(recipe.input.isItemEqual(input) && recipe.firstOutput.isItemEqual(outputOne) || (recipe.input.getItem() == input.getItem() && recipe.firstOutput.getItem() == outputOne.getItem() && recipe.input.getItemDamage() == Util.WILDCARD)) return true;
2015-05-04 17:26:50 +02:00
}
2015-05-25 17:00:54 +02:00
return false;
2015-05-04 17:26:50 +02:00
}
2015-06-21 02:28:49 +02:00
public static int getSecondChance(ItemStack input){
for(CrusherRecipe recipe : recipes){
if(recipe.input.isItemEqual(input) || (recipe.input.getItem() == input.getItem() && recipe.input.getItemDamage() == Util.WILDCARD)){
return recipe.secondChance;
}
}
return 0;
}
public static class CrusherRecipe{
public final ItemStack input;
public final ItemStack firstOutput;
public final ItemStack secondOutput;
public final int secondChance;
public CrusherRecipe(ItemStack input, ItemStack firstOutput, ItemStack secondOutput, int secondChance){
this.input = input;
this.firstOutput = firstOutput;
this.secondOutput = secondOutput;
this.secondChance = secondChance;
}
}
}