Added command to reload oreDicRecipes

This commit is contained in:
modmuss50 2015-05-09 13:42:47 +01:00
parent 333ba855fe
commit c37858de79
4 changed files with 123 additions and 53 deletions

View file

@ -1,9 +1,12 @@
package techreborn.api.recipe;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
@ -14,6 +17,11 @@ public class RecipeHanderer {
*/
public static ArrayList<IBaseRecipeType> recipeList = new ArrayList<IBaseRecipeType>();
/**
* This is a backedup clone of the master recipeList
*/
public static ArrayList<IBaseRecipeType> recipeListBackup = new ArrayList<IBaseRecipeType>();
/**
* Use this to get all of the recipes form a recipe name
* @param name the name that the recipe was resisted as.
@ -45,68 +53,69 @@ public class RecipeHanderer {
public static void addOreDicRecipes(){
recipeListBackup.clear();
recipeListBackup.addAll(recipeList);
ArrayList<IBaseRecipeType> newRecipes = new ArrayList<IBaseRecipeType>();
for(IBaseRecipeType baseRecipe : recipeList){
if(baseRecipe instanceof BaseRecipe){
int i = 0;
for(ItemStack stack : baseRecipe.getInputs()){
for(int oreId : OreDictionary.getOreIDs(stack)){
for(ItemStack itemStack : OreDictionary.getOres(oreId)){
OreDicRecipe recipe = new OreDicRecipe(baseRecipe.getRecipeName(), ((BaseRecipe) baseRecipe).tickTime, ((BaseRecipe) baseRecipe).tickTime);
recipe.inputs.add(itemStack);
newRecipes.add(recipe);
for (int i = 0; i < baseRecipe.getInputs().size(); i++) {
BaseRecipe newRecipe = (BaseRecipe) baseRecipe;
for(int oreId : OreDictionary.getOreIDs(((BaseRecipe) baseRecipe).inputs.get(i))){
for(ItemStack itemStack : getInputs(OreDictionary.getOreName(oreId))){
System.out.println(itemStack.getDisplayName());
newRecipe.inputs.set(i, itemStack);
}
}
newRecipes.add(newRecipe);
}
for (int i = 0; i < baseRecipe.getOutputs().size(); i++) {
BaseRecipe newRecipe = (BaseRecipe) baseRecipe;
for(int oreId : OreDictionary.getOreIDs(((BaseRecipe) baseRecipe).outputs.get(i))){
for(ItemStack itemStack : OreDictionary.getOres(OreDictionary.getOreName(oreId))){
newRecipe.outputs.set(i, itemStack);
}
}
newRecipes.add(newRecipe);
}
}
}
recipeList.addAll(newRecipes);
}
public static List<ItemStack> getInputs(String name) {
List ores = getOres(name);
boolean hasInvalidEntries = false;
Iterator ret = ores.iterator();
while(ret.hasNext()) {
ItemStack i$ = (ItemStack)ret.next();
if(i$.getItem() == null) {
hasInvalidEntries = true;
break;
}
}
if(!hasInvalidEntries) {
return ores;
} else {
ArrayList ret1 = new ArrayList(ores.size());
Iterator i$1 = ores.iterator();
while(i$1.hasNext()) {
ItemStack stack = (ItemStack)i$1.next();
if(stack.getItem() != null) {
ret1.add(stack);
}
}
return Collections.unmodifiableList(ret1);
}
}
public static class OreDicRecipe implements IBaseRecipeType{
public ArrayList<ItemStack> inputs;
public ArrayList<ItemStack> outputs;
public String name;
public int tickTime;
public int euPerTick;
public OreDicRecipe(String name, int tickTime, int euPerTick) {
inputs = new ArrayList<ItemStack>();
outputs = new ArrayList<ItemStack>();
this.name = name;
//This adds all new recipes
this.tickTime = tickTime;
this.euPerTick = euPerTick;
}
@Override
public List<ItemStack> getOutputs() {
return outputs;
}
@Override
public List<ItemStack> getInputs() {
return inputs;
}
@Override
public String getRecipeName() {
return name;
}
@Override
public int tickTime() {
return tickTime;
}
@Override
public int euPerTick() {
return euPerTick;
}
private static List<ItemStack> getOres(String name) {
ArrayList ret = OreDictionary.getOres(name);
return ret;
}
}