Fixed repairing only working with the first 2 crafting slots (it will now work with any slot).

Fixes SlimeKnights/TinkersConstruct/#568
This commit is contained in:
squeek committed 2014-07-06 23:57:52 -07:00
1 parent 8075cb0b9e
commit 4fce1a924e
1 file changed
+35 -25
@@ -26,20 +26,23 @@ public class ModRepair extends ItemModifier
@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 @@ public class ModRepair extends ItemModifier
{
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]));
int numInputs = 0;
int materialValue = 0;
for (ItemStack curInput : input)
{
if (curInput != null)
{
materialValue += PatternBuilder.instance.getPartValue(curInput);
numInputs++;
}
}
if (numInputs == 0)
return false;
return ((damage - valueSlot1) > 0) && ((damage - valueSlot2) > 0);
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 class ModRepair extends ItemModifier
int itemsUsed = 0;
int materialValue = 0;
if (input[0] != null)
for (ItemStack curInput : input)
{
materialValue += PatternBuilder.instance.getPartValue(input[0]);
itemsUsed++;
}
if (input[1] != null)
{
materialValue += PatternBuilder.instance.getPartValue(input[1]);
itemsUsed++;
if (curInput != null)
{
materialValue += PatternBuilder.instance.getPartValue(curInput);
itemsUsed++;
}
}
int increase = calculateIncrease(tool, materialValue);