2.0 - damagetool kills the tools immediately
Zarius opened this issue ยท 8 comments
public void damageTool(short damage) {
if(damage == 0) return;
ItemStack stack = agent.getItemInHand();
// ************************
// FIXME: ** this bit is probably not needed **
if(stack == null || stack.getAmount() == 1) {
agent.setItemInHand(null);
return;
}
// ************************
// Either it's a tool and we damage it, or it's not and we take one
short maxDurability = stack.getType().getMaxDurability();
if(maxDurability > 0) { // a tool
short durability = stack.getDurability();
if(durability + damage >= maxDurability) agent.setItemInHand(null);
else stack.setDurability((short) (durability + damage));
} else { // not a tool
int amount = stack.getAmount();
if(amount <= damage) agent.setItemInHand(null);
else stack.setAmount(amount - damage);
}
I know the solution, just haven't had time to work on it yet.
Sorry, code was taken out of context - I've added the whole function to the first post now. Looks like it's just duplicated and can be removed but I didn't remove it on the spot as I didn't have time to test the result.
Or more appropriately - it should be changed to if (stack ==null) return;
That logic looks like it should apply to items, not tools. For tools it should check durability instead of stack size.
Ah, see that if ... else below it? The first branch of that is for tools, the second for items, so the getAmount check (<1 rather than ==1) and nullify the item should probably be nested within the second branch. The checking for null probably belongs where it is.
...wait, that check is already nested within that branch. Okay, go ahead and remove it then. ;)
I thought I did but I can't see a commit - I just changed:
if(stack == null || stack.getAmount() == 1) {
agent.setItemInHand(null);
return;
}
to
if(stack == null) return;
This was fixed, wasn't it? I forget whether it was me or you who did it, but I'm pretty sure I remember it being fixed.