Skip to content

Commit

Permalink
Fixed repairing only working with the first 2 crafting slots (it will…
Browse files Browse the repository at this point in the history
… now work with any slot).

Fixes SlimeKnights/TinkersConstruct/#568
  • Loading branch information
squeek502 committed Jul 7, 2014
1 parent 8075cb0 commit 4fce1a9
Showing 1 changed file with 36 additions and 26 deletions.
62 changes: 36 additions & 26 deletions src/main/java/tconstruct/modifiers/tools/ModRepair.java
Expand Up @@ -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;
}
Expand All @@ -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)
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 4fce1a9

Please sign in to comment.