Paper/patches/server/0203-Add-EntityKnockbackByEntityEvent-and-EntityPushedByE.patch

201 lines
15 KiB
Diff
Raw Normal View History

2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Brokkonaut <hannos17@gmx.de>
Date: Mon, 18 Jun 2018 15:46:23 +0200
Subject: [PATCH] Add EntityKnockbackByEntityEvent and
2022-12-23 20:59:11 +01:00
EntityPushedByEntityAttackEvent
Co-authored-by: aerulion <aerulion@gmail.com>
2021-06-11 14:02:28 +02:00
This event is called when an entity receives knockback by another entity.
2022-12-23 20:59:11 +01:00
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 42f8c39fa5f9f31c03d4e7af9fb6b7a842f29aae..d6437a6b6b90ceb6fe7d2375ab2fc9e28b469c9b 100644
2022-12-23 20:59:11 +01:00
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#10164) 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: 63c208dd Remove no longer used import 70be76c7 PR-958: Further clarify deprecation of TAG_CONTAINER_ARRAY ae21f4ac PR-955: Add methods to place structures with block/entity transformers e3d960f2 SPIGOT-7547: Remark that Damageable#setAbsorptionAmount() is capped to a specific value b125516c Fix typo in RecipeChoice.ExactChoice docs 309497c1 Add EntityMountEvent and EntityDismount Event 2fd45ae3 Improve ItemFactory#enchantItem consistency 2b198268 PR-933: Define native persistent data types for lists CraftBukkit Changes: 771182f70 PR-1327: Add methods to place structures with block/entity transformers e41ad4c82 SPIGOT-7567: SpawnReason for SNOWMAN is reported as BUILD_IRONGOLEM 76931e8bd Add EntityMountEvent and EntityDismount Event 9b29b21c7 PR-1183: Better handle lambda expression and renaming of classes in Commodore 1462ebe85 Reformat Commodore.java 9fde4c037 PR-1324: Improve ItemFactory#enchantItem consistency 4e419c774 PR-1295: Define native persistent data types for lists dd8cca388 SPIGOT-7562: Fix Score#getScore and Score#isScoreSet 690278200 Only fetch an online UUID in online mode 1da8d9a53 Fire PreLogin events even in offline mode 2e88514ad PR-1325: Use CraftBlockType and CraftItemType instead of CraftMagicNumbers to convert between minecraft and bukkit block / item representation Spigot Changes: 864e4acc Restore accidentally removed package-info.java f91a10d5 Remove obsolete EntityMountEvent and EntityDismountEvent 828f0593 SPIGOT-7558: Deprecate silenceable lightning API as sound is now client-side and cannot be removed cdc4e035 Remove obsolete patch fetching correct mode UUIDs 49e36b8e Merge related BungeeCord patches 6e87b9ab Remove obsolete firing of PreLogin events in offline mode 5c76b183 Remove redundant patch dealing with exceptions in the crash reporter 3a2219d1 Remove redundant patch logging cause of unexpected exception
2024-01-14 10:46:04 +01:00
@@ -1909,8 +1909,17 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
2022-12-23 20:59:11 +01:00
}
public void push(double deltaX, double deltaY, double deltaZ) {
- this.setDeltaMovement(this.getDeltaMovement().add(deltaX, deltaY, deltaZ));
- this.hasImpulse = true;
+ // Paper start - Add EntityKnockbackByEntityEvent and EntityPushedByEntityAttackEvent
2022-12-23 20:59:11 +01:00
+ this.push(deltaX, deltaY, deltaZ, null);
+ }
+
+ public void push(double deltaX, double deltaY, double deltaZ, @org.jetbrains.annotations.Nullable Entity pushingEntity) {
+ org.bukkit.util.Vector delta = new org.bukkit.util.Vector(deltaX, deltaY, deltaZ);
+ if (pushingEntity == null || new io.papermc.paper.event.entity.EntityPushedByEntityAttackEvent(getBukkitEntity(), pushingEntity.getBukkitEntity(), delta).callEvent()) {
+ this.setDeltaMovement(this.getDeltaMovement().add(delta.getX(), delta.getY(), delta.getZ()));
+ this.hasImpulse = true;
+ }
+ // Paper end - Add EntityKnockbackByEntityEvent and EntityPushedByEntityAttackEvent
2022-12-23 20:59:11 +01:00
}
protected void markHurt() {
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index fa1c7d1781a2e2269359fa1860de79e918de7635..854177cb491d602c1f33e3496e01ba8a63d708e6 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
2023-12-05 23:12:48 +01:00
@@ -1513,7 +1513,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
2023-03-14 19:59:51 +01:00
d0 = (Math.random() - Math.random()) * 0.01D;
2021-06-11 14:02:28 +02:00
}
2021-06-12 21:30:37 +02:00
- this.knockback(0.4000000059604645D, d0, d1);
+ this.knockback(0.4000000059604645D, d0, d1, entity1); // Paper - Add EntityKnockbackByEntityEvent and EntityPushedByEntityAttackEvent
2023-03-14 19:59:51 +01:00
if (!flag) {
this.indicateDamage(d0, d1);
}
2023-12-05 23:12:48 +01:00
@@ -1561,7 +1561,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
2021-06-11 14:02:28 +02:00
}
protected void blockedByShield(LivingEntity target) {
2021-06-12 21:30:37 +02:00
- target.knockback(0.5D, target.getX() - this.getX(), target.getZ() - this.getZ());
+ target.knockback(0.5D, target.getX() - this.getX(), target.getZ() - this.getZ(), this); // Paper - Add EntityKnockbackByEntityEvent and EntityPushedByEntityAttackEvent
2021-06-11 14:02:28 +02:00
}
private boolean checkTotemDeathProtection(DamageSource source) {
2023-12-05 23:12:48 +01:00
@@ -1820,6 +1820,11 @@ public abstract class LivingEntity extends Entity implements Attackable {
2021-06-11 14:02:28 +02:00
}
2021-06-12 21:30:37 +02:00
public void knockback(double strength, double x, double z) {
+ // Paper start - Add EntityKnockbackByEntityEvent and EntityPushedByEntityAttackEvent
2021-06-12 21:30:37 +02:00
+ this.knockback(strength, x, z, null);
2021-06-11 14:02:28 +02:00
+ }
2021-06-12 21:30:37 +02:00
+ public void knockback(double strength, double x, double z, Entity knockingBackEntity) {
+ // Paper end - Add EntityKnockbackByEntityEvent and EntityPushedByEntityAttackEvent
2021-06-12 21:30:37 +02:00
strength *= 1.0D - this.getAttributeValue(Attributes.KNOCKBACK_RESISTANCE);
if (strength > 0.0D) {
2021-06-11 14:02:28 +02:00
this.hasImpulse = true;
2023-12-05 23:12:48 +01:00
@@ -1827,6 +1832,15 @@ public abstract class LivingEntity extends Entity implements Attackable {
2021-06-12 21:30:37 +02:00
Vec3 vec3d1 = (new Vec3(x, 0.0D, z)).normalize().scale(strength);
2021-06-11 14:02:28 +02:00
2023-06-07 21:54:11 +02:00
this.setDeltaMovement(vec3d.x / 2.0D - vec3d1.x, this.onGround() ? Math.min(0.4D, vec3d.y / 2.0D + strength) : vec3d.y, vec3d.z / 2.0D - vec3d1.z);
+ // Paper start - Add EntityKnockbackByEntityEvent and EntityPushedByEntityAttackEventt
2021-06-12 21:30:37 +02:00
+ Vec3 currentMovement = this.getDeltaMovement();
+ org.bukkit.util.Vector delta = new org.bukkit.util.Vector(currentMovement.x - vec3d.x, currentMovement.y - vec3d.y, currentMovement.z - vec3d.z);
2021-06-11 14:02:28 +02:00
+ // Restore old velocity to be able to access it in the event
+ this.setDeltaMovement(vec3d);
2021-06-12 21:30:37 +02:00
+ if (knockingBackEntity == null || new com.destroystokyo.paper.event.entity.EntityKnockbackByEntityEvent((org.bukkit.entity.LivingEntity) getBukkitEntity(), knockingBackEntity.getBukkitEntity(), (float) strength, delta).callEvent()) {
2021-06-11 14:02:28 +02:00
+ this.setDeltaMovement(vec3d.x + delta.getX(), vec3d.y + delta.getY(), vec3d.z + delta.getZ());
+ }
+ // Paper end - Add EntityKnockbackByEntityEvent and EntityPushedByEntityAttackEvent
2021-06-11 14:02:28 +02:00
}
}
diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java
index 374a91e712c2a6a8ad87d1047bb07d44eaa9908a..70820b8d95c71ea6df8a5cae16784ed764440a45 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/entity/Mob.java
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
2023-12-05 23:12:48 +01:00
@@ -1646,7 +1646,7 @@ public abstract class Mob extends LivingEntity implements Targeting {
2021-06-11 14:02:28 +02:00
if (flag) {
if (f1 > 0.0F && target instanceof LivingEntity) {
2021-06-12 21:30:37 +02:00
- ((LivingEntity) target).knockback((double) (f1 * 0.5F), (double) Mth.sin(this.getYRot() * 0.017453292F), (double) (-Mth.cos(this.getYRot() * 0.017453292F)));
+ ((LivingEntity) target).knockback((double) (f1 * 0.5F), (double) Mth.sin(this.getYRot() * 0.017453292F), (double) (-Mth.cos(this.getYRot() * 0.017453292F)), this); // Paper - Add EntityKnockbackByEntityEvent and EntityPushedByEntityAttackEvent
2021-06-11 14:02:28 +02:00
this.setDeltaMovement(this.getDeltaMovement().multiply(0.6D, 1.0D, 0.6D));
}
diff --git a/src/main/java/net/minecraft/world/entity/ai/behavior/RamTarget.java b/src/main/java/net/minecraft/world/entity/ai/behavior/RamTarget.java
index e319a46a21a94314c5d496820b1ac4879dcf56b9..4f78e7fbb7a082069b44f7b28f0048e856e5c773 100644
--- a/src/main/java/net/minecraft/world/entity/ai/behavior/RamTarget.java
+++ b/src/main/java/net/minecraft/world/entity/ai/behavior/RamTarget.java
2023-03-14 19:59:51 +01:00
@@ -77,7 +77,7 @@ public class RamTarget extends Behavior<Goat> {
float f = 0.25F * (float)(i - j);
2022-12-07 19:52:24 +01:00
float g = Mth.clamp(entity.getSpeed() * 1.65F, 0.2F, 3.0F) + f;
2023-03-14 19:59:51 +01:00
float h = livingEntity.isDamageSourceBlocked(world.damageSources().mobAttack(entity)) ? 0.5F : 1.0F;
2022-12-07 19:52:24 +01:00
- livingEntity.knockback((double)(h * g) * this.getKnockbackForce.applyAsDouble(entity), this.ramDirection.x(), this.ramDirection.z());
+ livingEntity.knockback((double)(h * g) * this.getKnockbackForce.applyAsDouble(entity), this.ramDirection.x(), this.ramDirection.z(), entity); // Paper - Add EntityKnockbackByEntityEvent and EntityPushedByEntityAttackEvent
2022-12-07 19:52:24 +01:00
this.finishRam(world, entity);
world.playSound((Player)null, entity, this.getImpactSound.apply(entity), SoundSource.NEUTRAL, 1.0F, 1.0F);
} else if (this.hasRammedHornBreakingBlock(world, entity)) {
2022-12-23 20:59:11 +01:00
diff --git a/src/main/java/net/minecraft/world/entity/ai/behavior/warden/SonicBoom.java b/src/main/java/net/minecraft/world/entity/ai/behavior/warden/SonicBoom.java
index 29cfd065f246bbd3d3c2a5bbd32c3f4813a02951..771d798fa3b367043129f41101c65f13f0b466fa 100644
2022-12-23 20:59:11 +01:00
--- a/src/main/java/net/minecraft/world/entity/ai/behavior/warden/SonicBoom.java
+++ b/src/main/java/net/minecraft/world/entity/ai/behavior/warden/SonicBoom.java
2023-03-14 19:59:51 +01:00
@@ -68,7 +68,7 @@ public class SonicBoom extends Behavior<Warden> {
target.hurt(world.damageSources().sonicBoom(entity), 10.0F);
2022-12-23 20:59:11 +01:00
double d = 0.5D * (1.0D - target.getAttributeValue(Attributes.KNOCKBACK_RESISTANCE));
double e = 2.5D * (1.0D - target.getAttributeValue(Attributes.KNOCKBACK_RESISTANCE));
- target.push(vec33.x() * e, vec33.y() * d, vec33.z() * e);
+ target.push(vec33.x() * e, vec33.y() * d, vec33.z() * e, entity); // Paper - Add EntityKnockbackByEntityEvent and EntityPushedByEntityAttackEvent
2022-12-23 20:59:11 +01:00
});
}
}
diff --git a/src/main/java/net/minecraft/world/entity/boss/enderdragon/EnderDragon.java b/src/main/java/net/minecraft/world/entity/boss/enderdragon/EnderDragon.java
index f5ce6423b8146cc741023e15004fe9814a035da8..666c62d796cae9a70516680e26196f7e02c53918 100644
2022-12-23 20:59:11 +01:00
--- a/src/main/java/net/minecraft/world/entity/boss/enderdragon/EnderDragon.java
+++ b/src/main/java/net/minecraft/world/entity/boss/enderdragon/EnderDragon.java
2023-09-22 00:01:00 +02:00
@@ -458,7 +458,7 @@ public class EnderDragon extends Mob implements Enemy {
2022-12-23 20:59:11 +01:00
double d3 = entity.getZ() - d1;
double d4 = Math.max(d2 * d2 + d3 * d3, 0.1D);
- entity.push(d2 / d4 * 4.0D, 0.20000000298023224D, d3 / d4 * 4.0D);
+ entity.push(d2 / d4 * 4.0D, 0.20000000298023224D, d3 / d4 * 4.0D, this); // Paper - Add EntityKnockbackByEntityEvent and EntityPushedByEntityAttackEvent
2022-12-23 20:59:11 +01:00
if (!this.phaseManager.getCurrentPhase().isSitting() && ((LivingEntity) entity).getLastHurtByMobTimestamp() < entity.tickCount - 2) {
2023-03-14 19:59:51 +01:00
entity.hurt(this.damageSources().mobAttack(this), 5.0F);
2022-12-23 20:59:11 +01:00
this.doEnchantDamageEffects(this, entity);
diff --git a/src/main/java/net/minecraft/world/entity/monster/Ravager.java b/src/main/java/net/minecraft/world/entity/monster/Ravager.java
index 041f1650b853138e4286fe83a08d79d276054ce7..aba20a4352d8983b01ab5d329187588f68d3e405 100644
2022-12-23 20:59:11 +01:00
--- a/src/main/java/net/minecraft/world/entity/monster/Ravager.java
+++ b/src/main/java/net/minecraft/world/entity/monster/Ravager.java
2023-09-22 00:01:00 +02:00
@@ -265,7 +265,7 @@ public class Ravager extends Raider {
2022-12-23 20:59:11 +01:00
double d1 = entity.getZ() - this.getZ();
double d2 = Math.max(d0 * d0 + d1 * d1, 0.001D);
- entity.push(d0 / d2 * 4.0D, 0.2D, d1 / d2 * 4.0D);
+ entity.push(d0 / d2 * 4.0D, 0.2D, d1 / d2 * 4.0D, this); // Paper - Add EntityKnockbackByEntityEvent and EntityPushedByEntityAttackEvent
2022-12-23 20:59:11 +01:00
}
@Override
diff --git a/src/main/java/net/minecraft/world/entity/monster/hoglin/HoglinBase.java b/src/main/java/net/minecraft/world/entity/monster/hoglin/HoglinBase.java
index 81003ce3f05c6be6f52a92b86a4721235f4ce12a..cae7e3e85c3b911f50f8a06badf695c3df2847e5 100644
2022-12-23 20:59:11 +01:00
--- a/src/main/java/net/minecraft/world/entity/monster/hoglin/HoglinBase.java
+++ b/src/main/java/net/minecraft/world/entity/monster/hoglin/HoglinBase.java
2023-03-14 19:59:51 +01:00
@@ -40,7 +40,7 @@ public interface HoglinBase {
2023-06-07 21:54:11 +02:00
double j = f * (double)(attacker.level().random.nextFloat() * 0.5F + 0.2F);
2022-12-23 20:59:11 +01:00
Vec3 vec3 = (new Vec3(g, 0.0D, h)).normalize().scale(j).yRot(i);
2023-06-07 21:54:11 +02:00
double k = f * (double)attacker.level().random.nextFloat() * 0.5D;
2022-12-23 20:59:11 +01:00
- target.push(vec3.x, k, vec3.z);
+ target.push(vec3.x, k, vec3.z, attacker); // Paper - Add EntityKnockbackByEntityEvent and EntityPushedByEntityAttackEvent
2022-12-23 20:59:11 +01:00
target.hurtMarked = true;
}
}
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/world/entity/player/Player.java b/src/main/java/net/minecraft/world/entity/player/Player.java
index bfc33822ab5ca58d77e11d3cbd140ba6c0374a6e..871adf673c536912604ea18f8146e7eead01bde5 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/entity/player/Player.java
+++ b/src/main/java/net/minecraft/world/entity/player/Player.java
@@ -1277,9 +1277,9 @@ public abstract class Player extends LivingEntity {
2021-06-11 14:02:28 +02:00
if (flag5) {
if (i > 0) {
if (target instanceof LivingEntity) {
2021-06-12 21:30:37 +02:00
- ((LivingEntity) target).knockback((double) ((float) i * 0.5F), (double) Mth.sin(this.getYRot() * 0.017453292F), (double) (-Mth.cos(this.getYRot() * 0.017453292F)));
+ ((LivingEntity) target).knockback((double) ((float) i * 0.5F), (double) Mth.sin(this.getYRot() * 0.017453292F), (double) (-Mth.cos(this.getYRot() * 0.017453292F)), this); // Paper - Add EntityKnockbackByEntityEvent and EntityPushedByEntityAttackEvent
2021-06-11 14:02:28 +02:00
} else {
2022-12-23 20:59:11 +01:00
- target.push((double) (-Mth.sin(this.getYRot() * 0.017453292F) * (float) i * 0.5F), 0.1D, (double) (Mth.cos(this.getYRot() * 0.017453292F) * (float) i * 0.5F));
+ target.push((double) (-Mth.sin(this.getYRot() * 0.017453292F) * (float) i * 0.5F), 0.1D, (double) (Mth.cos(this.getYRot() * 0.017453292F) * (float) i * 0.5F), this); // Paper - Add EntityKnockbackByEntityEvent and EntityPushedByEntityAttackEvent
2021-06-11 14:02:28 +02:00
}
2022-12-23 20:59:11 +01:00
this.setDeltaMovement(this.getDeltaMovement().multiply(0.6D, 1.0D, 0.6D));
@@ -1301,7 +1301,7 @@ public abstract class Player extends LivingEntity {
2021-11-23 16:04:41 +01:00
if (entityliving != this && entityliving != target && !this.isAlliedTo((Entity) entityliving) && (!(entityliving instanceof ArmorStand) || !((ArmorStand) entityliving).isMarker()) && this.distanceToSqr((Entity) entityliving) < 9.0D) {
2021-06-11 14:02:28 +02:00
// CraftBukkit start - Only apply knockback if the damage hits
2023-03-14 19:59:51 +01:00
if (entityliving.hurt(this.damageSources().playerAttack(this).sweep(), f4)) {
2021-06-12 21:30:37 +02:00
- entityliving.knockback(0.4000000059604645D, (double) Mth.sin(this.getYRot() * 0.017453292F), (double) (-Mth.cos(this.getYRot() * 0.017453292F)));
+ entityliving.knockback(0.4000000059604645D, (double) Mth.sin(this.getYRot() * 0.017453292F), (double) (-Mth.cos(this.getYRot() * 0.017453292F)), this); // Paper - Add EntityKnockbackByEntityEvent and EntityPushedByEntityAttackEvent
2021-06-11 14:02:28 +02:00
}
// CraftBukkit end
}
2022-12-23 20:59:11 +01:00
diff --git a/src/main/java/net/minecraft/world/entity/projectile/AbstractArrow.java b/src/main/java/net/minecraft/world/entity/projectile/AbstractArrow.java
index 0f700442a7559fac5d27d1fb6b3716f3853a9897..f3861cea4eb6a39fa16936383f8dabc6689a58a9 100644
2022-12-23 20:59:11 +01:00
--- a/src/main/java/net/minecraft/world/entity/projectile/AbstractArrow.java
+++ b/src/main/java/net/minecraft/world/entity/projectile/AbstractArrow.java
2023-12-05 23:12:48 +01:00
@@ -409,7 +409,7 @@ public abstract class AbstractArrow extends Projectile {
2022-12-23 20:59:11 +01:00
Vec3 vec3d = this.getDeltaMovement().multiply(1.0D, 0.0D, 1.0D).normalize().scale((double) this.knockback * 0.6D * d0);
if (vec3d.lengthSqr() > 0.0D) {
- entityliving.push(vec3d.x, 0.1D, vec3d.z);
+ entityliving.push(vec3d.x, 0.1D, vec3d.z, this); // Paper
}
}