From 531cebbca6ca35959b4dbb95fbbaa471c7a6239b Mon Sep 17 00:00:00 2001 From: Bernhard Bonigl Date: Fri, 15 Aug 2014 16:34:39 +0200 Subject: [PATCH] Add easy part crafting in the crafting window --- .../reference/Config.java | 2 + .../tweaks/IguanaTweaks.java | 3 + .../tweaks/PartCraftingRecipe.java | 87 +++++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 src/main/java/iguanaman/iguanatweakstconstruct/tweaks/PartCraftingRecipe.java diff --git a/src/main/java/iguanaman/iguanatweakstconstruct/reference/Config.java b/src/main/java/iguanaman/iguanatweakstconstruct/reference/Config.java index b93d9b6..d11f306 100644 --- a/src/main/java/iguanaman/iguanatweakstconstruct/reference/Config.java +++ b/src/main/java/iguanaman/iguanatweakstconstruct/reference/Config.java @@ -63,6 +63,7 @@ public class Config { public static boolean disableStoneTools; public static boolean castsBurnMaterial; public static boolean easyToolRepair; + public static boolean easyPartCrafting; public static boolean allowPartReuse; public static boolean removeStoneTorchRecipe; public static boolean moreExpensiveSilkyCloth; @@ -188,6 +189,7 @@ public class Config { 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.!"); // stuff diff --git a/src/main/java/iguanaman/iguanatweakstconstruct/tweaks/IguanaTweaks.java b/src/main/java/iguanaman/iguanatweakstconstruct/tweaks/IguanaTweaks.java index ce6fb1e..72ceab4 100644 --- a/src/main/java/iguanaman/iguanatweakstconstruct/tweaks/IguanaTweaks.java +++ b/src/main/java/iguanaman/iguanatweakstconstruct/tweaks/IguanaTweaks.java @@ -144,6 +144,9 @@ public class IguanaTweaks { // has to be added after exchanging the repair modifier, to obtain the correct cache if(Config.easyToolRepair) GameRegistry.addRecipe(new RepairCraftingRecipe()); + + if(Config.easyPartCrafting) + GameRegistry.addRecipe(new PartCraftingRecipe()); } private void flintTweaks() diff --git a/src/main/java/iguanaman/iguanatweakstconstruct/tweaks/PartCraftingRecipe.java b/src/main/java/iguanaman/iguanatweakstconstruct/tweaks/PartCraftingRecipe.java new file mode 100644 index 0000000..947cbb7 --- /dev/null +++ b/src/main/java/iguanaman/iguanatweakstconstruct/tweaks/PartCraftingRecipe.java @@ -0,0 +1,87 @@ +package iguanaman.iguanatweakstconstruct.tweaks; + +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.TConstructRegistry; +import tconstruct.library.crafting.PatternBuilder; +import tconstruct.library.tools.ToolCore; +import tconstruct.library.util.IPattern; +import tconstruct.tools.items.Pattern; + +public class PartCraftingRecipe implements IRecipe { + static { + // register the recipe with the recipesorter + RecipeSorter.register(Reference.MOD_ID + ":part", RepairCraftingRecipe.class, RecipeSorter.Category.SHAPELESS, ""); + } + + private ItemStack outputPart; + + @Override + public boolean matches(InventoryCrafting inventoryCrafting, World world) { + outputPart = null; + ItemStack pattern = null; + ItemStack input = null; + + for(int i = 0; i < inventoryCrafting.getSizeInventory(); i++) + { + ItemStack slot = inventoryCrafting.getStackInSlot(i); + // empty slot + if(slot == null) + continue; + + // is it the tool? + if(slot.getItem() instanceof IPattern) { + // only one pattern + if(pattern != null) + return false; + + pattern = slot; + // otherwise.. input material + } + else { + if(input != null) + return false; + + input = slot; + } + } + + if(pattern == null || input == null) + return false; + + // make sure it's a valid pattern + if(!PatternBuilder.instance.toolPatterns.contains(pattern.getItem())) + return false; + + ItemStack[] output = PatternBuilder.instance.getToolPart(input, pattern, null); + if(output == null) + return false; + + for(ItemStack stack : output) + if(stack != null) { + outputPart = stack; + return true; + } + + return false; + } + + @Override + public ItemStack getCraftingResult(InventoryCrafting inventory) { + return outputPart; + } + + @Override + public int getRecipeSize() { + return 2; + } + + @Override + public ItemStack getRecipeOutput() { + return outputPart; + } +}