Why does cancelling the DropItemEvent prevent tool from losing durability?

Hello, I am trying to cancel the drop of an item on the break of a block, but whenever I do so, the tool used to break the block does not lose any durability. Why would this be happening?

This is the code being used:

@Listener
public void onItem(DropItemEvent.Destruct event) {
    event.setCancelled(true);
}

I kind of makes sense. Losing durability for something that is cancelled would cause problems for simple tasks, not too mention irritate me personally.

Shouldn’t tool breaking be handled by the ChangeBlockEvent.Break event, not the dropping of an item?

I agree, if you cancel the item drop but allow the block break, the tool should lose durability imo. After all, it’s not the item drop that the tool loses durability for, it’s the breaking of the block (from a logic standpoint).

1 Like

I missed that it was an item drop event in the code snippet. You mentioned breaking a block in your explanation. My bad. I’m curious though if the same behavior happens on the break event. Does seem odd.

1 Like

Honestly I think side effects like this need to be handled in their own events.

It shouldn’t matter whether the block break was cancelled or not, or whether the drops were cancelled or not. It should matter whether whatever event handles item stacks changing due to durability loss is cancelled or not.

And even then, considering Sponges habit of combining multiple event interfaces onto a single event, you can’t be sure if cancelling one interface isn’t really cancelling another as well…

1 Like

That sounds like a good idea. Do you know if there is already an event for durability loss or not?

Looking at it from another point of view, what you probably should be doing instead of cancelling the event, is filter the entities out, cancelling is really a way of affecting causality, and stopping whatever chain of operations are in motion.

Yes, that is the solution I went with.