mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-21 12:09:43 +00:00
mob fixes related to time and headYaw
This commit is contained in:
parent
0a36a67f78
commit
21d0530d39
9 changed files with 35 additions and 27 deletions
|
|
@ -197,10 +197,13 @@ class Entity extends Position
|
|||
$this->speedY += $vY;
|
||||
$this->speedZ += $vZ;
|
||||
}
|
||||
|
||||
public function isMovingHorizontally()
|
||||
{
|
||||
return ($this->speedX > 0.01 || $this->speedX < - 0.01) || ($this->speedZ > 0.01 || $this->speedZ < - 0.01);
|
||||
}
|
||||
public function isMoving()
|
||||
{
|
||||
return ($this->speedX > 0.01 || $this->speedX < - 0.01) || ($this->speedY > 0.007 || $this->speedY < - 0.007) || ($this->speedZ > 0.01 || $this->speedZ < - 0.01);
|
||||
return $this->isMovingHorizontally() || ($this->speedY > 0.007 || $this->speedY < - 0.007);
|
||||
}
|
||||
|
||||
public function setVelocity($vX, $vY = 0, $vZ = 0)
|
||||
|
|
@ -756,14 +759,6 @@ class Entity extends Position
|
|||
$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;
|
||||
}
|
||||
|
|
@ -774,13 +769,13 @@ class Entity extends Position
|
|||
return false;
|
||||
}
|
||||
$now = microtime(true);
|
||||
if($this->isStatic === false and ($this->last[0] != $this->x or $this->last[1] != $this->y or $this->last[2] != $this->z or $this->last[3] != $this->yaw or $this->last[4] != $this->pitch)){
|
||||
if($this->isStatic === false and ($this->lastX != $this->x or $this->lastY != $this->y or $this->lastZ != $this->z or $this->lastYaw != $this->yaw or $this->lastPitch != $this->pitch or $this->lastHeadYaw != $this->headYaw)){
|
||||
if($this->class === ENTITY_PLAYER or ($this->last[5] + 8) < $now){
|
||||
if($this->server->api->handle("entity.move", $this) === false){
|
||||
if($this->class === ENTITY_PLAYER){
|
||||
$this->player->teleport(new Vector3($this->last[0], $this->last[1], $this->last[2]), $this->last[3], $this->last[4]);
|
||||
} else{
|
||||
$this->setPosition($this->last[0], $this->last[1], $this->last[2], $this->last[3], $this->last[4]);
|
||||
//TODO fix $this->setPosition($this->last[0], $this->last[1], $this->last[2], $this->last[3], $this->last[4]);
|
||||
}
|
||||
} else{
|
||||
$this->updateLast();
|
||||
|
|
@ -797,6 +792,7 @@ class Entity extends Position
|
|||
$pk->bodyYaw = $this->yaw;
|
||||
$this->server->api->player->broadcastPacket($players, $pk);
|
||||
} else{
|
||||
|
||||
$pk = new MoveEntityPacket_PosRot();
|
||||
$pk->eid = $this->eid;
|
||||
$pk->x = $this->x;
|
||||
|
|
@ -814,6 +810,8 @@ class Entity extends Position
|
|||
}
|
||||
$this->updateLast();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
$this->lastUpdate = $now;
|
||||
|
|
|
|||
|
|
@ -35,14 +35,17 @@ class MobController
|
|||
|
||||
$tan = $dz == 0 ? ($dx < 0 ? 180 : 0) : (90 - rad2deg(atan($dx / $dz)));
|
||||
$thetaOffset = $dz < 0 ? 90 : 270;
|
||||
$this->entity->yaw = $this->entity->headYaw = ($thetaOffset + $tan);
|
||||
$calcYaw = ($thetaOffset + $tan);
|
||||
$this->entity->yaw = $this->entity->headYaw = $calcYaw;
|
||||
}
|
||||
|
||||
public function lookOffset($x, $y, $z, $pitch = true){
|
||||
$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->headYaw = $calcYaw;
|
||||
|
||||
$this->entity->yaw = $this->entity->headYaw = $calcYaw;
|
||||
|
||||
if($pitch){
|
||||
$diff = sqrt($x * $x + $z * $z);
|
||||
$calcPitch = rad2deg(atan($y / $diff));
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ class TaskLookAtPlayer extends TaskBase{
|
|||
public $target = false;
|
||||
private $state, $yaw, $pitch;
|
||||
public function canBeExecuted(EntityAI $ai){
|
||||
return Utils::randomFloat() < 0.02 && !$ai->entity->isMoving() && !$ai->isStarted("TaskLookAround") && !$ai->isStarted("TaskTempt") && !$ai->entity->hasPath();
|
||||
return Utils::randomFloat() < 0.02 && !$ai->entity->isMovingHorizontally() && !$ai->isStarted("TaskLookAround") && !$ai->isStarted("TaskTempt") && !$ai->entity->hasPath();
|
||||
}
|
||||
|
||||
protected function findTarget($e, $r){
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ class Skeleton extends Monster{
|
|||
}
|
||||
|
||||
public function updateBurning(){
|
||||
if($this->fire > 0 or $this->server->api->time->getPhase($this->level->getTime()) != "day"){
|
||||
if($this->fire > 0 or !$this->level->isDay()){
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ class Zombie extends Monster{
|
|||
}
|
||||
|
||||
public function updateBurning(){
|
||||
if($this->fire > 0 or $this->server->api->time->getPhase($this->level->getTime()) != "day"){
|
||||
if($this->fire > 0 or !$this->level->isDay()){
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue