diff --git a/src/main/java/techreborn/Core.java b/src/main/java/techreborn/Core.java index b29ca2428..dbf7ec47a 100644 --- a/src/main/java/techreborn/Core.java +++ b/src/main/java/techreborn/Core.java @@ -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 diff --git a/src/main/java/techreborn/api/recipe/RecipeHandler.java b/src/main/java/techreborn/api/recipe/RecipeHandler.java index cb8471df4..c3afbeb2f 100644 --- a/src/main/java/techreborn/api/recipe/RecipeHandler.java +++ b/src/main/java/techreborn/api/recipe/RecipeHandler.java @@ -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()); } diff --git a/src/main/java/techreborn/api/recipe/recipeConfig/ConfigItem.java b/src/main/java/techreborn/api/recipe/recipeConfig/ConfigItem.java new file mode 100644 index 000000000..bf9dcf1aa --- /dev/null +++ b/src/main/java/techreborn/api/recipe/recipeConfig/ConfigItem.java @@ -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; + } +} diff --git a/src/main/java/techreborn/api/recipe/recipeConfig/RecipeConfig.java b/src/main/java/techreborn/api/recipe/recipeConfig/RecipeConfig.java new file mode 100644 index 000000000..f364ff8d7 --- /dev/null +++ b/src/main/java/techreborn/api/recipe/recipeConfig/RecipeConfig.java @@ -0,0 +1,60 @@ +package techreborn.api.recipe.recipeConfig; + +import java.util.ArrayList; + +public class RecipeConfig { + + ArrayList inputs; + + ArrayList outputs; + + Boolean enabled; + + String machine; + + public ArrayList getInputs() { + return inputs; + } + + public void setInputs(ArrayList inputs) { + this.inputs = inputs; + } + + public ArrayList getOutputs() { + return outputs; + } + + public void setOutputs(ArrayList 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(); + } + inputs.add(item); + } + + public void addOutputs(ConfigItem item){ + if(outputs == null){ + outputs = new ArrayList(); + } + outputs.add(item); + } +} diff --git a/src/main/java/techreborn/api/recipe/recipeConfig/RecipeConfigManager.java b/src/main/java/techreborn/api/recipe/recipeConfig/RecipeConfigManager.java new file mode 100644 index 000000000..c413f87dd --- /dev/null +++ b/src/main/java/techreborn/api/recipe/recipeConfig/RecipeConfigManager.java @@ -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 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.stackSize); + newItem.setLocalName(stack.getDisplayName()); + return newItem; + } + +}