diff --git a/src/main/java/iguanaman/iguanatweakstconstruct/reference/Config.java b/src/main/java/iguanaman/iguanatweakstconstruct/reference/Config.java index d11f306..f681272 100644 --- a/src/main/java/iguanaman/iguanatweakstconstruct/reference/Config.java +++ b/src/main/java/iguanaman/iguanatweakstconstruct/reference/Config.java @@ -62,8 +62,12 @@ public class Config { public static int recipeGravelPerFlint; public static boolean disableStoneTools; public static boolean castsBurnMaterial; + public static boolean easyToolRepair; public static boolean easyPartCrafting; + public static boolean easyToolBuilding; + public static boolean easyAdvancedToolBuilding; + public static boolean allowPartReuse; public static boolean removeStoneTorchRecipe; public static boolean moreExpensiveSilkyCloth; @@ -188,10 +192,14 @@ public class Config { // ticon tweaks disableStoneTools = configfile.getBoolean("disableStoneTools", CATEGORY_Tweaks, true, "Stone Tools can only be used to create casts, but no tools"); castsBurnMaterial = configfile.getBoolean("castingBurnsMaterial", CATEGORY_Tweaks, true, "Creating a metal cast burns up the material that was used to create it"); - easyToolRepair = configfile.getBoolean("easyToolRepair", CATEGORY_Tweaks, true, "Allows to repair your tool in a crafting grid, without tool station"); - easyPartCrafting = configfile.getBoolean("easyPartCrafting", CATEGORY_Tweaks, false, "Allows to craft tool parts with a pattern and the material in any crafting grid."); allowPartReuse = configfile.getBoolean("allowPartReuse", CATEGORY_Tweaks, true, "Allows toolparts to be used as material in the Part Builder. Like, turn a Pick head into a Shovel head.!"); + // easy crafting + easyToolRepair = configfile.getBoolean("easyToolRepair", CATEGORY_Tweaks, true, "Allows to repair your tool in a crafting grid, without tool station"); + easyPartCrafting = configfile.getBoolean("easyPartCrafting", CATEGORY_Tweaks, false, "Allows to craft tool parts with a pattern and the material in any crafting grid."); + easyToolBuilding = configfile.getBoolean("easyToolBuilding", CATEGORY_Tweaks, false, "Allows to create Tool Station Tools (2-3 Parts) in any crafting grid"); + easyAdvancedToolBuilding = configfile.getBoolean("easyToolBuildingForge", CATEGORY_Tweaks, false, "Allows to also create Tool Forge Tools (4 Parts) in any crafting grid"); + // stuff removeStoneTorchRecipe = configfile.getBoolean("removeStoneTorchRecipe", CATEGORY_Tweaks, false, "Removes the recipe for Tinker's Construct's stone torch"); moreExpensiveSilkyCloth = configfile.getBoolean("moreExpensiveSilkyCloth", CATEGORY_Tweaks, true, "Silky Cloth needs gold ingots, instead of nuggets"); diff --git a/src/main/java/iguanaman/iguanatweakstconstruct/tweaks/IguanaTweaks.java b/src/main/java/iguanaman/iguanatweakstconstruct/tweaks/IguanaTweaks.java index 72ceab4..41bc2a9 100644 --- a/src/main/java/iguanaman/iguanatweakstconstruct/tweaks/IguanaTweaks.java +++ b/src/main/java/iguanaman/iguanatweakstconstruct/tweaks/IguanaTweaks.java @@ -147,6 +147,9 @@ public class IguanaTweaks { if(Config.easyPartCrafting) GameRegistry.addRecipe(new PartCraftingRecipe()); + + if(Config.easyToolBuilding) + GameRegistry.addRecipe(new ToolCraftingRecipe()); } private void flintTweaks() diff --git a/src/main/java/iguanaman/iguanatweakstconstruct/tweaks/ToolCraftingRecipe.java b/src/main/java/iguanaman/iguanatweakstconstruct/tweaks/ToolCraftingRecipe.java new file mode 100644 index 0000000..01d4f3e --- /dev/null +++ b/src/main/java/iguanaman/iguanatweakstconstruct/tweaks/ToolCraftingRecipe.java @@ -0,0 +1,114 @@ +package iguanaman.iguanatweakstconstruct.tweaks; + +import com.google.common.collect.Sets; +import iguanaman.iguanatweakstconstruct.reference.Config; +import iguanaman.iguanatweakstconstruct.reference.Reference; +import net.minecraft.inventory.InventoryCrafting; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.IRecipe; +import net.minecraft.world.World; +import net.minecraftforge.oredict.RecipeSorter; +import tconstruct.library.crafting.ToolBuilder; +import tconstruct.library.tools.ToolCore; +import tconstruct.library.util.IToolPart; + +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; + +public class ToolCraftingRecipe implements IRecipe { + static { + // register the recipe with the recipesorter + RecipeSorter.register(Reference.MOD_ID + ":tool", RepairCraftingRecipe.class, RecipeSorter.Category.SHAPELESS, ""); + } + + private ItemStack outputTool; + + @Override + public boolean matches(InventoryCrafting inventoryCrafting, World world) { + outputTool = null; + + List input = new LinkedList(); + + for(int i = 0; i < inventoryCrafting.getSizeInventory(); i++) + { + ItemStack slot = inventoryCrafting.getStackInSlot(i); + // empty slot + if(slot == null) + continue; + + // is it a toolpart? + if(!(slot.getItem() instanceof IToolPart)) + return false; + + // save it + input.add(slot); + } + + // check correct size + if(input.size() < 2 || (input.size() > 3 && !Config.easyAdvancedToolBuilding)) + return false; + + // ok. we have to cycle through all permutations. urgh. + Set> permutations = new HashSet>(); + permutate(new LinkedList(), input, permutations); + + for(List comb : permutations) + { + ItemStack tool = null; + ItemStack accessory = null, extra = null; + if(comb.size() > 2) + accessory = comb.get(2); + if(comb.size() > 3) + extra = comb.get(3); + + // try this combination xX + tool = ToolBuilder.instance.buildTool(comb.get(0), comb.get(1), accessory, extra, ""); + + if(tool != null) + { + outputTool = tool; + return true; + } + } + + return false; + } + + private void permutate(List cur, List rest, Set> output) + { + // if we reached the last element, add the combination to the output + if(rest.size() == 1) { + List out = new LinkedList(cur); + out.add(rest.get(0)); + output.add(out); + } + // otherwise recursively cycle through all other variations + else { + for(ItemStack foo : rest) + { + List newCur = new LinkedList(cur); + List newRest = new LinkedList(rest); + newCur.add(foo); + newRest.remove(foo); + permutate(newCur, newRest, output); + } + } + } + + @Override + public ItemStack getCraftingResult(InventoryCrafting p_77572_1_) { + return outputTool; + } + + @Override + public int getRecipeSize() { + return 2; + } + + @Override + public ItemStack getRecipeOutput() { + return outputTool; + } +}