106 lines
5.0 KiB
Diff
106 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 11e6197dec541b28733715f0d7eaa4c7b834d632..6b7c92fdf562dfa46eee8e8acbc82b02fc3226c5 100644
|
|
--- a/net/minecraft/server/level/ServerPlayer.java
|
|
+++ b/net/minecraft/server/level/ServerPlayer.java
|
|
@@ -1345,6 +1345,13 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
|
|
this.awardStat(Stats.ENTITY_KILLED_BY.get(killCredit.getType()));
|
|
killCredit.awardKillScore(this, cause);
|
|
this.createWitherRose(killCredit);
|
|
+ // 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, cause);
|
|
+ }
|
|
+ // Luminol End - Cross Region Damage trace
|
|
}
|
|
|
|
this.level().broadcastEntityEvent(this, (byte)3);
|
|
@@ -1368,6 +1375,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 567d63ae589705e13403814b36e35d00c241a69e..3f4b1c54f9207ba1854a8c8da965cbaca5ea517d 100644
|
|
--- a/net/minecraft/world/entity/LivingEntity.java
|
|
+++ b/net/minecraft/world/entity/LivingEntity.java
|
|
@@ -1948,6 +1948,13 @@ public abstract class LivingEntity extends Entity implements Attackable, Waypoin
|
|
final LivingEntity killer = this.getKillCredit();
|
|
if (killer != null) {
|
|
killer.awardKillScore(this, damageSource);
|
|
+ // 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, damageSource);
|
|
+ }
|
|
+ // Luminol End - Cross Region Damage trace
|
|
}
|
|
}); // Paper end
|
|
this.postDeathDropItems(deathEvent); // Paper
|
|
@@ -1958,6 +1965,18 @@ 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 {
|
|
+ nmsEntity.awardKillScore(this, damageSource);
|
|
+ } catch (Throwable ex) {
|
|
+ LOGGER.error(ex.getMessage(), ex);
|
|
+ }
|
|
+ }, null, 1L );
|
|
+ }
|
|
+ // Luminol End - Cross Region Damage trace
|
|
+
|
|
protected void dropEquipment(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
|
|
@@ -2556,6 +2575,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);
|
|
}
|