107 lines
4.9 KiB
Diff
107 lines
4.9 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Helvetica Volubi <suisuroru@blue-millennium.fun>
|
|
Date: Tue, 29 Apr 2025 23:03:56 +0800
|
|
Subject: [PATCH] Add config to enable cross region damage trace
|
|
|
|
|
|
diff --git a/net/minecraft/server/level/ServerPlayer.java b/net/minecraft/server/level/ServerPlayer.java
|
|
index b4d8cc8b520266abe1921b5e990c34fce3f1d982..93c76c2faf75bf4901ecaba1e04d957d5ddddfca 100644
|
|
--- a/net/minecraft/server/level/ServerPlayer.java
|
|
+++ b/net/minecraft/server/level/ServerPlayer.java
|
|
@@ -1448,6 +1448,13 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
|
|
this.awardStat(Stats.ENTITY_KILLED_BY.get(killer.getType()));
|
|
killer.awardKillScore(this, source);
|
|
this.createWitherRose(killer);
|
|
+ // Lophine Start - Cross Region Damage trace
|
|
+ } else if (fun.bm.lophine.config.modules.experiment.EntityDamageSourceTraceConfig.enabled) {
|
|
+ final LivingEntity entitylivingnew = this.getKillCreditOrigin();
|
|
+ if (entitylivingnew != null) {
|
|
+ this.damageTransferToAsync(entitylivingnew, source);
|
|
+ }
|
|
+ // Lophine End - Cross Region Damage trace
|
|
}
|
|
|
|
this.level().broadcastEntityEvent(this, EntityEvent.DEATH);
|
|
@@ -1462,6 +1469,24 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
|
|
this.connection.markClientUnloadedAfterDeath();
|
|
}
|
|
|
|
+ // Lophine Start - Cross Region Damage trace
|
|
+ private void damageTransferToAsync(LivingEntity entity, DamageSource cause) {
|
|
+ // Operations running on current entity
|
|
+ this.awardStat(Stats.ENTITY_KILLED_BY.get(entity.getType()));
|
|
+ this.createWitherRose(entity);
|
|
+
|
|
+ // the entity might be in another tickregion sometimes, so we need to schedule the task onto the entity
|
|
+ // to ensure thread safe
|
|
+ entity.getBukkitEntity().taskScheduler.schedule((LivingEntity nmsEntity) -> {
|
|
+ try {
|
|
+ nmsEntity.awardKillScore(this, cause);
|
|
+ } catch (Throwable ex) {
|
|
+ LOGGER.error(ex.getMessage(), ex);
|
|
+ }
|
|
+ }, null, 1L);
|
|
+ }
|
|
+ // Lophine End - Cross Region Damage trace
|
|
+
|
|
private void tellNeutralMobsThatIDied() {
|
|
AABB aabb = new AABB(this.blockPosition()).inflate(32.0, 10.0, 32.0);
|
|
this.level()
|
|
diff --git a/net/minecraft/world/entity/LivingEntity.java b/net/minecraft/world/entity/LivingEntity.java
|
|
index fcaeb471dada57e9ba4d224693cefbff2fa631be..5762eed9e99d918bee02d77c0ddd70be0aa0e2ec 100644
|
|
--- a/net/minecraft/world/entity/LivingEntity.java
|
|
+++ b/net/minecraft/world/entity/LivingEntity.java
|
|
@@ -1855,6 +1855,13 @@ public abstract class LivingEntity extends Entity implements Attackable, Waypoin
|
|
Runnable afterEvent = () -> { // Paper
|
|
if (killer != null) {
|
|
killer.awardKillScore(this, source);
|
|
+ // Lophine Start - Cross Region Damage trace
|
|
+ } else if (fun.bm.lophine.config.modules.experiment.EntityDamageSourceTraceConfig.enabled) {
|
|
+ final LivingEntity killernew = this.getKillCreditOrigin();
|
|
+ if (killernew != null) {
|
|
+ this.damageTransferToAsync(killernew, source);
|
|
+ }
|
|
+ // Lophine End - Cross Region Damage trace
|
|
}
|
|
|
|
if (this.isSleeping()) {
|
|
@@ -1943,6 +1950,19 @@ public abstract class LivingEntity extends Entity implements Attackable, Waypoin
|
|
this.postDeathEventTasks.add(() -> this.dropExperience(level, source.getEntity())); // Paper
|
|
}
|
|
|
|
+ // Lophine Start - Cross Region Damage trace
|
|
+ private void damageTransferToAsync(LivingEntity entity, DamageSource damageSource) {
|
|
+ entity.getBukkitEntity().taskScheduler.schedule((LivingEntity nmsEntity) -> {
|
|
+ try {
|
|
+ if (nmsEntity.isRemoved()) return;
|
|
+ nmsEntity.awardKillScore(this, damageSource);
|
|
+ } catch (Throwable ex) {
|
|
+ LOGGER.error(ex.getMessage(), ex);
|
|
+ }
|
|
+ }, null, 1L );
|
|
+ }
|
|
+ // Lophine End - Cross Region Damage trace
|
|
+
|
|
protected void dropEquipment(final ServerLevel level) {
|
|
}
|
|
|
|
@@ -2609,6 +2629,18 @@ public abstract class LivingEntity extends Entity implements Attackable, Waypoin
|
|
}
|
|
}
|
|
|
|
+ // Lophine Start - Cross Region Damage trace
|
|
+ @Nullable
|
|
+ public LivingEntity getKillCreditOrigin() {
|
|
+ if (this.lastHurtByPlayer != null) {
|
|
+ return this.lastHurtByPlayer.getEntity(this.level(), Player.class);
|
|
+ } else if (this.lastHurtByMob != null) {
|
|
+ return this.lastHurtByMob.getEntity(this.level(), LivingEntity.class);
|
|
+ }
|
|
+ return null;
|
|
+ }
|
|
+ // Lophine End - Cross Region Damage trace
|
|
+
|
|
public final float getMaxHealth() {
|
|
return (float)this.getAttributeValue(Attributes.MAX_HEALTH);
|
|
}
|