From e803ca0e06299974f9010e1a610dc19c559f10ac Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 22 Jul 2021 14:27:20 +0100 Subject: [PATCH] Living: Limit vertical knockback to 0.4 by default this will break non-standard use cases with large forces, but they only have to stick a 'null' at the end of the parameter list. Since this function should be primarily used for vanilla knockback, it makes more sense to keep the default as vanilla, but allow people to change it if they want to. closes #4106 (this is close to #4106 anyway, but small enough that it was easier to recreate it than pull and modify it) closes #2707 --- src/entity/Living.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/entity/Living.php b/src/entity/Living.php index c21f6720a..afa3096d9 100644 --- a/src/entity/Living.php +++ b/src/entity/Living.php @@ -507,7 +507,7 @@ abstract class Living extends Entity{ $this->broadcastAnimation(new HurtAnimation($this)); } - public function knockBack(float $x, float $z, float $base = 0.4) : void{ + public function knockBack(float $x, float $z, float $base = 0.4, ?float $verticalLimit = 0.4) : void{ $f = sqrt($x * $x + $z * $z); if($f <= 0){ return; @@ -522,8 +522,9 @@ abstract class Living extends Entity{ $motionY += $base; $motionZ += $z * $f * $base; - if($motionY > $base){ - $motionY = $base; + $verticalLimit ??= $base; + if($motionY > $verticalLimit){ + $motionY = $verticalLimit; } $this->setMotion(new Vector3($motionX, $motionY, $motionZ));