Avoid direct mutations of Entity->location

This commit is contained in:
Dylan K. Taylor 2022-01-20 21:49:14 +00:00
parent 345ac75aac
commit fc53f3721a
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
3 changed files with 15 additions and 8 deletions

View File

@ -808,14 +808,17 @@ abstract class Living extends Entity{
public function lookAt(Vector3 $target) : void{
$horizontal = sqrt(($target->x - $this->location->x) ** 2 + ($target->z - $this->location->z) ** 2);
$vertical = $target->y - ($this->location->y + $this->getEyeHeight());
$this->location->pitch = -atan2($vertical, $horizontal) / M_PI * 180; //negative is up, positive is down
$pitch = -atan2($vertical, $horizontal) / M_PI * 180; //negative is up, positive is down
$xDist = $target->x - $this->location->x;
$zDist = $target->z - $this->location->z;
$this->location->yaw = atan2($zDist, $xDist) / M_PI * 180 - 90;
if($this->location->yaw < 0){
$this->location->yaw += 360.0;
$yaw = atan2($zDist, $xDist) / M_PI * 180 - 90;
if($yaw < 0){
$yaw += 360.0;
}
$this->setRotation($yaw, $pitch);
}
protected function sendSpawnPacket(Player $player) : void{

View File

@ -113,8 +113,10 @@ class Squid extends WaterAnimal{
}
$f = sqrt(($this->motion->x ** 2) + ($this->motion->z ** 2));
$this->location->yaw = (-atan2($this->motion->x, $this->motion->z) * 180 / M_PI);
$this->location->pitch = (-atan2($f, $this->motion->y) * 180 / M_PI);
$this->setRotation(
-atan2($this->motion->x, $this->motion->z) * 180 / M_PI,
-atan2($f, $this->motion->y) * 180 / M_PI
);
}
return $hasUpdate;

View File

@ -253,8 +253,10 @@ abstract class Projectile extends Entity{
//recompute angles...
$f = sqrt(($this->motion->x ** 2) + ($this->motion->z ** 2));
$this->location->yaw = (atan2($this->motion->x, $this->motion->z) * 180 / M_PI);
$this->location->pitch = (atan2($this->motion->y, $f) * 180 / M_PI);
$this->setRotation(
atan2($this->motion->x, $this->motion->z) * 180 / M_PI,
atan2($this->motion->y, $f) * 180 / M_PI
);
}
$this->getWorld()->onEntityMoved($this);