Skip to content

Reducing damage in EntityDamageByEntityEvent causes invulnerability timer to be bypassed #11480

@okx-code

Description

@okx-code

Expected behavior

Reducing the damage in EntityDamageByEntityEvent has no side effects and just reduces the damage.

Observed/Actual behavior

If the damage is reduced in EntityDamageByEntityEvent, the invulnerability timer for an entity is bypassed for subsequent attacks, due to a mismatch in how Paper calculates the most recent attack damage (lastHurt)

Steps/models to reproduce

Add a listener to EntityDamageByEntityEvent to multiply the damage by 0.9.

Place a breakpoint at LivingEntity.java#1470 (at return false):

                if (amount <= this.lastHurt) {
                    return false;
                }

If you spam click an entity, verify that this the breakpoint at 1470 is never hit with the listener, but is hit without.

Plugin and Datapack List

N/A

Paper version

This server is running Paper version 1.21.1-119-master@7cd4f2c (2024-10-03T15:19:34Z) (Implementing API version 1.21.1-R0.1-SNAPSHOT)
You are running the latest version
Previous version: 1.21.1-40-2fdb2e9 (MC: 1.21.1)

Other

I'm diagnosing a combat bug caused by this if statement if (amount <= this.lastHurt), what I think it does is it allows the invulnerability timer to be bypassed if a player receives an attack with more damage(?). Due to #11045 this has caused a bug on our server where if you reduce the damage (amount) in the EntityDamageEvent, this if statement will always be false, and players will always receive damage, bypassing the invulnerability timer.

My workaround is to make sure that the amount stored in this.lastHurt is always the original amount (see screenshot), but I'm not sure if this is the best solution. Possibly a PreDamageEvent could make sense here? Any thoughts?

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    resolution: duplicateIssue or Request is a copy of an existing ticket.type: bugSomething doesn't work as it was intended to.version: 1.21.1Game version 1.21.1

    Type

    No fields configured for Bug.

    Projects

    Status

    Invalid

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions