PaperMC / PaperMC/Paper

Reducing damage of an EntityDamageEvent allows future damage to bypass NoDamageTicks partially

Open
#11,393 11 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

priority: high status: input wanted type: bug version: 1.21.1 version: 1.21.4
Dominant language
Java
Stars
12.7k
Forks
3.5k
Avg merge
3d 13h
Merged PRs (30d)
11

Description

Expected behavior

This issue applies to all damage types, but is specifically more noticeable in damage types that attempt to deal damage each tick (lava, cactus), so i will use lava as an example.

When standing in lava, I expect armor to take damage every 10 ticks as it does in vanilla, regardless of the amount of damage the lava deals.

Observed/Actual behavior

Armor takes damage and lava burn sounds are played every tick.

Steps/models to reproduce
  1. Create a plugin with the following handler in a Listener:
    @EventHandler
    public void onLava(EntityDamageEvent event) {
    if (event.getCause() == EntityDamageEvent.DamageCause.LAVA) {
    event.setDamage(event.getDamage() * .99);
    }
    }
  2. Run the server and equip armor.
  3. Stand in lava.
  4. Observe your armor taking damage each tick, instead of every 10th tick.
Plugin and Datapack List

Nothing except this listener.

Paper version

This server is running Silvera version 1.21.1-DEV-main@9d0a210 (2024-09-13T02:50:33Z) (Implementing API version 1.21.1-R0.1-SNAPSHOT)

This is a private fork, but is based off of latest and has no related changes, several other servers have run into this issue, presumably on other forks or standard Paper. I can replicate it on latest if necessary.

Other

This appears to be the source of the issue. https://github.com/PaperMC/Paper/pull/11045/commits/d98db3945a76eb6203062c7ccfa2a71bce22f4e4

image
This is caused by amount being set to a lower value before lastHurt is assigned to this value.
For example, lava deals 4 damage, but if this is reduced to 3 damage, lastHurt will be 3 on the next tick, but amount will be 4, resulting in the if case failing and damage attempting to be dealt.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by examining the linked Paper pull request commit and reproduce the issue with the minimal EntityDamageEvent listener described here. Trace how reduced damage is compared with the entity's existing damage cooldown, then verify that lava damage, armor wear, and burn sounds are throttled to the vanilla interval after damage is reduced.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
game-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.