diff --git a/src/com/github/igotyou/FactoryMod/Factorys/ProductionFactory.java b/src/com/github/igotyou/FactoryMod/Factorys/ProductionFactory.java index 2725eccd..f92fb6f8 100644 --- a/src/com/github/igotyou/FactoryMod/Factorys/ProductionFactory.java +++ b/src/com/github/igotyou/FactoryMod/Factorys/ProductionFactory.java @@ -208,44 +208,12 @@ public List getChestResponse() int percentRepaired=(int) (( (double) amountRepaired)/getProductionFactoryProperties().getRepair()*100); responses.add(new InteractionResponse(InteractionResult.SUCCESS,"Will repair "+String.valueOf(percentRepaired)+"% of the factory with "+currentRecipe.getRepairs().getMultiple(amountRepaired).toString()+".")); } - if(getProductionFactoryProperties().getRepair()!=0) - if(!currentRecipe.getOutputRecipes().isEmpty()) - { - List outputRecipes=currentRecipe.getOutputRecipes(); - String response="Makes available: "; - for(int i=0;i outputRecipes=new HashMap(); + //Import recipes + for(String title:recipeConfiguration.getKeys(false)) { - //Section header in recipe file, also serves as unique identifier for the recipe //All spaces are replaced with udnerscores so they don't disrupt saving format - //There should be a check for uniqueness of this identifier... - ConfigurationSection configSection=recipeConfiguration.getConfigurationSection(title); - title=title.replaceAll(" ","_"); - //Display name of the recipe, Deafult of "Default Name" - String recipeName = configSection.getString("name","Default Name"); - //Production time of the recipe, default of 1 - int productionTime=configSection.getInt("production_time",2); - //Inputs of the recipe, empty of there are no inputs - ItemList inputs = ItemList.fromConfig(configSection.getConfigurationSection("inputs")); - //Inputs of the recipe, empty of there are no inputs - ItemList upgrades = ItemList.fromConfig(configSection.getConfigurationSection("upgrades")); - //Outputs of the recipe, empty of there are no inputs - ItemList outputs = ItemList.fromConfig(configSection.getConfigurationSection("outputs")); - //Enchantments of the recipe, empty of there are no inputs - List enchantments=ProbabilisticEnchantment.listFromConfig(configSection.getConfigurationSection("enchantments")); - //Whether this recipe can only be used once - boolean useOnce = configSection.getBoolean("use_once"); - ProductionRecipe recipe = new ProductionRecipe(title,recipeName,productionTime,inputs,upgrades,outputs,enchantments,useOnce,new ItemList()); - productionRecipes.put(title,recipe); - //Store the titles of the recipes that this should point to - ArrayList currentOutputRecipes=new ArrayList(); - currentOutputRecipes.addAll(configSection.getStringList("output_recipes")); - outputRecipes.put(recipe,currentOutputRecipes); - } - //Once ProductionRecipe objects have been created correctly insert different pointers - for(ProductionRecipe recipe:outputRecipes.keySet()) - { - Iterator outputIterator=outputRecipes.get(recipe).iterator(); - while(outputIterator.hasNext()) - { - recipe.addOutputRecipe(productionRecipes.get(outputIterator.next())); - } - FactoryModPlugin.sendConsoleMessage("Added Recipe: "+recipe.getRecipeName()); + productionRecipes.put(title.replaceAll(" ","_"),ProductionRecipe.fromConfig(title.replaceAll(" ","_"), recipeConfiguration.getConfigurationSection(title))); } + //Import factories ConfigurationSection factoryConfiguration=productionConfiguration.getConfigurationSection("factories"); for(String title:factoryConfiguration.getKeys(false)) diff --git a/src/com/github/igotyou/FactoryMod/recipes/ProductionRecipe.java b/src/com/github/igotyou/FactoryMod/recipes/ProductionRecipe.java index 10d85dc2..d0b437de 100644 --- a/src/com/github/igotyou/FactoryMod/recipes/ProductionRecipe.java +++ b/src/com/github/igotyou/FactoryMod/recipes/ProductionRecipe.java @@ -1,15 +1,12 @@ package com.github.igotyou.FactoryMod.recipes; -import java.util.HashMap; -import java.util.Random; import java.util.ArrayList; import java.util.List; -import org.bukkit.enchantments.Enchantment; - import com.github.igotyou.FactoryMod.interfaces.Recipe; import com.github.igotyou.FactoryMod.utility.ItemList; import com.github.igotyou.FactoryMod.utility.NamedItemStack; +import org.bukkit.configuration.ConfigurationSection; import org.bukkit.inventory.Inventory; public class ProductionRecipe implements Recipe @@ -21,12 +18,17 @@ public class ProductionRecipe implements Recipe private ItemList upgrades; private ItemList outputs; private ItemList repairs; - private List outputRecipes; private List enchantments; - private boolean useOnce; - public ProductionRecipe(String title,String recipeName,int productionTime,ItemList inputs,ItemList upgrades, - ItemList outputs,List enchantments,boolean useOnce, ItemList repairs) + public ProductionRecipe( + String title, + String recipeName, + int productionTime, + ItemList inputs, + ItemList upgrades, + ItemList outputs, + List enchantments, + ItemList repairs) { this.title=title; this.recipeName = recipeName; @@ -34,25 +36,20 @@ public ProductionRecipe(String title,String recipeName,int productionTime,ItemLi this.inputs = inputs; this.upgrades=upgrades; this.outputs = outputs; - this.outputRecipes=new ArrayList(); this.enchantments=enchantments; - this.useOnce=useOnce; this.repairs=repairs; } public ProductionRecipe(String title,String recipeName,int productionTime,ItemList repairs) { - this(title,recipeName,productionTime,new ItemList(),new ItemList(),new ItemList(),new ArrayList(),false,repairs); + this(title,recipeName,productionTime,new ItemList(),new ItemList(),new ItemList(),new ArrayList(),repairs); } public boolean hasMaterials(Inventory inventory) { return inputs.allIn(inventory)&&upgrades.oneIn(inventory)&&repairs.allIn(inventory); } - public void addOutputRecipe(ProductionRecipe outputRecipe) - { - this.outputRecipes.add(outputRecipe); - } + public ItemList getInputs() { @@ -97,14 +94,23 @@ public int getProductionTime() { return productionTime; } - - public List getOutputRecipes() - { - return outputRecipes; - } - - public boolean getUseOnce() + + public static ProductionRecipe fromConfig(String title, ConfigurationSection recipeConfig) { - return useOnce; + //Display name of the recipe, Deafult of "Default Name" + String recipeName = recipeConfig.getString("name","Default Name"); + //Production time of the recipe, default of 1 + int productionTime=recipeConfig.getInt("production_time",2); + //Inputs of the recipe, empty of there are no inputs + ItemList inputs = ItemList.fromConfig(recipeConfig.getConfigurationSection("inputs")); + //Inputs of the recipe, empty of there are no inputs + ItemList upgrades = ItemList.fromConfig(recipeConfig.getConfigurationSection("upgrades")); + //Outputs of the recipe, empty of there are no inputs + ItemList outputs = ItemList.fromConfig(recipeConfig.getConfigurationSection("outputs")); + //Enchantments of the recipe, empty of there are no inputs + List enchantments=ProbabilisticEnchantment.listFromConfig(recipeConfig.getConfigurationSection("enchantments")); + //Whether this recipe can only be used once + ProductionRecipe productionRecipe = new ProductionRecipe(title,recipeName,productionTime,inputs,upgrades,outputs,enchantments,new ItemList()); + return productionRecipe; } }