2020-05-06 11:48:49 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2019-04-30 03:20:24 +02:00
|
|
|
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.
|
|
|
|
|
2020-06-26 08:29:44 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/EntityHuman.java b/src/main/java/net/minecraft/server/EntityHuman.java
|
2020-12-21 08:56:22 +01:00
|
|
|
index 88a23d3e8f251304f22818b8c65590c39c42cd80..e59d54755542b9053e64618495a3fa79cb084915 100644
|
2020-06-26 08:29:44 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/EntityHuman.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/EntityHuman.java
|
2020-08-25 04:22:08 +02:00
|
|
|
@@ -1080,7 +1080,7 @@ public abstract class EntityHuman extends EntityLiving {
|
2020-06-26 08:29:44 +02:00
|
|
|
if (flag5) {
|
|
|
|
if (i > 0) {
|
|
|
|
if (entity instanceof EntityLiving) {
|
2020-06-26 23:33:49 +02:00
|
|
|
- ((EntityLiving) entity).a((float) i * 0.5F, (double) MathHelper.sin(this.yaw * 0.017453292F), (double) (-MathHelper.cos(this.yaw * 0.017453292F)));
|
|
|
|
+ ((EntityLiving) entity).doKnockback((float) i * 0.5F, (double) MathHelper.sin(this.yaw * 0.017453292F), (double) (-MathHelper.cos(this.yaw * 0.017453292F)), this); // Paper
|
2020-06-26 08:29:44 +02:00
|
|
|
} else {
|
2020-08-25 04:22:08 +02:00
|
|
|
entity.i((double) (-MathHelper.sin(this.yaw * 0.017453292F) * (float) i * 0.5F), 0.1D, (double) (MathHelper.cos(this.yaw * 0.017453292F) * (float) i * 0.5F));
|
2020-06-26 08:29:44 +02:00
|
|
|
}
|
2020-08-25 04:22:08 +02:00
|
|
|
@@ -1104,7 +1104,7 @@ public abstract class EntityHuman extends EntityLiving {
|
2020-06-26 08:29:44 +02:00
|
|
|
if (entityliving != this && entityliving != entity && !this.r(entityliving) && (!(entityliving instanceof EntityArmorStand) || !((EntityArmorStand) entityliving).isMarker()) && this.h((Entity) entityliving) < 9.0D) {
|
|
|
|
// CraftBukkit start - Only apply knockback if the damage hits
|
|
|
|
if (entityliving.damageEntity(DamageSource.playerAttack(this).sweep(), f4)) {
|
2020-06-26 23:33:49 +02:00
|
|
|
- entityliving.a(0.4F, (double) MathHelper.sin(this.yaw * 0.017453292F), (double) (-MathHelper.cos(this.yaw * 0.017453292F)));
|
2020-08-25 04:22:08 +02:00
|
|
|
+ entityliving.doKnockback(0.4F, (double) MathHelper.sin(this.yaw * 0.017453292F), (double) (-MathHelper.cos(this.yaw * 0.017453292F)), this); // Paper
|
2020-06-26 08:29:44 +02:00
|
|
|
}
|
|
|
|
// CraftBukkit end
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/EntityInsentient.java b/src/main/java/net/minecraft/server/EntityInsentient.java
|
2020-11-18 04:45:18 +01:00
|
|
|
index 1b0c4234cf579b35f404c129c2c6d3266b670b09..38bf49da2cc6b2f7068462ea8b57cf3a76ae1779 100644
|
2020-06-26 08:29:44 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/EntityInsentient.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/EntityInsentient.java
|
2020-08-27 15:37:37 +02:00
|
|
|
@@ -1500,7 +1500,7 @@ public abstract class EntityInsentient extends EntityLiving {
|
2020-06-26 08:29:44 +02:00
|
|
|
|
|
|
|
if (flag) {
|
|
|
|
if (f1 > 0.0F && entity instanceof EntityLiving) {
|
2020-06-26 23:33:49 +02:00
|
|
|
- ((EntityLiving) entity).a(f1 * 0.5F, (double) MathHelper.sin(this.yaw * 0.017453292F), (double) (-MathHelper.cos(this.yaw * 0.017453292F)));
|
2020-08-25 04:22:08 +02:00
|
|
|
+ ((EntityLiving) entity).doKnockback(f1 * 0.5F, (double) MathHelper.sin(this.yaw * 0.017453292F), (double) (-MathHelper.cos(this.yaw * 0.017453292F)), this); // Paper
|
2020-06-26 08:29:44 +02:00
|
|
|
this.setMot(this.getMot().d(0.6D, 1.0D, 0.6D));
|
|
|
|
}
|
|
|
|
|
2019-04-30 03:20:24 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java
|
2020-12-21 08:56:22 +01:00
|
|
|
index 134da62b90b7a167cd580680a986dd470a3b9aad..991839c39206ec984c442776693afdf50f90b409 100644
|
2019-04-30 03:20:24 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/EntityLiving.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/EntityLiving.java
|
2020-12-21 08:56:22 +01:00
|
|
|
@@ -1246,7 +1246,7 @@ public abstract class EntityLiving extends Entity {
|
2020-06-26 08:29:44 +02:00
|
|
|
}
|
|
|
|
|
2020-08-25 04:22:08 +02:00
|
|
|
this.ap = (float) (MathHelper.d(d1, d0) * 57.2957763671875D - (double) this.yaw);
|
2020-06-26 23:33:49 +02:00
|
|
|
- this.a(0.4F, d0, d1);
|
|
|
|
+ this.doKnockback(0.4F, d0, d1, entity1); // Paper
|
2020-06-26 08:29:44 +02:00
|
|
|
} else {
|
2020-08-25 04:22:08 +02:00
|
|
|
this.ap = (float) ((int) (Math.random() * 2.0D) * 180);
|
2020-06-26 08:29:44 +02:00
|
|
|
}
|
2020-12-21 08:56:22 +01:00
|
|
|
@@ -1294,7 +1294,7 @@ public abstract class EntityLiving extends Entity {
|
2020-06-26 08:29:44 +02:00
|
|
|
}
|
|
|
|
|
2020-08-25 04:22:08 +02:00
|
|
|
protected void e(EntityLiving entityliving) {
|
2020-06-26 23:33:49 +02:00
|
|
|
- entityliving.a(0.5F, entityliving.locX() - this.locX(), entityliving.locZ() - this.locZ());
|
2020-08-25 04:22:08 +02:00
|
|
|
+ entityliving.doKnockback(0.5F, entityliving.locX() - this.locX(), entityliving.locZ() - this.locZ(), this); // Paper
|
2020-06-26 08:29:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private boolean f(DamageSource damagesource) {
|
2020-12-21 08:56:22 +01:00
|
|
|
@@ -1530,6 +1530,11 @@ public abstract class EntityLiving extends Entity {
|
2020-06-26 23:33:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void a(float f, double d0, double d1) {
|
|
|
|
+ // Paper start - add knockbacking entity parameter
|
|
|
|
+ this.doKnockback(f, d0, d1, null);
|
|
|
|
+ }
|
|
|
|
+ public void doKnockback(float f, double d0, double d1, Entity knockingBackEntity) {
|
|
|
|
+ // Paper end - add knockbacking entity parameter
|
|
|
|
f = (float) ((double) f * (1.0D - this.b(GenericAttributes.KNOCKBACK_RESISTANCE)));
|
|
|
|
if (f > 0.0F) {
|
|
|
|
this.impulse = true;
|
2020-12-21 08:56:22 +01:00
|
|
|
@@ -1537,6 +1542,16 @@ public abstract class EntityLiving extends Entity {
|
2019-04-30 03:20:24 +02:00
|
|
|
Vec3D vec3d1 = (new Vec3D(d0, 0.0D, d1)).d().a((double) f);
|
|
|
|
|
|
|
|
this.setMot(vec3d.x / 2.0D - vec3d1.x, this.onGround ? Math.min(0.4D, vec3d.y / 2.0D + (double) f) : vec3d.y, vec3d.z / 2.0D - vec3d1.z);
|
|
|
|
+
|
|
|
|
+ // Paper start - call EntityKnockbackByEntityEvent
|
|
|
|
+ Vec3D currentMot = this.getMot();
|
|
|
|
+ org.bukkit.util.Vector delta = new org.bukkit.util.Vector(currentMot.x - vec3d.x, currentMot.y - vec3d.y, currentMot.z - vec3d.z);
|
|
|
|
+ // Restore old velocity to be able to access it in the event
|
|
|
|
+ this.setMot(vec3d);
|
2020-06-26 08:29:44 +02:00
|
|
|
+ if (knockingBackEntity == null || new com.destroystokyo.paper.event.entity.EntityKnockbackByEntityEvent((LivingEntity) getBukkitEntity(), knockingBackEntity.getBukkitEntity(), f, delta).callEvent()) {
|
2019-04-30 03:20:24 +02:00
|
|
|
+ this.setMot(vec3d.x + delta.getX(), vec3d.y + delta.getY(), vec3d.z + delta.getZ());
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|