diff options
Diffstat (limited to 'patches/server/0951-Fix-DamageSource-API.patch')
-rw-r--r-- | patches/server/0951-Fix-DamageSource-API.patch | 45 |
1 files changed, 34 insertions, 11 deletions
diff --git a/patches/server/0951-Fix-DamageSource-API.patch b/patches/server/0951-Fix-DamageSource-API.patch index 1cf932b9ac..a9af537493 100644 --- a/patches/server/0951-Fix-DamageSource-API.patch +++ b/patches/server/0951-Fix-DamageSource-API.patch @@ -7,42 +7,58 @@ Uses the correct entity in the EntityDamageByEntity event Returns the correct entity for API's DamageSource#getCausingEntity diff --git a/src/main/java/net/minecraft/world/damagesource/DamageSource.java b/src/main/java/net/minecraft/world/damagesource/DamageSource.java -index 10bee9b217fae9170af9d66dac9741046be1cab6..bb1a60180e58c1333e7bb33e8acf1b0225eda8a8 100644 +index aee26dd78953ff43306aaa64161f5b9edcdd4b83..bb1a60180e58c1333e7bb33e8acf1b0225eda8a8 100644 --- a/src/main/java/net/minecraft/world/damagesource/DamageSource.java +++ b/src/main/java/net/minecraft/world/damagesource/DamageSource.java -@@ -29,7 +29,8 @@ public class DamageSource { +@@ -29,8 +29,8 @@ public class DamageSource { 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 + @Nullable + private Entity customEventDamager = null; // This field is a helper for when causing entity damage is not set by vanilla // Paper - fix DamageSource API public DamageSource sweep() { this.sweep = true; -@@ -58,18 +59,19 @@ public class DamageSource { +@@ -59,33 +59,19 @@ public class DamageSource { return this.poison; } - public Entity getDamager() { - 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 +- if (this.customEntityDamager != null || this.directEntity == entity || this.causingEntity == entity) { +- return this; +- } +- DamageSource damageSource = this.cloneInstance(); +- damageSource.customEntityDamager = entity; +- return damageSource; + // Paper start - fix DamageSource API + @Nullable + public Entity getCustomEventDamager() { + return (this.customEventDamager != null) ? this.customEventDamager : this.directEntity; } -- public DamageSource customEntityDamager(Entity entity) { +- 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.customEntityDamager != null || this.directEntity == entity || this.causingEntity == entity) { +- if (this.customCausingEntityDamager != null || this.directEntity == entity || this.causingEntity == entity) { - return this; + public DamageSource customEventDamager(Entity entity) { + if (this.directEntity != null) { + throw new IllegalStateException("Cannot set custom event damager when direct entity is already set (report a bug to Paper)"); } DamageSource damageSource = this.cloneInstance(); -- damageSource.customEntityDamager = entity; +- damageSource.customCausingEntityDamager = entity; + damageSource.customEventDamager = entity; + // Paper end - fix DamageSource API return damageSource; @@ -107,14 +123,14 @@ index 7bc612890f941177da11da0ce047d5a74d8ebb33..270acce7411e5ada71eaa04c05efc888 if (damager != null) { event = new HangingBreakByEntityEvent((Hanging) this.getBukkitEntity(), damager.getBukkitEntity(), source.is(DamageTypeTags.IS_EXPLOSION) ? HangingBreakEvent.RemoveCause.EXPLOSION : HangingBreakEvent.RemoveCause.ENTITY); diff --git a/src/main/java/net/minecraft/world/entity/monster/Creeper.java b/src/main/java/net/minecraft/world/entity/monster/Creeper.java -index acc844c10db9cb42c0e70f3b467e620906b739f0..cb1b19e2e0d8f0744b2355b8f4da0206b196b19c 100644 +index 2c01fbea62812f795111060d260f871cdf85e8bf..cb1b19e2e0d8f0744b2355b8f4da0206b196b19c 100644 --- a/src/main/java/net/minecraft/world/entity/monster/Creeper.java +++ b/src/main/java/net/minecraft/world/entity/monster/Creeper.java @@ -271,7 +271,7 @@ public class Creeper extends Monster implements PowerableMob { if (!event.isCancelled()) { // CraftBukkit end this.dead = true; -- 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(), Level.ExplosionInteraction.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(), Level.ExplosionInteraction.MOB); // CraftBukkit + this.level().explode(this, this.getX(), this.getY(), this.getZ(), event.getRadius(), event.getFire(), Level.ExplosionInteraction.MOB); // CraftBukkit // Paper - fix DamageSource API (revert to vanilla, no, just no, don't change this) this.spawnLingeringCloud(); this.triggerOnDeathMobEffects(Entity.RemovalReason.KILLED); @@ -159,10 +175,17 @@ index 60eac9df10a9a395a1568925515d010eb51a64e5..55fd997a4e894eeab24de269d59e4861 if (flag && entity instanceof LivingEntity entityliving) { diff --git a/src/main/java/org/bukkit/craftbukkit/damage/CraftDamageSource.java b/src/main/java/org/bukkit/craftbukkit/damage/CraftDamageSource.java -index ab67c5caaff6e8c7de293b528636f53254b805bd..98e5ec1cc2dba2512650ba706393d1abe0c95591 100644 +index 5572c50cac4968e3ec75fe1fc98442407bc3b905..3c5e937ade4bbf6a2f5f123ce53001eb915d51eb 100644 --- a/src/main/java/org/bukkit/craftbukkit/damage/CraftDamageSource.java +++ b/src/main/java/org/bukkit/craftbukkit/damage/CraftDamageSource.java -@@ -47,7 +47,7 @@ public class CraftDamageSource implements DamageSource { +@@ -41,13 +41,13 @@ public class CraftDamageSource implements DamageSource { + + @Override + public org.bukkit.entity.Entity getCausingEntity() { +- net.minecraft.world.entity.Entity entity = this.getHandle().getCausingDamager(); ++ net.minecraft.world.entity.Entity entity = this.getHandle().getCustomEventDamager(); // Paper + return (entity != null) ? entity.getBukkitEntity() : null; + } @Override public org.bukkit.entity.Entity getDirectEntity() { |