diff --git a/src/entity/Entity.php b/src/entity/Entity.php index c7288db27..e28cb59cd 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -1270,11 +1270,8 @@ abstract class Entity{ } if($vector->lengthSquared() > 0){ - $vector = $vector->normalize(); $d = 0.014; - $this->motion->x += $vector->x * $d; - $this->motion->y += $vector->y * $d; - $this->motion->z += $vector->z * $d; + $this->motion = $this->motion->addVector($vector->normalize()->multiply($d)); } } @@ -1392,9 +1389,7 @@ abstract class Entity{ * Adds the given values to the entity's motion vector. */ public function addMotion(float $x, float $y, float $z) : void{ - $this->motion->x += $x; - $this->motion->y += $y; - $this->motion->z += $z; + $this->motion = $this->motion->add($x, $y, $z); } public function isOnGround() : bool{ diff --git a/src/entity/object/ExperienceOrb.php b/src/entity/object/ExperienceOrb.php index 6594369b8..c928d4c16 100644 --- a/src/entity/object/ExperienceOrb.php +++ b/src/entity/object/ExperienceOrb.php @@ -195,11 +195,7 @@ class ExperienceOrb extends Entity{ $distance = $vector->lengthSquared(); if($distance < 1){ - $diff = $vector->normalize()->multiply(0.2 * (1 - sqrt($distance)) ** 2); - - $this->motion->x += $diff->x; - $this->motion->y += $diff->y; - $this->motion->z += $diff->z; + $this->motion = $this->motion->addVector($vector->normalize()->multiply(0.2 * (1 - sqrt($distance)) ** 2)); } if($currentTarget->getXpManager()->canPickupXp() and $this->boundingBox->intersectsWith($currentTarget->getBoundingBox())){ diff --git a/src/entity/projectile/Projectile.php b/src/entity/projectile/Projectile.php index f4aa9aa1b..4a3d8f95e 100644 --- a/src/entity/projectile/Projectile.php +++ b/src/entity/projectile/Projectile.php @@ -247,7 +247,7 @@ abstract class Projectile extends Entity{ } $this->isCollided = $this->onGround = true; - $this->motion->x = $this->motion->y = $this->motion->z = 0; + $this->motion = new Vector3(0, 0, 0); }else{ $this->isCollided = $this->onGround = false; $this->blockHit = null; diff --git a/src/player/Player.php b/src/player/Player.php index 074aac255..92f7821b2 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -1340,7 +1340,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, if($this->spawned){ $this->processMostRecentMovements(); - $this->motion->x = $this->motion->y = $this->motion->z = 0; //TODO: HACK! (Fixes player knockback being messed up) + $this->motion = new Vector3(0, 0, 0); //TODO: HACK! (Fixes player knockback being messed up) if($this->onGround){ $this->inAirTicks = 0; }else{