mojira.dev
MC-121048

When an entity dies, the combat tracker only records the killing blow

Code analysis below uses 1.19's code, deobfuscated manually using the official obfuscation mappings for 1.19.

Living entities have a CombatTracker, which tracks the details of recent hits. When such an entity is damaged, the combat tracker's recordDamage method is called to record it.

recordDamage first calls recheckStatus, which resets the tracked data if certain conditions are met. It then adds the data for the damage currently being taken.

The issue here is that, when recordDamage is called for the killing blow, recheckStatus will clear the tracker due to the condition !this.mob.isAlive() being met. This is because isAlive checks that the entity's health is above 0.

Looking at the method LivingEntity#actuallyHurt shows the problem:

protected void actuallyHurt(DamageSource damageSrc, float amount) {
   if (!this.isInvulnerableTo(damageSrc)) {
      amount = this.getDamageAfterArmorAbsorb(damageSrc, amount);
      amount = this.getDamageAfterMagicAbsorb(damageSrc, amount);
      float f2 = amount;
      amount = Math.max(amount - this.getAbsorptionAmount(), 0.0F);
      this.setAbsorptionAmount(this.getAbsorptionAmount() - f2 - amount);
      float f = f2 - amount;
      if (f > 0.0F && f < 3.4028235E37F && damageSrc.getEntity() instanceof ServerPlayer) {
         ((ServerPlayer)damageSrc.getEntity()).awardStat(Stats.DAMAGE_DEALT_ABSORBED, Math.round(f * 10.0F));
      }
      if (f2 != 0.0F) {
         float f1 = this.getHealth();
         this.setHealth(f1 - f2);
         this.getCombatTracker().recordDamage(damageSrc, f1, f2);
         this.setAbsorptionAmount(this.getAbsorptionAmount() - amount);
         this.gameEvent(GameEvent.ENTITY_DAMAGE);
      }
   }
}

The health is updated before recordDamage is called, which makes the entity show up as dead and causes the combat data to be cleared.

Then, shortly afterwards, die is called for the just-killed entity. This checks getKillCredit to determine who to credit with the kill.

getKillCredit will first consult CombatTracker#getKiller which contains logic to go through the combat history and pick out the "best" attacker.

However this logic is currently irrelevant, as due to the above issue, the tracker will only contain an entry for the killing blow and nothing else.

The solution here is to change LivingEntity#actuallyHurt to call recordDamage first, followed by setHealth.

Fixing this bug will allow for the "doomed to fall" death messages to appear.

Linked issues

Attachments

Comments 7

Does this still affect the latest versions of the game (Stable 1.15.2 / Snapshot 20w21a)? If so, please update this ticket accordingly. Should the original reported be inactive and no longer contribute to the bug tracker, the reporter of the ticket can be changed to an active user.

Quick Links:
📓 Issue Guidelines – 💬 Community Support – 📧 Customer Support – ✍️ Feedback and Suggestions – 📖 Game Wiki

I can confirm that this is still an issue in 1.17 Release Candidate 1.

This report is currently missing crucial information. Please take a look at the other comments to find out what we are looking for.
If you added the required information and a moderator sees your comment, they will reopen and update the report. However, if you think your update to this report has been overlooked or you want to make sure that this report is reopened, you can contact the Mojira staff on Discord or Reddit.
-- I am a bot. This action was performed automatically! If you think it was incorrect, please notify us on Discord or Reddit

Can confirm for 1.19.1 Pre-release 4. May I request ownership?

seems this is still not working correctly in 1.19.4 rc3? https://youtu.be/3mZguAFyUrQ 

Not 100% sure if this is the one, but fixing this bug in 1.19.4 may have caused some havoc in totalKillCount scoreboards (and similar objectives). I've been using this objective to display custom kill messages, and sometimes they showed the wrong player credited for the kill, most likely the one to deal the most damage. It was all working in 1.19.2 and before.

Ben Staddon

[Mod] ManosSef

Fantastime

Confirmed

Platform

Important

Combat

Minecraft 1.12.2, Minecraft 1.13.2, 1.15.2, 20w09a, 20w10a, ..., 22w43a, 22w44a, 22w46a, 1.19.3 Pre-release 1, 1.19.3

23w03a

Retrieved