From 272b76d24c5af4e67759b59269e079608f58d6e1 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 24 Jun 2018 13:43:52 +0100 Subject: [PATCH] fix Punch mess --- src/pocketmine/entity/projectile/Arrow.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/pocketmine/entity/projectile/Arrow.php b/src/pocketmine/entity/projectile/Arrow.php index 3db4e26a5..71d5f5c07 100644 --- a/src/pocketmine/entity/projectile/Arrow.php +++ b/src/pocketmine/entity/projectile/Arrow.php @@ -138,10 +138,11 @@ class Arrow extends Projectile{ protected function onHitEntity(Entity $entityHit, RayTraceResult $hitResult) : void{ parent::onHitEntity($entityHit, $hitResult); if($this->punchKnockback > 0){ - $mot = $entityHit->getMotion(); - $multiplier = $this->punchKnockback * 0.6 / $mot->length(); - - $entityHit->setMotion($mot->add($mot->x * $multiplier, 0.1, $mot->z * $multiplier)); + $horizontalSpeed = sqrt($this->motion->x ** 2 + $this->motion->z ** 2); + if($horizontalSpeed > 0){ + $multiplier = $this->punchKnockback * 0.6 / $horizontalSpeed; + $entityHit->setMotion($entityHit->getMotion()->add($this->motion->x * $multiplier, 0.1, $this->motion->z * $multiplier)); + } } }