mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-04 10:11:29 +01:00
702864d8f8
Updated Upstream (Bukkit/CraftBukkit) 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: fa99e752 PR-1007: Add ItemMeta#getAsComponentString() 94a91782 Fix copy-pasted BlockType.Typed documentation 9b34ac8c Largely restore deprecated PotionData API 51a6449b PR-1008: Deprecate ITEMS_TOOLS, removed in 1.20.5 702d15fe Fix Javadoc reference 42f6cdf4 PR-919: Add internal ItemType and BlockType, delegate Material methods to them 237bb37b SPIGOT-1166, SPIGOT-7647: Expose Damager BlockState in EntityDamageByBlockEvent 035ea146 SPIGOT-6993: Allow #setVelocity to change the speed of a fireball and add a note to #setDirection about it 8c7880fb PR-1004: Improve field rename handling and centralize conversion between bukkit and string more 87c90e93 SPIGOT-7650: Add DamageSource for EntityDeathEvent and PlayerDeathEvent CraftBukkit Changes: 4af0f22e8 SPIGOT-7664: Item meta should prevail over block states c2ccc46ec SPIGOT-7666: Fix access to llama and horse special slot 124ac66d7 SPIGOT-7665: Fix ThrownPotion#getEffects() implementation only bringing custom effects 66f1f439a Restore null page behaviour of signed books even though not strictly allowed by API 6118e5398 Fix regression listening to minecraft:brand custom payloads c1a26b366 Fix unnecessary and potential not thread-safe chat visibility check 12360a7ec Remove unused imports 147b098b4 PR-1397: Add ItemMeta#getAsComponentString() 428aefe0e Largely restore deprecated PotionData API afe5b5ee9 PR-1275: Add internal ItemType and BlockType, delegate Material methods to them 8afeafa7d SPIGOT-1166, SPIGOT-7647: Expose Damager BlockState in EntityDamageByBlockEvent 4e7d749d4 SPIGOT-6993: Allow #setVelocity to change the speed of a fireball and add a note to #setDirection about it 441880757 Support both entity_data and bucket_entity_data on axolotl/fish buckets 0e22fdd1e Fix custom direct BlockState being not correctly set in DamageSource f2182ed47 SPIGOT-7659: TropicalFishBucketMeta should use BUCKET_ENTITY_DATA 2a6207fe1 PR-1393: Improve field rename handling and centralize conversion between bukkit and string more c024a5039 SPIGOT-7650: Add DamageSource for EntityDeathEvent and PlayerDeathEvent 741b84480 PR-1390: Improve internal handling of damage sources 0364df4e1 SPIGOT-7657: Error when loading angry entities
211 lines
14 KiB
Diff
211 lines
14 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/world/damagesource/DamageSource.java
|
|
+++ b/src/main/java/net/minecraft/world/damagesource/DamageSource.java
|
|
@@ -0,0 +0,0 @@ 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
|
|
+ @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;
|
|
@@ -0,0 +0,0 @@ public class DamageSource {
|
|
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 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;
|
|
+ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/world/damagesource/DamageSources.java
|
|
+++ b/src/main/java/net/minecraft/world/damagesource/DamageSources.java
|
|
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/animal/Turtle.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/animal/Turtle.java
|
|
@@ -0,0 +0,0 @@ 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/HangingEntity.java b/src/main/java/net/minecraft/world/entity/decoration/HangingEntity.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/decoration/HangingEntity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/decoration/HangingEntity.java
|
|
@@ -0,0 +0,0 @@ public abstract class HangingEntity extends Entity {
|
|
} else {
|
|
if (!this.isRemoved() && !this.level().isClientSide) {
|
|
// CraftBukkit start - fire break events
|
|
- Entity damager = (source.isIndirect()) ? source.getEntity() : source.getDirectEntity();
|
|
+ Entity damager = (source.isIndirect() && 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/monster/Creeper.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/monster/Creeper.java
|
|
@@ -0,0 +0,0 @@ public class Creeper extends Monster implements PowerableMob {
|
|
if (!event.isCancelled()) {
|
|
// CraftBukkit end
|
|
this.dead = true;
|
|
- this.level().explode(this, this.level().damageSources().explosion(this, this.entityIgniter, net.minecraft.world.damagesource.DamageTypes.EXPLOSION), 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.discard(EntityRemoveEvent.Cause.EXPLODE); // CraftBukkit - add Bukkit remove cause
|
|
this.spawnLingeringCloud();
|
|
// CraftBukkit start
|
|
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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/projectile/EvokerFangs.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/projectile/EvokerFangs.java
|
|
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/projectile/ThrownEnderpearl.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/projectile/ThrownEnderpearl.java
|
|
@@ -0,0 +0,0 @@ public class ThrownEnderpearl extends ThrowableItemProjectile {
|
|
|
|
entityplayer.connection.teleport(teleEvent.getTo());
|
|
entity.resetFallDistance();
|
|
- entity.hurt(this.damageSources().fall().customEntityDamager(this), 5.0F); // CraftBukkit
|
|
+ entity.hurt(this.damageSources().fall().customEventDamager(this), 5.0F); // CraftBukkit // Paper - fix DamageSource API
|
|
}
|
|
// CraftBukkit end
|
|
this.level().playSound((Player) null, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_TELEPORT, SoundSource.PLAYERS);
|
|
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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/projectile/WitherSkull.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/projectile/WitherSkull.java
|
|
@@ -0,0 +0,0 @@ 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) {
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/damage/CraftDamageSource.java b/src/main/java/org/bukkit/craftbukkit/damage/CraftDamageSource.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/damage/CraftDamageSource.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/damage/CraftDamageSource.java
|
|
@@ -0,0 +0,0 @@ public class CraftDamageSource implements DamageSource {
|
|
|
|
@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;
|
|
}
|
|
|
|
@@ -0,0 +0,0 @@ public class CraftDamageSource implements DamageSource {
|
|
|
|
@Override
|
|
public boolean isIndirect() {
|
|
- return this.getHandle().getEntity() != this.getHandle().getDamager();
|
|
+ return this.getHandle().isIndirect(); // 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/damage/CraftDamageSourceBuilder.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/damage/CraftDamageSourceBuilder.java
|
|
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
@@ -0,0 +0,0 @@ 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);
|