diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 165343a58..daa095d02 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -827,21 +827,25 @@ abstract class Entity{ } protected function updateMovement(bool $teleport = false) : void{ - //TODO: hack for client-side AI interference: prevent client sided movement when motion is 0 - $this->setImmobile($this->motion->x == 0 and $this->motion->y == 0 and $this->motion->z == 0); - $diffPosition = $this->location->distanceSquared($this->lastLocation); $diffRotation = ($this->location->yaw - $this->lastLocation->yaw) ** 2 + ($this->location->pitch - $this->lastLocation->pitch) ** 2; $diffMotion = $this->motion->subtract($this->lastMotion)->lengthSquared(); - if($teleport or $diffPosition > 0.0001 or $diffRotation > 1.0){ + $still = $this->motion->lengthSquared() == 0.0; + $wasStill = $this->lastMotion->lengthSquared() == 0.0; + if($wasStill !== $still){ + //TODO: hack for client-side AI interference: prevent client sided movement when motion is 0 + $this->setImmobile($still); + } + + if($teleport or $diffPosition > 0.0001 or $diffRotation > 1.0 or (!$wasStill and $still)){ $this->lastLocation = $this->location->asLocation(); $this->broadcastMovement($teleport); } - if($diffMotion > 0.0025 or ($diffMotion > 0.0001 and $this->motion->lengthSquared() <= 0.0001)){ //0.05 ** 2 + if($diffMotion > 0.0025 or $wasStill !== $still){ //0.05 ** 2 $this->lastMotion = clone $this->motion; $this->broadcastMotion();