Merge commit 'd9bbab54f4608954a8ac0fffa88c2f32c07669f1'

This commit is contained in:
Dylan K. Taylor 2020-01-18 18:07:45 +00:00
commit 7762b73647

View File

@ -827,21 +827,25 @@ abstract class Entity{
} }
protected function updateMovement(bool $teleport = false) : void{ 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); $diffPosition = $this->location->distanceSquared($this->lastLocation);
$diffRotation = ($this->location->yaw - $this->lastLocation->yaw) ** 2 + ($this->location->pitch - $this->lastLocation->pitch) ** 2; $diffRotation = ($this->location->yaw - $this->lastLocation->yaw) ** 2 + ($this->location->pitch - $this->lastLocation->pitch) ** 2;
$diffMotion = $this->motion->subtract($this->lastMotion)->lengthSquared(); $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->lastLocation = $this->location->asLocation();
$this->broadcastMovement($teleport); $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->lastMotion = clone $this->motion;
$this->broadcastMotion(); $this->broadcastMotion();