Fix CombatTracker stale on death (#12562)

This commit is contained in:
Pedro
2025-05-21 12:19:08 -04:00
committed by GitHub
parent f303a076bc
commit 87349c317f
2 changed files with 13 additions and 7 deletions

View File

@ -1,6 +1,17 @@
--- a/net/minecraft/world/damagesource/CombatTracker.java --- a/net/minecraft/world/damagesource/CombatTracker.java
+++ b/net/minecraft/world/damagesource/CombatTracker.java +++ b/net/minecraft/world/damagesource/CombatTracker.java
@@ -38,6 +_,13 @@ @@ -29,15 +_,24 @@
private int combatEndTime;
public boolean inCombat;
public boolean takingDamage;
+ public final io.papermc.paper.world.damagesource.PaperCombatTrackerWrapper paperCombatTracker; // Paper - Combat tracker API
public CombatTracker(LivingEntity mob) {
this.mob = mob;
+ this.paperCombatTracker = new io.papermc.paper.world.damagesource.PaperCombatTrackerWrapper(this); // Paper - Combat tracker API
}
public void recordDamage(DamageSource source, float damage) {
this.recheckStatus(); this.recheckStatus();
FallLocation currentFallLocation = FallLocation.getCurrentFallLocation(this.mob); FallLocation currentFallLocation = FallLocation.getCurrentFallLocation(this.mob);
CombatEntry combatEntry = new CombatEntry(source, damage, currentFallLocation, (float)this.mob.fallDistance); CombatEntry combatEntry = new CombatEntry(source, damage, currentFallLocation, (float)this.mob.fallDistance);

View File

@ -10,8 +10,6 @@ import java.util.Set;
import java.util.UUID; import java.util.UUID;
import net.minecraft.Optionull; import net.minecraft.Optionull;
import io.papermc.paper.world.damagesource.CombatTracker; import io.papermc.paper.world.damagesource.CombatTracker;
import io.papermc.paper.world.damagesource.PaperCombatTrackerWrapper;
import io.papermc.paper.world.damagesource.FallLocationType;
import net.minecraft.core.component.DataComponents; import net.minecraft.core.component.DataComponents;
import net.minecraft.network.protocol.game.ClientboundHurtAnimationPacket; import net.minecraft.network.protocol.game.ClientboundHurtAnimationPacket;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
@ -94,14 +92,11 @@ import org.bukkit.util.Vector;
public class CraftLivingEntity extends CraftEntity implements LivingEntity { public class CraftLivingEntity extends CraftEntity implements LivingEntity {
private final PaperCombatTrackerWrapper combatTracker;
private CraftEntityEquipment equipment; private CraftEntityEquipment equipment;
public CraftLivingEntity(final CraftServer server, final net.minecraft.world.entity.LivingEntity entity) { public CraftLivingEntity(final CraftServer server, final net.minecraft.world.entity.LivingEntity entity) {
super(server, entity); super(server, entity);
this.combatTracker = new PaperCombatTrackerWrapper(entity.getCombatTracker());
if (entity instanceof Mob || entity instanceof ArmorStand) { if (entity instanceof Mob || entity instanceof ArmorStand) {
this.equipment = new CraftEntityEquipment(this); this.equipment = new CraftEntityEquipment(this);
} }
@ -1168,6 +1163,6 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
@Override @Override
public CombatTracker getCombatTracker() { public CombatTracker getCombatTracker() {
return this.combatTracker; return this.getHandle().getCombatTracker().paperCombatTracker;
} }
} }