mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-22 12:39:43 +00:00
headYaw was added
This commit is contained in:
parent
cf13bd4c43
commit
685efef843
3 changed files with 20 additions and 20 deletions
|
|
@ -287,17 +287,7 @@ class EntityAPI{
|
||||||
|
|
||||||
public function getAll($level = null){
|
public function getAll($level = null){
|
||||||
if($level instanceof Level){
|
if($level instanceof Level){
|
||||||
$entities = [];
|
return $level->entityList;
|
||||||
$l = $this->server->query("SELECT EID FROM entities WHERE level = '" . $level->getName() . "';");
|
|
||||||
if($l !== false and $l !== true){
|
|
||||||
while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){
|
|
||||||
$e = $this->get($e["EID"]);
|
|
||||||
if($e instanceof Entity){
|
|
||||||
$entities[$e->eid] = $e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $entities;
|
|
||||||
}
|
}
|
||||||
return $this->entities;
|
return $this->entities;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,9 +31,9 @@ class Entity extends Position
|
||||||
public $speedY;
|
public $speedY;
|
||||||
public $speedZ;
|
public $speedZ;
|
||||||
public $speed;
|
public $speed;
|
||||||
public $lastX = 0, $lastY = 0, $lastZ = 0, $lastYaw = 0, $lastPitch = 0, $lastTime = 0;
|
public $lastX = 0, $lastY = 0, $lastZ = 0, $lastYaw = 0, $lastPitch = 0, $lastTime = 0, $lastHeadYaw = 0;
|
||||||
public $last;
|
public $last;
|
||||||
public $yaw;
|
public $yaw, $headYaw;
|
||||||
public $pitch;
|
public $pitch;
|
||||||
public $dead;
|
public $dead;
|
||||||
public $data;
|
public $data;
|
||||||
|
|
@ -104,6 +104,7 @@ class Entity extends Position
|
||||||
$this->speedZ = isset($this->data["speedZ"]) ? (float) $this->data["speedZ"] : 0;
|
$this->speedZ = isset($this->data["speedZ"]) ? (float) $this->data["speedZ"] : 0;
|
||||||
$this->speed = 0;
|
$this->speed = 0;
|
||||||
$this->yaw = isset($this->data["yaw"]) ? (float) $this->data["yaw"] : 0;
|
$this->yaw = isset($this->data["yaw"]) ? (float) $this->data["yaw"] : 0;
|
||||||
|
$this->headYaw = isset($this->data["headYaw"]) ? $this->data["headYaw"] : $this->yaw;
|
||||||
$this->pitch = isset($this->data["pitch"]) ? (float) $this->data["pitch"] : 0;
|
$this->pitch = isset($this->data["pitch"]) ? (float) $this->data["pitch"] : 0;
|
||||||
$this->position = array(
|
$this->position = array(
|
||||||
"level" => $this->level,
|
"level" => $this->level,
|
||||||
|
|
@ -535,7 +536,7 @@ class Entity extends Position
|
||||||
if(Utils::in_range($this->speedY, - 0.001, 0.001)){
|
if(Utils::in_range($this->speedY, - 0.001, 0.001)){
|
||||||
$this->speedY = 0;
|
$this->speedY = 0;
|
||||||
}
|
}
|
||||||
if(($this->class === ENTITY_MOB || $this->class === ENTITY_ITEM) && ($this->speedX != 0 || $this->speedY != 0 || $this->speedZ != 0)){
|
if(($this->class === ENTITY_MOB || $this->class === ENTITY_ITEM || ($this->class === ENTITY_OBJECT && $this->type === OBJECT_PRIMEDTNT)) && ($this->speedX != 0 || $this->speedY != 0 || $this->speedZ != 0)){
|
||||||
$blocks = $this->level->getCubes($this->boundingBox->getOffsetBoundingBox($this->speedX, $this->speedY, $this->speedZ));
|
$blocks = $this->level->getCubes($this->boundingBox->getOffsetBoundingBox($this->speedX, $this->speedY, $this->speedZ));
|
||||||
foreach($blocks as $b){
|
foreach($blocks as $b){
|
||||||
$this->speedX = $b->calculateXOffset($this->boundingBox, $this->speedX);
|
$this->speedX = $b->calculateXOffset($this->boundingBox, $this->speedX);
|
||||||
|
|
@ -695,7 +696,11 @@ class Entity extends Position
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else{
|
} else{
|
||||||
$this->updatePosition($this->x, $this->y, $this->z, $this->yaw, $this->pitch);
|
$this->updatePosition();
|
||||||
|
if($this->lastHeadYaw != $this->headYaw){
|
||||||
|
$this->sendHeadYaw();
|
||||||
|
}
|
||||||
|
$this->updateLast();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -978,6 +983,13 @@ class Entity extends Position
|
||||||
$this->updateAABB();
|
$this->updateAABB();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function sendHeadYaw(){
|
||||||
|
$pk = new RotateHeadPacket;
|
||||||
|
$pk->eid = $this->eid;
|
||||||
|
$pk->yaw = $this->headYaw;
|
||||||
|
$this->server->api->player->broadcastPacket($this->level->players, $pk);
|
||||||
|
}
|
||||||
|
|
||||||
public function setPosition(Vector3 $pos, $yaw = false, $pitch = false)
|
public function setPosition(Vector3 $pos, $yaw = false, $pitch = false)
|
||||||
{
|
{
|
||||||
if($pos instanceof Position and $pos->level instanceof Level and $this->level !== $pos->level){
|
if($pos instanceof Position and $pos->level instanceof Level and $this->level !== $pos->level){
|
||||||
|
|
@ -1121,6 +1133,7 @@ class Entity extends Position
|
||||||
$this->last[3] = $this->yaw;
|
$this->last[3] = $this->yaw;
|
||||||
$this->last[4] = $this->pitch;
|
$this->last[4] = $this->pitch;
|
||||||
$this->last[5] = microtime(true);
|
$this->last[5] = microtime(true);
|
||||||
|
$this->lastHeadYaw = $this->headYaw;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPosition($round = false)
|
public function getPosition($round = false)
|
||||||
|
|
|
||||||
|
|
@ -35,10 +35,7 @@ class TaskRandomWalk extends TaskBase
|
||||||
$ai->entity->moveEntityWithOffset(($this->x > 0 ? 1 : ($this->x < 0 ? -1 : 0)), 0, ($this->z > 0 ? 1 : ($this->z < 0 ? -1 : 0)));
|
$ai->entity->moveEntityWithOffset(($this->x > 0 ? 1 : ($this->x < 0 ? -1 : 0)), 0, ($this->z > 0 ? 1 : ($this->z < 0 ? -1 : 0)));
|
||||||
if($this->looking){
|
if($this->looking){
|
||||||
$this->testLook($ai, $ai->entity->speedX, $ai->entity->speedZ);
|
$this->testLook($ai, $ai->entity->speedX, $ai->entity->speedZ);
|
||||||
$pk = new RotateHeadPacket();
|
$ai->entity->headYaw = $ai->entity->yaw;
|
||||||
$pk->eid = $ai->entity->eid;
|
|
||||||
$pk->yaw = $ai->entity->yaw;
|
|
||||||
$ai->entity->server->api->player->broadcastPacket($ai->entity->level->players, $pk);
|
|
||||||
$this->looking = false;
|
$this->looking = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue