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
This commit is contained in:
Dylan K. Taylor 2021-07-22 14:27:20 +01:00
parent 3466fbe3e3
commit e803ca0e06
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -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));