Added recipe list exporting to json

This commit is contained in:
modmuss50 2015-07-27 14:13:22 +01:00
parent b1682a64bd
commit 3db7271fd1
5 changed files with 181 additions and 0 deletions

View file

@ -17,6 +17,8 @@ import net.minecraftforge.common.MinecraftForge;
import org.apache.commons.lang3.time.StopWatch;
import techreborn.achievement.TRAchievements;
import techreborn.api.recipe.RecipeHandler;
import techreborn.api.recipe.recipeConfig.RecipeConfig;
import techreborn.api.recipe.recipeConfig.RecipeConfigManager;
import techreborn.client.GuiHandler;
import techreborn.command.TechRebornDevCommand;
import techreborn.compat.CompatManager;
@ -60,6 +62,8 @@ public class Core {
for(ICompatModule compatModule : CompatManager.INSTANCE.compatModules){
compatModule.preInit(event);
}
RecipeConfigManager.load(event.getModConfigurationDirectory());
}
@Mod.EventHandler
@ -114,6 +118,8 @@ public class Core {
LogHelper.info(RecipeHandler.recipeList.size() + " recipes loaded");
// RecipeHandler.scanForDupeRecipes();
RecipeConfigManager.save();
}
@Mod.EventHandler

View file

@ -2,6 +2,7 @@ package techreborn.api.recipe;
import net.minecraft.item.ItemStack;
import org.apache.commons.lang3.time.StopWatch;
import techreborn.api.recipe.recipeConfig.RecipeConfigManager;
import techreborn.util.ItemUtils;
import techreborn.util.LogHelper;
@ -61,6 +62,9 @@ public class RecipeHandler {
if (recipeList.contains(recipe)) {
return;
}
if(!RecipeConfigManager.canLoadRecipe(recipe)){
return;
}
if (!machineNames.contains(recipe.getRecipeName())) {
machineNames.add(recipe.getRecipeName());
}

View file

@ -0,0 +1,46 @@
package techreborn.api.recipe.recipeConfig;
public class ConfigItem {
String localName;
String itemName;
int meta;
int stackSize;
public String getItemName() {
return itemName;
}
public void setItemName(String itemName) {
this.itemName = itemName;
}
public int getMeta() {
return meta;
}
public void setMeta(int meta) {
this.meta = meta;
}
public int getStackSize() {
return stackSize;
}
public void setStackSize(int stackSize) {
this.stackSize = stackSize;
}
public String getLocalName() {
return localName;
}
public void setLocalName(String localName) {
this.localName = localName;
}
}

View file

@ -0,0 +1,60 @@
package techreborn.api.recipe.recipeConfig;
import java.util.ArrayList;
public class RecipeConfig {
ArrayList<ConfigItem> inputs;
ArrayList<ConfigItem> outputs;
Boolean enabled;
String machine;
public ArrayList<ConfigItem> getInputs() {
return inputs;
}
public void setInputs(ArrayList<ConfigItem> inputs) {
this.inputs = inputs;
}
public ArrayList<ConfigItem> getOutputs() {
return outputs;
}
public void setOutputs(ArrayList<ConfigItem> outputs) {
this.outputs = outputs;
}
public Boolean getEnabled() {
return enabled;
}
public void setEnabled(Boolean enabled) {
this.enabled = enabled;
}
public String getMachine() {
return machine;
}
public void setMachine(String machine) {
this.machine = machine;
}
public void addInputs(ConfigItem item){
if(inputs == null){
inputs = new ArrayList<ConfigItem>();
}
inputs.add(item);
}
public void addOutputs(ConfigItem item){
if(outputs == null){
outputs = new ArrayList<ConfigItem>();
}
outputs.add(item);
}
}

View file

@ -0,0 +1,65 @@
package techreborn.api.recipe.recipeConfig;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import net.minecraft.item.ItemStack;
import techreborn.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<RecipeConfig>();
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.stackSize);
newItem.setLocalName(stack.getDisplayName());
return newItem;
}
}