diff --git a/paper-server/patches/sources/net/minecraft/world/damagesource/DamageSource.java.patch b/paper-server/patches/sources/net/minecraft/world/damagesource/DamageSource.java.patch index 1cfa141a77..65bbca9531 100644 --- a/paper-server/patches/sources/net/minecraft/world/damagesource/DamageSource.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/damagesource/DamageSource.java.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/damagesource/DamageSource.java +++ b/net/minecraft/world/damagesource/DamageSource.java -@@ -21,7 +21,120 @@ +@@ -21,7 +21,106 @@ private final Entity directEntity; @Nullable private final Vec3 damageSourcePosition; @@ -12,8 +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 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; @@ -42,33 +42,19 @@ + return this.poison; + } + -+ public Entity getDamager() { -+ return (this.customEntityDamager != null) ? this.customEntityDamager : this.directEntity; ++ // Paper start - fix DamageSource API ++ @Nullable ++ public Entity getCustomEventDamager() { ++ return (this.customEventDamager != null) ? this.customEventDamager : 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; ++ 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; -+ 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; ++ damageSource.customEventDamager = entity; ++ // Paper end - fix DamageSource API + return damageSource; + } + @@ -121,7 +107,7 @@ public String toString() { return "DamageSource (" + this.type().msgId() + ")"; } -@@ -163,4 +276,18 @@ +@@ -163,4 +262,18 @@ public Holder typeHolder() { return this.type; } diff --git a/paper-server/patches/sources/net/minecraft/world/damagesource/DamageSources.java.patch b/paper-server/patches/sources/net/minecraft/world/damagesource/DamageSources.java.patch index a02a23d0e1..ef590e6374 100644 --- a/paper-server/patches/sources/net/minecraft/world/damagesource/DamageSources.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/damagesource/DamageSources.java.patch @@ -16,10 +16,11 @@ this.inFire = this.source(DamageTypes.IN_FIRE); this.campfire = this.source(DamageTypes.CAMPFIRE); this.lightningBolt = this.source(DamageTypes.LIGHTNING_BOLT); -@@ -84,6 +90,16 @@ +@@ -83,7 +89,17 @@ + private DamageSource source(ResourceKey key, @Nullable Entity source, @Nullable Entity attacker) { return new DamageSource(this.damageTypes.getOrThrow(key), source, attacker); - } ++ } + + // CraftBukkit start + public DamageSource melting() { @@ -28,27 +29,21 @@ + + public DamageSource poison() { + return this.poison; -+ } + } + // CraftBukkit end public DamageSource inFire() { return this.inFire; -@@ -254,17 +270,29 @@ +@@ -254,7 +270,7 @@ } public DamageSource explosion(@Nullable Entity source, @Nullable Entity attacker) { - return this.source(attacker != null && source != null ? DamageTypes.PLAYER_EXPLOSION : DamageTypes.EXPLOSION, source, attacker); -+ // CraftBukkit start -+ return this.explosion(source, attacker, attacker != null && source != null ? DamageTypes.PLAYER_EXPLOSION : DamageTypes.EXPLOSION); ++ return this.source(attacker != null && source != null ? DamageTypes.PLAYER_EXPLOSION : DamageTypes.EXPLOSION, source, attacker); // Paper - revert to vanilla } -+ public DamageSource explosion(@Nullable Entity entity, @Nullable Entity entity1, ResourceKey resourceKey) { -+ return this.source(resourceKey, entity, entity1); -+ // CraftBukkit end -+ } -+ public DamageSource sonicBoom(Entity attacker) { - return this.source(DamageTypes.SONIC_BOOM, attacker); +@@ -262,9 +278,15 @@ } public DamageSource badRespawnPointExplosion(Vec3 position) { diff --git a/paper-server/patches/sources/net/minecraft/world/entity/Entity.java.patch b/paper-server/patches/sources/net/minecraft/world/entity/Entity.java.patch index 06cf6e51af..01d6aabeef 100644 --- a/paper-server/patches/sources/net/minecraft/world/entity/Entity.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/entity/Entity.java.patch @@ -1391,7 +1391,7 @@ + return; + } + -+ if (!this.hurtServer(world, this.damageSources().lightningBolt().customEntityDamager(lightning), 5.0F)) { ++ if (!this.hurtServer(world, this.damageSources().lightningBolt().customEventDamager(lightning), 5.0F)) { // Paper - fix DamageSource API + return; + } + // CraftBukkit end diff --git a/paper-server/patches/sources/net/minecraft/world/entity/animal/Turtle.java.patch b/paper-server/patches/sources/net/minecraft/world/entity/animal/Turtle.java.patch index 4b9ddbae38..49bba2e107 100644 --- a/paper-server/patches/sources/net/minecraft/world/entity/animal/Turtle.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/entity/animal/Turtle.java.patch @@ -15,7 +15,7 @@ @Override public void thunderHit(ServerLevel world, LightningBolt lightning) { - this.hurtServer(world, this.damageSources().lightningBolt(), Float.MAX_VALUE); -+ this.hurtServer(world, this.damageSources().lightningBolt().customEntityDamager(lightning), Float.MAX_VALUE); // CraftBukkit ++ this.hurtServer(world, this.damageSources().lightningBolt().customEventDamager(lightning), Float.MAX_VALUE); // CraftBukkit // Paper - fix DamageSource API } @Override diff --git a/paper-server/patches/sources/net/minecraft/world/entity/decoration/BlockAttachedEntity.java.patch b/paper-server/patches/sources/net/minecraft/world/entity/decoration/BlockAttachedEntity.java.patch index cf010341e8..2f102c86b9 100644 --- a/paper-server/patches/sources/net/minecraft/world/entity/decoration/BlockAttachedEntity.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/entity/decoration/BlockAttachedEntity.java.patch @@ -72,7 +72,7 @@ } else { if (!this.isRemoved()) { + // CraftBukkit start - fire break events -+ Entity damager = (source.isDirect()) ? source.getDirectEntity() : source.getEntity(); ++ Entity damager = (!source.isDirect() && source.getEntity() != null) ? source.getEntity() : source.getDirectEntity(); // Paper - fix DamageSource API + HangingBreakEvent event; + 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/paper-server/patches/sources/net/minecraft/world/entity/monster/Creeper.java.patch b/paper-server/patches/sources/net/minecraft/world/entity/monster/Creeper.java.patch index 5737767075..ea4e74957f 100644 --- a/paper-server/patches/sources/net/minecraft/world/entity/monster/Creeper.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/entity/monster/Creeper.java.patch @@ -73,7 +73,7 @@ + // CraftBukkit end this.dead = true; - worldserver.explode(this, this.getX(), this.getY(), this.getZ(), (float) this.explosionRadius * f, Level.ExplosionInteraction.MOB); -+ worldserver.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 ++ worldserver.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(worldserver, Entity.RemovalReason.KILLED); - this.discard(); diff --git a/paper-server/patches/sources/net/minecraft/world/entity/projectile/EvokerFangs.java.patch b/paper-server/patches/sources/net/minecraft/world/entity/projectile/EvokerFangs.java.patch index 22b4caea72..fc93ad07be 100644 --- a/paper-server/patches/sources/net/minecraft/world/entity/projectile/EvokerFangs.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/entity/projectile/EvokerFangs.java.patch @@ -24,7 +24,7 @@ if (target.isAlive() && !target.isInvulnerable() && target != entityliving1) { if (entityliving1 == null) { - target.hurt(this.damageSources().magic(), 6.0F); -+ target.hurt(this.damageSources().magic().customEntityDamager(this), 6.0F); // CraftBukkit ++ target.hurt(this.damageSources().magic().customEventDamager(this), 6.0F); // CraftBukkit // Paper - fix DamageSource API } else { if (entityliving1.isAlliedTo((Entity) target)) { return; diff --git a/paper-server/patches/sources/net/minecraft/world/entity/projectile/ThrownEnderpearl.java.patch b/paper-server/patches/sources/net/minecraft/world/entity/projectile/ThrownEnderpearl.java.patch index b80080c890..423dce8353 100644 --- a/paper-server/patches/sources/net/minecraft/world/entity/projectile/ThrownEnderpearl.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/entity/projectile/ThrownEnderpearl.java.patch @@ -48,7 +48,7 @@ entityplayer1.resetFallDistance(); entityplayer1.resetCurrentImpulseContext(); - entityplayer1.hurtServer(entityplayer.serverLevel(), this.damageSources().enderPearl(), 5.0F); -+ entityplayer1.hurtServer(entityplayer.serverLevel(), this.damageSources().enderPearl().customEntityDamager(this), 5.0F); // CraftBukkit ++ entityplayer1.hurtServer(entityplayer.serverLevel(), this.damageSources().enderPearl().customEventDamager(this), 5.0F); // CraftBukkit // Paper - fix DamageSource API } this.playSound(worldserver, vec3d); diff --git a/paper-server/patches/sources/net/minecraft/world/entity/projectile/WitherSkull.java.patch b/paper-server/patches/sources/net/minecraft/world/entity/projectile/WitherSkull.java.patch index ef46840746..96234163f1 100644 --- a/paper-server/patches/sources/net/minecraft/world/entity/projectile/WitherSkull.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/entity/projectile/WitherSkull.java.patch @@ -21,7 +21,7 @@ } } else { - flag = entity.hurtServer(worldserver, this.damageSources().magic(), 5.0F); -+ flag = entity.hurtServer(worldserver, this.damageSources().magic().customCausingEntity(this), 5.0F); // Paper - Fire EntityDamageByEntityEvent for unowned wither skulls ++ flag = entity.hurtServer(worldserver, this.damageSources().magic().customEventDamager(this), 5.0F); // Paper - Fire EntityDamageByEntityEvent for unowned wither skulls // Paper - fix DamageSource API } if (flag && entity instanceof LivingEntity entityliving) { 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 8532324060..7df86e7124 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,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().getEntity(); // Paper - fix DamageSource API - revert to vanilla return (entity != null) ? entity.getBukkitEntity() : null; } @Override public org.bukkit.entity.Entity getDirectEntity() { - net.minecraft.world.entity.Entity entity = this.getHandle().getDamager(); + net.minecraft.world.entity.Entity entity = this.getHandle().getDirectEntity(); // Paper - fix DamageSource API return (entity != null) ? entity.getBukkitEntity() : null; } @@ -65,7 +65,7 @@ public class CraftDamageSource implements DamageSource { @Override public boolean isIndirect() { - return this.getHandle().getCausingDamager() != this.getHandle().getDamager(); + return !this.getHandle().isDirect(); // Paper - fix DamageSource API } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/damage/CraftDamageSourceBuilder.java b/paper-server/src/main/java/org/bukkit/craftbukkit/damage/CraftDamageSourceBuilder.java index 4c6e15535f..35eb95ef6f 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/damage/CraftDamageSourceBuilder.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/damage/CraftDamageSourceBuilder.java @@ -41,6 +41,11 @@ public class CraftDamageSourceBuilder implements DamageSource.Builder { @Override public DamageSource build() { + // Paper start - fix DamageCause API + if (this.causingEntity != null && this.directEntity == null) { + throw new IllegalArgumentException("Direct entity must be set if causing entity is set"); + } + // Paper end - fix DamageCause API return CraftDamageSource.buildFromBukkit(this.damageType, this.causingEntity, this.directEntity, this.damageLocation); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index ea4e1bf4bf..937ed4e777 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -1092,7 +1092,7 @@ public class CraftEventFactory { private static EntityDamageEvent handleEntityDamageEvent(Entity entity, DamageSource source, Map modifiers, Map> modifierFunctions, boolean cancelled) { CraftDamageSource bukkitDamageSource = new CraftDamageSource(source); - Entity damager = (source.getDamager() != null) ? source.getDamager() : source.getEntity(); + final Entity damager = source.getCustomEventDamager(); // Paper - fix DamageSource API if (source.is(DamageTypeTags.IS_EXPLOSION)) { if (damager == null) { return CraftEventFactory.callEntityDamageEvent(source.getDirectBlock(), source.getDirectBlockState(), entity, DamageCause.BLOCK_EXPLOSION, bukkitDamageSource, modifiers, modifierFunctions, cancelled);