From 58a1ccc3e79901eb989cf176c2aaeb66fd45dc9b Mon Sep 17 00:00:00 2001 From: luisc Date: Thu, 23 Sep 2021 03:02:58 -0500 Subject: [PATCH] Added new knockback function with x y and z knockback power parameters. --- .../java/noppes/npcs/scripted/ScriptEntity.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/noppes/npcs/scripted/ScriptEntity.java b/src/main/java/noppes/npcs/scripted/ScriptEntity.java index 2deeb9d8e..ccb7203cc 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptEntity.java +++ b/src/main/java/noppes/npcs/scripted/ScriptEntity.java @@ -461,6 +461,20 @@ public class ScriptEntity { entity.motionZ *= 0.6D; entity.attackEntityFrom(DamageSource.outOfWorld, 0.0001F); } + + /** + * @param xpower How strong the knockback is on the x axis + * @param ypower How strong the knockback is on the y axis + * @param zpower How strong the knockback is on the z axis + * @param direction The direction in which he flies back (0-360). Usually based on getRotation() + */ + public void knockback(int xpower, int ypower, int zpower, float direction){ + float v = direction * (float)Math.PI / 180.0F; + entity.addVelocity(-MathHelper.sin(v) * (float)xpower, ypower, MathHelper.cos(v) * (float)zpower); + entity.motionX *= 0.6D; + entity.motionZ *= 0.6D; + entity.attackEntityFrom(DamageSource.outOfWorld, 0.0001F); + } /** * @since 1.7.10c