aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-Server-Patches/0273-Implement-EntityKnockbackByEntityEvent.patch
blob: b7f5305ad519eec8e0f03ffa9d650a5b12818d24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
From fe425522ea63caa0bf747aeff4b7d92b27dd1506 Mon Sep 17 00:00:00 2001
From: Brokkonaut <hannos17@gmx.de>
Date: Mon, 18 Jun 2018 15:46:23 +0200
Subject: [PATCH] Implement EntityKnockbackByEntityEvent

This event is called when an entity receives knockback by another entity.

diff --git a/src/main/java/net/minecraft/server/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java
index deb50b84f..164e4b412 100644
--- a/src/main/java/net/minecraft/server/EntityLiving.java
+++ b/src/main/java/net/minecraft/server/EntityLiving.java
@@ -1251,6 +1251,12 @@ public abstract class EntityLiving extends Entity {
             this.impulse = true;
             float f1 = MathHelper.sqrt(d0 * d0 + d1 * d1);
 
+            // Paper start - preserve old velocity
+            double oldMotX = this.motX;
+            double oldMotY = this.motY;
+            double oldMotZ = this.motZ;
+            // Paper end
+
             this.motX /= 2.0D;
             this.motZ /= 2.0D;
             this.motX -= d0 / (double) f1 * (double) f;
@@ -1263,6 +1269,18 @@ public abstract class EntityLiving extends Entity {
                 }
             }
 
+            // Paper start - call EntityKnockbackByEntityEvent
+            org.bukkit.util.Vector delta = new org.bukkit.util.Vector(this.motX - oldMotX, this.motY - oldMotY, this.motZ - oldMotZ);
+            // Restore old velocity to be able to access it in the event
+            this.motX = oldMotX;
+            this.motY = oldMotY;
+            this.motZ = oldMotZ;
+            if (entity == null || new com.destroystokyo.paper.event.entity.EntityKnockbackByEntityEvent((LivingEntity) getBukkitEntity(), entity.getBukkitEntity(), f, delta).callEvent()) {
+                this.motX += delta.getX();
+                this.motY += delta.getY();
+                this.motZ += delta.getZ();
+            }
+            // Paper end
         }
     }
 
-- 
2.21.0