From 4fce1a924e4394277fff34f8d55e627626960551 Mon Sep 17 00:00:00 2001 From: squeek Date: Mon, 14 Apr 2014 16:57:13 -0700 Subject: [PATCH] Fixed repairing only working with the first 2 crafting slots (it will now work with any slot). Fixes SlimeKnights/TinkersConstruct/#568 --- .../tconstruct/modifiers/tools/ModRepair.java | 62 +++++++++++-------- 1 file changed, 36 insertions(+), 26 deletions(-) diff --git a/src/main/java/tconstruct/modifiers/tools/ModRepair.java b/src/main/java/tconstruct/modifiers/tools/ModRepair.java index 16711043e1a..a3fece18727 100644 --- a/src/main/java/tconstruct/modifiers/tools/ModRepair.java +++ b/src/main/java/tconstruct/modifiers/tools/ModRepair.java @@ -26,20 +26,23 @@ public boolean matches (ItemStack[] input, ItemStack tool) @Override protected boolean canModify (ItemStack tool, ItemStack[] input) { - if ((input[0] == null && input[1] == null)) - return false; - NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool"); if (tags.getInteger("Damage") > 0) { int headID = tags.getInteger("Head"); - if (input[0] != null && input[1] != null) - return headID == PatternBuilder.instance.getPartID(input[0]) && headID == PatternBuilder.instance.getPartID(input[1]) && calculateIfNecessary(tool, input); - else if (input[0] != null && input[1] == null) - return headID == PatternBuilder.instance.getPartID(input[0]); - else if (input[0] == null && input[1] != null) - return headID == PatternBuilder.instance.getPartID(input[1]); - + boolean areInputsValid = true; + for (ItemStack curInput : input) + { + if (curInput != null && headID != PatternBuilder.instance.getPartID(curInput)) + { + areInputsValid = false; + break; + } + } + if (areInputsValid) + { + return calculateIfNecessary(tool, input); + } } return false; } @@ -48,14 +51,23 @@ private boolean calculateIfNecessary (ItemStack tool, ItemStack[] input) { NBTTagCompound tags = tool.getTagCompound().getCompoundTag("InfiTool"); int damage = tags.getInteger("Damage"); - int valueSlot1 = 0; - int valueSlot2 = 0; - if (input[0] != null) - valueSlot1 = calculateIncrease(tool, PatternBuilder.instance.getPartValue(input[0])); - if (input[1] != null) - valueSlot2 = calculateIncrease(tool, PatternBuilder.instance.getPartValue(input[1])); - - return ((damage - valueSlot1) > 0) && ((damage - valueSlot2) > 0); + int numInputs = 0; + int materialValue = 0; + for (ItemStack curInput : input) + { + if (curInput != null) + { + materialValue += PatternBuilder.instance.getPartValue(curInput); + numInputs++; + } + } + if (numInputs == 0) + return false; + + int totalRepairValue = calculateIncrease(tool, materialValue); + float averageRepairValue = totalRepairValue / numInputs; + + return numInputs == 1 || (damage - totalRepairValue >= -averageRepairValue); } private int calculateIncrease (ItemStack tool, int materialValue) @@ -95,15 +107,13 @@ public void modify (ItemStack[] input, ItemStack tool) int itemsUsed = 0; int materialValue = 0; - if (input[0] != null) - { - materialValue += PatternBuilder.instance.getPartValue(input[0]); - itemsUsed++; - } - if (input[1] != null) + for (ItemStack curInput : input) { - materialValue += PatternBuilder.instance.getPartValue(input[1]); - itemsUsed++; + if (curInput != null) + { + materialValue += PatternBuilder.instance.getPartValue(curInput); + itemsUsed++; + } } int increase = calculateIncrease(tool, materialValue);