This commit is contained in:
GameHerobrine 2022-12-31 21:59:40 +03:00
parent 0f72601891
commit 2573e4f90d
14 changed files with 65 additions and 57 deletions

View file

@ -780,6 +780,15 @@ class Entity extends Position
if($this->class !== ENTITY_PLAYER && $update){
$this->updateMovement();
}
if($this->headYaw != $this->lastHeadYaw) {
$this->lastHeadYaw = $this->headYaw;
$pk = new RotateHeadPacket();
$pk->eid = $this->eid;
$pk->yaw = $this->headYaw;
$this->server->api->player->broadcastPacket($this->level->players, $pk);
}
$this->needsUpdate = $hasUpdate;
$this->lastUpdate = $now;
}

View file

@ -31,7 +31,13 @@ abstract class Living extends Entity implements Damageable, Pathfindable{
$this->ai->updateTasks();
}
$this->pathFollower->followPath();
if($this->onGround){
/*if($this->path === null && $this->pathFinder instanceof ITileNavigator){ // mt_rand(0, 120) === 0){
$this->path = $this->pathFinder->navigate(new PathTileXYZ($this->x, $this->y, $this->z, $this->level), new PathTileXYZ($this->x + mt_rand(-10, 10), $this->y, $this->z + mt_rand(-10, 10), $this->level), 10);
}*/
$this->pathFollower->followPath();
}
parent::update();
}

View file

@ -21,10 +21,6 @@ class MobController
$oz = ($z > 0 ? 1 : ($z < 0 ? -1 : 0));
$this->entity->moveEntityWithOffset($ox, $oy, $oz);
$this->faceEntity($this->entity->add($ox, $oy, $oz));
$pk = new RotateHeadPacket(); //TODO headYaw auto update
$pk->eid = $this->entity->eid;
$pk->yaw = $this->entity->yaw;
$this->entity->server->api->player->broadcastPacket($this->entity->level->players, $pk);
return true;
}
@ -46,7 +42,7 @@ class MobController
$tan = $z == 0 ? ($x < 0 ? 180 : 0) : (90 - rad2deg(atan($x / $z))); /*arctan(infinity) = pi/2 = (90deg) - 90 = 0*/
$thetaOffset = $z <= 0 ? 90 : 270;
$calcYaw = $tan + $thetaOffset;
$this->entity->yaw = $calcYaw;
$this->entity->headYaw = $calcYaw;
if($pitch){
$diff = sqrt($x * $x + $z * $z);
$calcPitch = rad2deg(atan($y / $diff));

View file

@ -25,11 +25,7 @@ class TaskLookAround extends TaskBase
$this->selfCounter = 0;
}
$v = min(Utils::getSign($this->rotation) * 10, $this->rotation);
$ai->entity->yaw += $v;
$pk = new RotateHeadPacket(); //TODO headYaw auto update
$pk->eid = $ai->entity->eid;
$pk->yaw = $ai->entity->yaw;
$ai->entity->server->api->player->broadcastPacket($ai->entity->level->players, $pk);
$ai->entity->headYaw += $v;
$this->rotation -= $v;
}

View file

@ -47,10 +47,6 @@ class TaskLookAtPlayer extends TaskBase{
return;
}
$ai->mobController->lookOn($this->target);
$pk = new RotateHeadPacket(); //TODO headYaw auto update
$pk->eid = $ai->entity->eid;
$pk->yaw = $ai->entity->yaw;
$ai->entity->server->api->player->broadcastPacket($ai->entity->level->players, $pk);
$this->selfCounter--;
}

View file

@ -23,10 +23,6 @@ class TaskTempt extends TaskBase
}
//TODO following
$ai->mobController->lookOn($this->target);
$pk = new RotateHeadPacket(); //TODO headYaw auto update
$pk->eid = $ai->entity->eid;
$pk->yaw = $ai->entity->yaw;
$ai->entity->server->api->player->broadcastPacket($ai->entity->level->players, $pk);
}
public function canBeExecuted(EntityAI $ai)