From c985be99a6e3604f6d3876778559d82b4303eaa0 Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Sat, 15 Jun 2024 06:47:48 +1000 Subject: [PATCH] #1420: Fix DirectEntity and CausingEntity Damager for Creepers ignited by Player By: Doc --- .../world/damagesource/DamageSource.patch | 20 +++++++++++++++++-- .../world/entity/monster/EntityCreeper.patch | 2 +- .../craftbukkit/damage/CraftDamageSource.java | 2 +- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/paper-server/nms-patches/net/minecraft/world/damagesource/DamageSource.patch b/paper-server/nms-patches/net/minecraft/world/damagesource/DamageSource.patch index 7b0c6c0e32..a76f254922 100644 --- a/paper-server/nms-patches/net/minecraft/world/damagesource/DamageSource.patch +++ b/paper-server/nms-patches/net/minecraft/world/damagesource/DamageSource.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/damagesource/DamageSource.java +++ b/net/minecraft/world/damagesource/DamageSource.java -@@ -21,6 +21,103 @@ +@@ -21,6 +21,119 @@ private final Entity directEntity; @Nullable private final Vec3D damageSourcePosition; @@ -12,7 +12,8 @@ + private boolean sweep = false; + private boolean melting = false; + private boolean poison = false; -+ private Entity customEntityDamager = null; // This field is a helper for when causing entity damage is not set by vanilla ++ private Entity customEntityDamager = null; // This field is a helper for when direct entity damage is not set by vanilla ++ private Entity customCausingEntityDamager = null; // This field is a helper for when causing entity damage is not set by vanilla + + public DamageSource sweep() { + this.sweep = true; @@ -45,6 +46,10 @@ + return (this.customEntityDamager != null) ? this.customEntityDamager : this.directEntity; + } + ++ public Entity getCausingDamager() { ++ return (this.customCausingEntityDamager != null) ? this.customCausingEntityDamager : this.causingEntity; ++ } ++ + public DamageSource customEntityDamager(Entity entity) { + // This method is not intended for change the causing entity if is already set + // also is only necessary if the entity passed is not the direct entity or different from the current causingEntity @@ -56,6 +61,17 @@ + return damageSource; + } + ++ public DamageSource customCausingEntityDamager(Entity entity) { ++ // This method is not intended for change the causing entity if is already set ++ // also is only necessary if the entity passed is not the direct entity or different from the current causingEntity ++ if (this.customCausingEntityDamager != null || this.directEntity == entity || this.causingEntity == entity) { ++ return this; ++ } ++ DamageSource damageSource = this.cloneInstance(); ++ damageSource.customCausingEntityDamager = entity; ++ return damageSource; ++ } ++ + public org.bukkit.block.Block getDirectBlock() { + return this.directBlock; + } diff --git a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityCreeper.patch b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityCreeper.patch index 9a0cd3ebf4..bd3f79b3ec 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityCreeper.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityCreeper.patch @@ -64,7 +64,7 @@ + // CraftBukkit end this.dead = true; - this.level().explode(this, this.getX(), this.getY(), this.getZ(), (float) this.explosionRadius * f, World.a.MOB); -+ this.level().explode(this, net.minecraft.world.level.Explosion.getDefaultDamageSource(this.level(), this).customEntityDamager(this.entityIgniter), null, this.getX(), this.getY(), this.getZ(), event.getRadius(), event.getFire(), World.a.MOB); // CraftBukkit ++ this.level().explode(this, net.minecraft.world.level.Explosion.getDefaultDamageSource(this.level(), this).customCausingEntityDamager(this.entityIgniter), null, this.getX(), this.getY(), this.getZ(), event.getRadius(), event.getFire(), World.a.MOB); // CraftBukkit this.spawnLingeringCloud(); this.triggerOnDeathMobEffects(Entity.RemovalReason.KILLED); - this.discard(); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/damage/CraftDamageSource.java b/paper-server/src/main/java/org/bukkit/craftbukkit/damage/CraftDamageSource.java index 4a1b01c735..392fbd678f 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/damage/CraftDamageSource.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/damage/CraftDamageSource.java @@ -41,7 +41,7 @@ public class CraftDamageSource implements DamageSource { @Override public org.bukkit.entity.Entity getCausingEntity() { - net.minecraft.world.entity.Entity entity = this.getHandle().getEntity(); + net.minecraft.world.entity.Entity entity = this.getHandle().getCausingDamager(); return (entity != null) ? entity.getBukkitEntity() : null; }