PaperMC / Paper

The most widely used, high performance Minecraft server that aims to fix gameplay and mechanics inconsistencies
https://papermc.io/
Other
9.34k stars 2.2k forks source link

Wolf armor gets damaged when EntityDamageEvent is cancelled #10978

Open TothAdam0012 opened 6 days ago

TothAdam0012 commented 6 days ago

Expected behavior

Cancelling EntityDamageEvent should prevent wolf armor from taking damage since there's no incoming damage to defend against.

Observed/Actual behavior

Even though EntityDamageEvent is cancelled the wolf armor takes damage and eventually breaks.

Steps/models to reproduce

Create an empty plugin an register the following event

    @EventHandler
    public void onEntityDamage(EntityDamageEvent e) {
        if(e.getEntityType() == EntityType.WOLF) {
            e.setCancelled(true);
        }
    }

After summoning a wolf tame it and put armor on it. When the wolf gets hit by the player the armor takes damage.

Plugin and Datapack List

Empty/test plugin

Paper version

[22:56:28 INFO]: Checking version, please wait...
[22:56:30 INFO]: This server is running Paper version 1.21-37-master@dd49fba (2024-06-24T02:08:49Z) (Implementing API version 1.21-R0.1-SNAPSHOT)
You are running the latest version
Previous version: 1.21-27-76c2f16 (MC: 1.21)

Other

No response

Doc94 commented 6 days ago

I check internally and looks like the event is called in actuallyHurts (in the final) what is only called if the wolf not has armor (or the damage ignore the wolf armor) currently in upstream is more easy fix that because the event now is created before the actuallyHurts is called and pass the event later to actuallyHurts where can check the cancel state for avoid damage the armor, but Paper has EntityDamageItemEvent what is called for damage in items like the Wolf Armor then you can use that for cancel the damage in Wolf Armor

TothAdam0012 commented 6 days ago

Shouldn't EntityDamageItemEvent not even get called for this and just not damage the item? Or maybe not damage the item and call the event in a cancelled state.

Doc94 commented 6 days ago

Shouldn't EntityDamageItemEvent not even get called for this and just not damage the item? Or maybe not damage the item and call the event in a cancelled state.

In teory.. but i dont like that solution of just call EntityDamageItemEvent in canceled because that can cause another user cases fails if is just called in that part of code (currently... with the last upstreams changes in teory its just listen the canceled state passed in the hurts methods for wolfs)