Skip to content

Commit

Permalink
Removed one time use and upgradable recipes ot eliminate bugs, moved …
Browse files Browse the repository at this point in the history
…recipe config parsing, Fixed #30, Fixed #21 Fixed #38
  • Loading branch information
gmlaxfanatic committed Aug 12, 2013
1 parent 7a38c26 commit 7b850bf
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 92 deletions.
32 changes: 0 additions & 32 deletions src/com/github/igotyou/FactoryMod/Factorys/ProductionFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -208,44 +208,12 @@ public List<InteractionResponse> 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<ProductionRecipe> outputRecipes=currentRecipe.getOutputRecipes();
String response="Makes available: ";
for(int i=0;i<outputRecipes.size();i++)
{
response+=outputRecipes.get(i).getRecipeName();
if(i<outputRecipes.size()-1)
{
response+=", ";
}
}
response+=".";
responses.add(new InteractionResponse(InteractionResult.SUCCESS,response));
}
return responses;
}

protected void recipeFinished() {
//Remove upgrade and replace it with its upgraded form
currentRecipe.getUpgrades().removeOneFrom(getInventory()).putIn(getInventory(),currentRecipe.getEnchantments());
//Adds new recipes to the factory

for (int i = 0; i < currentRecipe.getOutputRecipes().size();i++)
{
if(!recipes.contains(currentRecipe.getOutputRecipes().get(i)))
{
recipes.add(currentRecipe.getOutputRecipes().get(i));
}
}

//Remove currentRecipe if it only is meant to be used once
if(currentRecipe.getUseOnce())
{
recipes.remove(currentRecipe);
setRecipeToNumber(0);
}
}

@Override
Expand Down
41 changes: 4 additions & 37 deletions src/com/github/igotyou/FactoryMod/managers/ProductionManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import com.github.igotyou.FactoryMod.interfaces.Factory;
import com.github.igotyou.FactoryMod.interfaces.FactoryManager;
import com.github.igotyou.FactoryMod.properties.ProductionProperties;
import com.github.igotyou.FactoryMod.recipes.ProbabilisticEnchantment;
import com.github.igotyou.FactoryMod.utility.InteractionResponse;
import com.github.igotyou.FactoryMod.utility.InteractionResponse.InteractionResult;
import com.github.igotyou.FactoryMod.recipes.ProductionRecipe;
Expand Down Expand Up @@ -172,47 +171,15 @@ public void initConfig(ConfigurationSection productionConfiguration)
{
//Import recipes from config.yml
ConfigurationSection recipeConfiguration=productionConfiguration.getConfigurationSection("recipes");
//Temporary Storage array to store where recipes should point to each other
HashMap<ProductionRecipe,ArrayList> outputRecipes=new HashMap<ProductionRecipe,ArrayList>();
//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<NamedItemStack> inputs = ItemList.fromConfig(configSection.getConfigurationSection("inputs"));
//Inputs of the recipe, empty of there are no inputs
ItemList<NamedItemStack> upgrades = ItemList.fromConfig(configSection.getConfigurationSection("upgrades"));
//Outputs of the recipe, empty of there are no inputs
ItemList<NamedItemStack> outputs = ItemList.fromConfig(configSection.getConfigurationSection("outputs"));
//Enchantments of the recipe, empty of there are no inputs
List<ProbabilisticEnchantment> 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<NamedItemStack>());
productionRecipes.put(title,recipe);
//Store the titles of the recipes that this should point to
ArrayList <String> currentOutputRecipes=new ArrayList<String>();
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<String> 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))
Expand Down
52 changes: 29 additions & 23 deletions src/com/github/igotyou/FactoryMod/recipes/ProductionRecipe.java
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -21,38 +18,38 @@ public class ProductionRecipe implements Recipe
private ItemList<NamedItemStack> upgrades;
private ItemList<NamedItemStack> outputs;
private ItemList<NamedItemStack> repairs;
private List<ProductionRecipe> outputRecipes;
private List<ProbabilisticEnchantment> enchantments;
private boolean useOnce;

public ProductionRecipe(String title,String recipeName,int productionTime,ItemList<NamedItemStack> inputs,ItemList<NamedItemStack> upgrades,
ItemList<NamedItemStack> outputs,List<ProbabilisticEnchantment> enchantments,boolean useOnce, ItemList<NamedItemStack> repairs)
public ProductionRecipe(
String title,
String recipeName,
int productionTime,
ItemList<NamedItemStack> inputs,
ItemList<NamedItemStack> upgrades,
ItemList<NamedItemStack> outputs,
List<ProbabilisticEnchantment> enchantments,
ItemList<NamedItemStack> repairs)
{
this.title=title;
this.recipeName = recipeName;
this.productionTime = productionTime;
this.inputs = inputs;
this.upgrades=upgrades;
this.outputs = outputs;
this.outputRecipes=new ArrayList<ProductionRecipe>();
this.enchantments=enchantments;
this.useOnce=useOnce;
this.repairs=repairs;
}

public ProductionRecipe(String title,String recipeName,int productionTime,ItemList<NamedItemStack> repairs)
{
this(title,recipeName,productionTime,new ItemList<NamedItemStack>(),new ItemList<NamedItemStack>(),new ItemList<NamedItemStack>(),new ArrayList<ProbabilisticEnchantment>(),false,repairs);
this(title,recipeName,productionTime,new ItemList<NamedItemStack>(),new ItemList<NamedItemStack>(),new ItemList<NamedItemStack>(),new ArrayList<ProbabilisticEnchantment>(),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<NamedItemStack> getInputs()
{
Expand Down Expand Up @@ -97,14 +94,23 @@ public int getProductionTime()
{
return productionTime;
}

public List<ProductionRecipe> 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<NamedItemStack> inputs = ItemList.fromConfig(recipeConfig.getConfigurationSection("inputs"));
//Inputs of the recipe, empty of there are no inputs
ItemList<NamedItemStack> upgrades = ItemList.fromConfig(recipeConfig.getConfigurationSection("upgrades"));
//Outputs of the recipe, empty of there are no inputs
ItemList<NamedItemStack> outputs = ItemList.fromConfig(recipeConfig.getConfigurationSection("outputs"));
//Enchantments of the recipe, empty of there are no inputs
List<ProbabilisticEnchantment> 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<NamedItemStack>());
return productionRecipe;
}
}

0 comments on commit 7b850bf

Please sign in to comment.