mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-25 20:16:19 +01:00
d1a72eac31
Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 1fc1020a PR-1049: Add MenuType API 8ae2e3be PR-1055: Expand riptiding API cac68bfb SPIGOT-7890: AttributeModifier#getUniqueId() doesn't match the UUID passed to its constructor 7004fcf2 SPIGOT-7886: Fix mistake in AttributeModifier UUID shim 1ac7f950 PR-1054: Add FireworkMeta#hasPower 4cfb565f SPIGOT-7873: Add powered state for skulls CraftBukkit Changes: bbb30e7a8 SPIGOT-7894: NPE when sending tile entity update ba21e9472 SPIGOT-7895: PlayerItemBreakEvent not firing 0fb24bbe0 SPIGOT-7875: Fix PlayerItemConsumeEvent cancellation causing client-side desync 815066449 SPIGOT-7891: Can't remove second ingredient of MerchantRecipe 45c206f2c PR-1458: Add MenuType API 19c8ef9ae SPIGOT-7867: Merchant instanceof AbstractVillager always returns false 4e006d28f PR-1468: Expand riptiding API bd8aded7d Ignore checks in CraftPlayerProfile for ResolvableProfile used in profile components 8679620b5 SPIGOT-7889: Fix tool component deserialisation without speed and/or correct-for-drops 8d5222691 SPIGOT-7882, PR-1467: Fix conversion of name in Profile Component to empty if it is missing 63f91669a SPIGOT-7887: Remove duplicate ProjectileHitEvent for fireballs 7070de8c8 SPIGOT-7878: Server#getLootTable does not return null on invalid loot table 060ee6cae SPIGOT-7876: Can't kick player or disconnect player in PlayerLoginEvent when checking for cookies 7ccb86cc0 PR-1465: Add FireworkMeta#hasPower 804ad6491 SPIGOT-7873: Add powered state for skulls f9610cdcb Improve minecart movement Spigot Changes: a759b629 Rebuild patches Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
235 lines
15 KiB
Diff
235 lines
15 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Jake Potrebic <jake.m.potrebic@gmail.com>
|
|
Date: Sat, 9 Mar 2024 14:13:04 -0800
|
|
Subject: [PATCH] Fix DamageSource API
|
|
|
|
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 aee26dd78953ff43306aaa64161f5b9edcdd4b83..bb1a60180e58c1333e7bb33e8acf1b0225eda8a8 100644
|
|
--- a/src/main/java/net/minecraft/world/damagesource/DamageSource.java
|
|
+++ b/src/main/java/net/minecraft/world/damagesource/DamageSource.java
|
|
@@ -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 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;
|
|
@@ -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 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;
|
|
+ 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.customCausingEntityDamager = entity;
|
|
+ damageSource.customEventDamager = entity;
|
|
+ // Paper end - fix DamageSource API
|
|
return damageSource;
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/damagesource/DamageSources.java b/src/main/java/net/minecraft/world/damagesource/DamageSources.java
|
|
index caf1d79e2bbdd257a5439e2973653747e678805f..e34584e4780f343d6c946af5377088d53818e88e 100644
|
|
--- a/src/main/java/net/minecraft/world/damagesource/DamageSources.java
|
|
+++ b/src/main/java/net/minecraft/world/damagesource/DamageSources.java
|
|
@@ -264,13 +264,7 @@ public class DamageSources {
|
|
}
|
|
|
|
public DamageSource explosion(@Nullable Entity source, @Nullable Entity attacker) {
|
|
- // CraftBukkit start
|
|
- return this.explosion(source, attacker, attacker != null && source != null ? DamageTypes.PLAYER_EXPLOSION : DamageTypes.EXPLOSION);
|
|
- }
|
|
-
|
|
- public DamageSource explosion(@Nullable Entity entity, @Nullable Entity entity1, ResourceKey<DamageType> resourceKey) {
|
|
- return this.source(resourceKey, entity, entity1);
|
|
- // CraftBukkit end
|
|
+ return this.source(attacker != null && source != null ? DamageTypes.PLAYER_EXPLOSION : DamageTypes.EXPLOSION, source, attacker); // Paper - revert to vanilla
|
|
}
|
|
|
|
public DamageSource sonicBoom(Entity attacker) {
|
|
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
index 57e7938bc605f320ed5303fcbc617b4d32ba42b8..ef05c75d86ce3a7e4d4438dcd6f98c778568634a 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
@@ -3262,7 +3262,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
|
return;
|
|
}
|
|
|
|
- if (!this.hurt(this.damageSources().lightningBolt().customEntityDamager(lightning), 5.0F)) {
|
|
+ if (!this.hurt(this.damageSources().lightningBolt().customEventDamager(lightning), 5.0F)) { // Paper - fix DamageSource API
|
|
return;
|
|
}
|
|
// CraftBukkit end
|
|
diff --git a/src/main/java/net/minecraft/world/entity/animal/Turtle.java b/src/main/java/net/minecraft/world/entity/animal/Turtle.java
|
|
index 2e5ef2a680e294b49f29e8d7ba8bd0ed023c393c..4bfa947531c4a67989e18032754dabf4c69e989c 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/animal/Turtle.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/animal/Turtle.java
|
|
@@ -334,7 +334,7 @@ public class Turtle extends Animal {
|
|
|
|
@Override
|
|
public void thunderHit(ServerLevel world, LightningBolt lightning) {
|
|
- this.hurt(this.damageSources().lightningBolt().customEntityDamager(lightning), Float.MAX_VALUE); // CraftBukkit
|
|
+ this.hurt(this.damageSources().lightningBolt().customEventDamager(lightning), Float.MAX_VALUE); // CraftBukkit // Paper - fix DamageSource API
|
|
}
|
|
|
|
@Override
|
|
diff --git a/src/main/java/net/minecraft/world/entity/decoration/BlockAttachedEntity.java b/src/main/java/net/minecraft/world/entity/decoration/BlockAttachedEntity.java
|
|
index 7bc612890f941177da11da0ce047d5a74d8ebb33..270acce7411e5ada71eaa04c05efc888b295d9e3 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/decoration/BlockAttachedEntity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/decoration/BlockAttachedEntity.java
|
|
@@ -96,7 +96,7 @@ public abstract class BlockAttachedEntity extends Entity {
|
|
} else {
|
|
if (!this.isRemoved() && !this.level().isClientSide) {
|
|
// 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/src/main/java/net/minecraft/world/entity/monster/Creeper.java b/src/main/java/net/minecraft/world/entity/monster/Creeper.java
|
|
index 9bf11a8b44e696b6587bc775904a836d390e437b..d1041f2a4f1b3ea29ad532006e18cdc30c5019fa 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).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);
|
|
this.discard(EntityRemoveEvent.Cause.EXPLODE); // CraftBukkit - add Bukkit remove cause
|
|
diff --git a/src/main/java/net/minecraft/world/entity/projectile/EvokerFangs.java b/src/main/java/net/minecraft/world/entity/projectile/EvokerFangs.java
|
|
index c75433bb0fcd4264148950467bf6b700296aca7b..820965950c8b6c868ee261cf9613665e583f092e 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/projectile/EvokerFangs.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/projectile/EvokerFangs.java
|
|
@@ -135,7 +135,7 @@ public class EvokerFangs extends Entity implements TraceableEntity {
|
|
|
|
if (target.isAlive() && !target.isInvulnerable() && target != entityliving1) {
|
|
if (entityliving1 == null) {
|
|
- 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/src/main/java/net/minecraft/world/entity/projectile/ThrownEnderpearl.java b/src/main/java/net/minecraft/world/entity/projectile/ThrownEnderpearl.java
|
|
index f43dd56182ced23cf1cf65c149c532a611cc933a..1aa5e57a4e6a4be60514d8808a2e6c973d93e798 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/projectile/ThrownEnderpearl.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/projectile/ThrownEnderpearl.java
|
|
@@ -89,7 +89,7 @@ public class ThrownEnderpearl extends ThrowableItemProjectile {
|
|
// entity.changeDimension(new DimensionTransition(worldserver, this.position(), entity.getDeltaMovement(), entity.getYRot(), entity.getXRot(), DimensionTransition.DO_NOTHING)); // CraftBukkit - moved up
|
|
entity.resetFallDistance();
|
|
entityplayer.resetCurrentImpulseContext();
|
|
- entity.hurt(this.damageSources().fall().customEntityDamager(this), 5.0F); // CraftBukkit
|
|
+ entity.hurt(this.damageSources().fall().customEventDamager(this), 5.0F); // CraftBukkit // Paper - fix DamageSource API
|
|
this.playSound(worldserver, this.position());
|
|
}
|
|
} else {
|
|
diff --git a/src/main/java/net/minecraft/world/entity/projectile/WitherSkull.java b/src/main/java/net/minecraft/world/entity/projectile/WitherSkull.java
|
|
index 60eac9df10a9a395a1568925515d010eb51a64e5..55fd997a4e894eeab24de269d59e486196ffbe8d 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/projectile/WitherSkull.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/projectile/WitherSkull.java
|
|
@@ -77,7 +77,7 @@ public class WitherSkull extends AbstractHurtingProjectile {
|
|
}
|
|
}
|
|
} else {
|
|
- flag = entity.hurt(this.damageSources().magic().customCausingEntity(this), 5.0F); // Paper - Fire EntityDamageByEntityEvent for unowned wither skulls
|
|
+ flag = entity.hurt(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/src/main/java/org/bukkit/craftbukkit/damage/CraftDamageSource.java b/src/main/java/org/bukkit/craftbukkit/damage/CraftDamageSource.java
|
|
index 8532324060eed772a10e2a3429890438cf32f9ba..7df86e7124a9ed359f05324b8fc4c8862f7e4b79 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/damage/CraftDamageSource.java
|
|
+++ b/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/src/main/java/org/bukkit/craftbukkit/damage/CraftDamageSourceBuilder.java b/src/main/java/org/bukkit/craftbukkit/damage/CraftDamageSourceBuilder.java
|
|
index 4c6e15535fa40aad8cf1920f392589404f9ba79c..35eb95ef6fb6a0f7ea63351e90741c489fdd15f9 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/damage/CraftDamageSourceBuilder.java
|
|
+++ b/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/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
index d4c809649ff84ac953c0c93fc7031a27d235b72c..4432592de42df9c5a1851ec7430a14afc8ec5647 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
@@ -1094,7 +1094,7 @@ public class CraftEventFactory {
|
|
|
|
private static EntityDamageEvent handleEntityDamageEvent(Entity entity, DamageSource source, Map<DamageModifier, Double> modifiers, Map<DamageModifier, Function<? super Double, Double>> 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);
|