107 lines
5.0 KiB
Diff
107 lines
5.0 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 fecab5bfbc35fbecef8c559369de70c198bfe1e7..338e0c7c09120c6e9617893dd074cbd5da40a093 100644
|
|
--- a/net/minecraft/server/level/ServerPlayer.java
|
|
+++ b/net/minecraft/server/level/ServerPlayer.java
|
|
@@ -1464,6 +1464,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);
|
|
+ // Luminol 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);
|
|
+ }
|
|
+ // Luminol End - Cross Region Damage trace
|
|
}
|
|
|
|
this.level().broadcastEntityEvent(this, EntityEvent.DEATH);
|
|
@@ -1487,6 +1494,24 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
|
|
}
|
|
// Leaves end - exp fix
|
|
|
|
+ // Luminol 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);
|
|
+ }
|
|
+ // Luminol 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 cd2fb9e2110d0dba1358daa283af767db3f4e80a..cc7b2ea7fda1326e3f9ed46373190a05f60c4d34 100644
|
|
--- a/net/minecraft/world/entity/LivingEntity.java
|
|
+++ b/net/minecraft/world/entity/LivingEntity.java
|
|
@@ -1961,6 +1961,13 @@ public abstract class LivingEntity extends Entity implements Attackable, Waypoin
|
|
final LivingEntity killer = this.getKillCredit();
|
|
if (killer != null) {
|
|
killer.awardKillScore(this, source);
|
|
+ // Luminol 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);
|
|
+ }
|
|
+ // Luminol End - Cross Region Damage trace
|
|
}
|
|
}); // Paper end
|
|
this.postDeathDropItems(deathEvent); // Paper
|
|
@@ -1971,6 +1978,19 @@ public abstract class LivingEntity extends Entity implements Attackable, Waypoin
|
|
return deathEvent; // Paper
|
|
}
|
|
|
|
+ // Luminol 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 );
|
|
+ }
|
|
+ // Luminol End - Cross Region Damage trace
|
|
+
|
|
protected void dropEquipment(final ServerLevel level) {
|
|
}
|
|
protected void postDeathDropItems(org.bukkit.event.entity.EntityDeathEvent event) {} // Paper - method for post death logic that cannot be ran before the event is potentially cancelled
|
|
@@ -2629,6 +2649,18 @@ public abstract class LivingEntity extends Entity implements Attackable, Waypoin
|
|
}
|
|
}
|
|
|
|
+ // Luminol 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;
|
|
+ }
|
|
+ // Luminol End - Cross Region Damage trace
|
|
+
|
|
public final float getMaxHealth() {
|
|
return (float)this.getAttributeValue(Attributes.MAX_HEALTH);
|
|
}
|