2015-03-07 12:51:28 +01:00
|
|
|
package ellpeck.actuallyadditions.recipe;
|
2015-03-07 02:23:31 +01:00
|
|
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
2015-05-07 16:36:29 +02:00
|
|
|
import net.minecraftforge.oredict.OreDictionary;
|
2015-03-07 02:23:31 +01:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
public class GrinderRecipes{
|
|
|
|
|
|
|
|
private static final GrinderRecipes instance = new GrinderRecipes();
|
|
|
|
|
|
|
|
public ArrayList<GrinderRecipe> recipes = new ArrayList<GrinderRecipe>();
|
|
|
|
|
|
|
|
public static GrinderRecipes instance(){
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void registerRecipe(ItemStack input, ItemStack outputOne, ItemStack outputTwo, int secondChance){
|
|
|
|
this.recipes.add(new GrinderRecipe(input, outputOne, outputTwo, secondChance));
|
|
|
|
}
|
|
|
|
|
2015-05-07 16:36:29 +02:00
|
|
|
public void registerRecipe(String input, String outputOne, String outputTwo, int secondChance, int outputTwoAmount){
|
|
|
|
ArrayList<ItemStack> inputStacks = OreDictionary.getOres(input);
|
|
|
|
ArrayList<ItemStack> outputOneStacks = OreDictionary.getOres(outputOne);
|
|
|
|
ArrayList<ItemStack> outputTwoStacks = OreDictionary.getOres(outputTwo);
|
|
|
|
|
|
|
|
if(inputStacks != null && !inputStacks.isEmpty()){
|
|
|
|
for(ItemStack theInput : inputStacks){
|
|
|
|
if(outputOneStacks != null && !outputOneStacks.isEmpty()){
|
|
|
|
for(ItemStack theOutputOne : outputOneStacks){
|
|
|
|
theOutputOne.stackSize = outputTwoAmount;
|
|
|
|
if(outputTwoStacks != null && !outputTwoStacks.isEmpty()){
|
|
|
|
for(ItemStack theOutputTwo : outputTwoStacks){
|
|
|
|
this.registerRecipe(theInput, theOutputOne, theOutputTwo, secondChance);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else this.registerRecipe(theInput, theOutputOne, null, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void registerRecipe(String input, String outputOne){
|
|
|
|
this.registerRecipe(input, outputOne, "", 0, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void registerRecipe(ItemStack input, ItemStack outputOne){
|
|
|
|
this.registerRecipe(input, outputOne, null, 0);
|
|
|
|
}
|
|
|
|
|
2015-03-07 02:23:31 +01:00
|
|
|
public ItemStack getOutput(ItemStack input, boolean wantSecond){
|
|
|
|
for(GrinderRecipe recipe : recipes){
|
|
|
|
if(recipe.input.isItemEqual(input)){
|
|
|
|
return wantSecond ? recipe.secondOutput : recipe.firstOutput;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2015-05-07 16:36:29 +02:00
|
|
|
public boolean hasRecipe(String input, String outputOne){
|
|
|
|
boolean containsInput = false;
|
|
|
|
boolean containsOutput = false;
|
|
|
|
|
2015-05-04 17:26:50 +02:00
|
|
|
for(GrinderRecipe recipe : recipes){
|
2015-05-07 16:36:29 +02:00
|
|
|
int[] recipeInputIDs = OreDictionary.getOreIDs(recipe.input);
|
|
|
|
for(int recipeInputID : recipeInputIDs){
|
|
|
|
if(input.equals(OreDictionary.getOreName(recipeInputID))){
|
|
|
|
containsInput = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int[] recipeOutputIDs = OreDictionary.getOreIDs(recipe.firstOutput);
|
|
|
|
for(int recipeOutputID : recipeOutputIDs){
|
|
|
|
if(outputOne.equals(OreDictionary.getOreName(recipeOutputID))){
|
|
|
|
containsOutput = true;
|
|
|
|
break;
|
|
|
|
}
|
2015-05-04 17:26:50 +02:00
|
|
|
}
|
|
|
|
}
|
2015-05-07 16:36:29 +02:00
|
|
|
return containsInput && containsOutput;
|
2015-05-04 17:26:50 +02:00
|
|
|
}
|
|
|
|
|
2015-03-07 02:23:31 +01:00
|
|
|
public int getSecondChance(ItemStack input){
|
|
|
|
for(GrinderRecipe recipe : recipes){
|
|
|
|
if(recipe.input.isItemEqual(input)){
|
|
|
|
return recipe.secondChance;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public class GrinderRecipe{
|
|
|
|
|
|
|
|
public final ItemStack input;
|
|
|
|
public final ItemStack firstOutput;
|
|
|
|
public final ItemStack secondOutput;
|
|
|
|
public final int secondChance;
|
|
|
|
|
|
|
|
public GrinderRecipe(ItemStack input, ItemStack firstOutput, ItemStack secondOutput, int secondChance){
|
|
|
|
this.input = input;
|
|
|
|
this.firstOutput = firstOutput;
|
|
|
|
this.secondOutput = secondOutput;
|
|
|
|
this.secondChance = secondChance;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|