Update to support updated recipe format in reborn core.

This commit is contained in:
modmuss50 2017-01-08 21:43:15 +00:00
parent d435d5d772
commit 6aa8fde64a
No known key found for this signature in database
GPG key ID: 203A5ED4D3E48BEA
7 changed files with 54 additions and 91 deletions

View file

@ -3,6 +3,7 @@ package techreborn.api.recipe;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import reborncore.api.recipe.IBaseRecipeType;
import reborncore.common.recipes.RecipeTranslator;
import java.security.InvalidParameterException;
import java.util.ArrayList;
@ -16,7 +17,7 @@ public abstract class BaseRecipe implements IBaseRecipeType, Cloneable {
public String name;
public int tickTime;
public int euPerTick;
private ArrayList<ItemStack> inputs;
private ArrayList<Object> inputs;
private ArrayList<ItemStack> outputs;
private boolean oreDict = true;
@ -47,7 +48,7 @@ public abstract class BaseRecipe implements IBaseRecipeType, Cloneable {
}
@Override
public List<ItemStack> getInputs() {
public List<Object> getInputs() {
return inputs;
}
@ -101,10 +102,18 @@ public abstract class BaseRecipe implements IBaseRecipeType, Cloneable {
return outputs;
}
public void addInput(ItemStack inuput) {
if (inuput == null || inuput.isEmpty()) {
public void addInput(Object inuput) {
if (inuput == null) {
throw new InvalidParameterException("input is invalid!");
}
if(inuput instanceof ItemStack){
if(((ItemStack) inuput).isEmpty()){
throw new InvalidParameterException("input is invalid!");
}
}
if(RecipeTranslator.getStackFromObject(inuput) == null){
throw new InvalidParameterException("Could not determin recipe input for " + inuput);
}
inputs.add(inuput);
}
}

View file

@ -1,63 +0,0 @@
package techreborn.api.recipe.recipeConfig;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import net.minecraft.item.ItemStack;
import reborncore.api.recipe.IBaseRecipeType;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
public class RecipeConfigManager {
public static ArrayList<RecipeConfig> configs = new ArrayList<>();
static File configFile = null;
public static void load(File configDir) {
if (configFile == null) {
configFile = new File(configDir, "techRebornRecipes.json");
}
}
public static void save() {
if (configFile.exists()) {
configFile.delete();
}
Gson gson = new GsonBuilder().setPrettyPrinting().create();
String json = gson.toJson(configs);
try {
FileWriter writer = new FileWriter(configFile);
writer.write(json);
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public static boolean canLoadRecipe(IBaseRecipeType recipeType) {
RecipeConfig config = new RecipeConfig();
for (ItemStack stack : recipeType.getInputs()) {
config.addInputs(itemToConfig(stack));
}
for (ItemStack stack : recipeType.getOutputs()) {
config.addOutputs(itemToConfig(stack));
}
config.enabled = true;
config.setMachine(recipeType.getRecipeName());
configs.add(config);
return config.enabled;
}
public static ConfigItem itemToConfig(ItemStack stack) {
ConfigItem newItem = new ConfigItem();
newItem.setItemName(stack.getItem().getUnlocalizedName());
newItem.setMeta(stack.getItemDamage());
newItem.setStackSize(stack.getCount());
newItem.setLocalName(stack.getDisplayName());
return newItem;
}
}