Paper/patches/server/0212-Implement-EntityKnockbackByEntityEvent-and-EntityPus.patch

201 lines
14 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
2022-12-23 20:59:11 +01:00
Subject: [PATCH] Implement EntityKnockbackByEntityEvent and
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 66b727c533d3a2b7b5938ab9b9b7b4a76bb62966..378027b72852e5d465c8f621168605ee5c522770 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -1767,8 +1767,17 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
}
public void push(double deltaX, double deltaY, double deltaZ) {
- this.setDeltaMovement(this.getDeltaMovement().add(deltaX, deltaY, deltaZ));
- this.hasImpulse = true;
+ // Paper start - call EntityPushedByEntityEvent
+ 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 - call EntityPushedByEntityEvent
}
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
2022-12-23 20:59:11 +01:00
index 4ebdf94833062cde6882f09f1d6878062f2c579e..19cd680bd77196b99767b274599e9eb5ead80192 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
2022-12-07 19:52:24 +01:00
@@ -1457,7 +1457,7 @@ public abstract class LivingEntity extends Entity {
2021-06-11 14:02:28 +02:00
}
2021-06-12 21:30:37 +02:00
this.hurtDir = (float) (Mth.atan2(d1, d0) * 57.2957763671875D - (double) this.getYRot());
- this.knockback(0.4000000059604645D, d0, d1);
2022-12-23 20:59:11 +01:00
+ this.knockback(0.4000000059604645D, d0, d1, entity1); // Paper
2021-06-11 14:02:28 +02:00
} else {
this.hurtDir = (float) ((int) (Math.random() * 2.0D) * 180);
}
2022-12-07 19:52:24 +01:00
@@ -1505,7 +1505,7 @@ public abstract class LivingEntity extends Entity {
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());
2022-12-23 20:59:11 +01:00
+ target.knockback(0.5D, target.getX() - this.getX(), target.getZ() - this.getZ(), this); // Paper
2021-06-11 14:02:28 +02:00
}
private boolean checkTotemDeathProtection(DamageSource source) {
2022-12-07 19:52:24 +01:00
@@ -1761,6 +1761,11 @@ public abstract class LivingEntity extends Entity {
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) {
2021-06-11 14:02:28 +02:00
+ // Paper start - add knockbacking entity parameter
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) {
2021-06-11 14:02:28 +02:00
+ // Paper end - add knockbacking entity parameter
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;
2022-12-07 19:52:24 +01:00
@@ -1768,6 +1773,15 @@ public abstract class LivingEntity extends Entity {
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
2021-06-12 21:30:37 +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);
2021-06-11 14:02:28 +02:00
+ // Paper start - call EntityKnockbackByEntityEvent
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
}
}
diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java
2022-12-07 19:52:24 +01:00
index 458a90529959d3ceae424236461cdeb4c588eedb..6f728231a7b326e605d6ddb8e4cd6f0f0aec820b 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
2022-12-07 19:52:24 +01:00
@@ -1605,7 +1605,7 @@ public abstract class Mob extends LivingEntity {
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
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
2022-12-08 05:24:59 +01:00
index 61328cde67c994c4ec0629b5869a878eda7c6cab..9b64a465be77bcc07e420c84f19fe75816e0ead1 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
2022-06-07 23:45:11 +02:00
@@ -78,7 +78,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;
float h = livingEntity.isDamageSourceBlocked(DamageSource.mobAttack(entity)) ? 0.5F : 1.0F;
- livingEntity.knockback((double)(h * g) * this.getKnockbackForce.applyAsDouble(entity), this.ramDirection.x(), this.ramDirection.z());
2022-12-08 05:24:59 +01:00
+ livingEntity.knockback((double)(h * g) * this.getKnockbackForce.applyAsDouble(entity), this.ramDirection.x(), this.ramDirection.z(), entity); // Paper
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 c8c5a46f526b3f8823b3c2047463c2e67f12c92e..27aea5c5e284767a2a9b7de1b7912c3d50ff3c3c 100644
--- 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
@@ -69,7 +69,7 @@ public class SonicBoom extends Behavior<Warden> {
target.hurt(DamageSource.sonicBoom(entity), 10.0F);
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
});
}
}
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 a889be9dd2a94b531a227ff69a5e761e103067be..7bf3ad1ccef09b697655dc949abab9ab006a95a9 100644
--- a/src/main/java/net/minecraft/world/entity/boss/enderdragon/EnderDragon.java
+++ b/src/main/java/net/minecraft/world/entity/boss/enderdragon/EnderDragon.java
@@ -432,7 +432,7 @@ public class EnderDragon extends Mob implements Enemy {
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
if (!this.phaseManager.getCurrentPhase().isSitting() && ((LivingEntity) entity).getLastHurtByMobTimestamp() < entity.tickCount - 2) {
entity.hurt(DamageSource.mobAttack(this), 5.0F);
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 8517fd004727b083545082a5de26b11cb2a93623..01dfe3e29ea55b9e839a4db027fdd6a1dbb5ca23 100644
--- a/src/main/java/net/minecraft/world/entity/monster/Ravager.java
+++ b/src/main/java/net/minecraft/world/entity/monster/Ravager.java
@@ -275,7 +275,7 @@ public class Ravager extends Raider {
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
}
@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 127948e7c8620de1f4fabce0d654fbb502510156..191f7afcb23b5ee58df9dd6bd8c78ac993630034 100644
--- a/src/main/java/net/minecraft/world/entity/monster/hoglin/HoglinBase.java
+++ b/src/main/java/net/minecraft/world/entity/monster/hoglin/HoglinBase.java
@@ -41,7 +41,7 @@ public interface HoglinBase {
double j = f * (double)(attacker.level.random.nextFloat() * 0.5F + 0.2F);
Vec3 vec3 = (new Vec3(g, 0.0D, h)).normalize().scale(j).yRot(i);
double k = f * (double)attacker.level.random.nextFloat() * 0.5D;
- target.push(vec3.x, k, vec3.z);
+ target.push(vec3.x, k, vec3.z, attacker); // Paper
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 2010e93da4e56a6a22a8e6f8c42a799eeba62acc..67da749cef5241d6cbe02a494e43ae8fb24bb56d 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
2022-12-23 20:59:11 +01:00
@@ -1278,9 +1278,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
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
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));
2022-12-07 19:52:24 +01:00
@@ -1302,7 +1302,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
if (entityliving.hurt(DamageSource.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
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 d4b8364fd860ee2cc632d8c752435b9b311c7ece..915c15faa510f4bdd3a96d8ba83280f08b12dec6 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
@@ -401,7 +401,7 @@ public abstract class AbstractArrow extends Projectile {
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
}
}