OtherDrops

226k Downloads

2.0 - damagetool kills the tools immediately

Zarius opened this issue ยท 8 comments

commented
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.

commented

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;

commented

That logic looks like it should apply to items, not tools. For tools it should check durability instead of stack size.

commented

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. ;)

commented

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;
commented

Maybe you forgot to commit? :P

commented

Did you fix this? If not, I'll go do it since it's a simple fix.

commented

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.

commented

Yes, this was fixed - closing issue.