more tweaks

This commit is contained in:
GameHerobrine 2023-10-30 07:48:10 +03:00
parent 6c08b74394
commit 426728342f
3 changed files with 23 additions and 14 deletions

View file

@ -1152,9 +1152,10 @@ class Player{
} }
public function addEntityMovementUpdateToQueue(Entity $e){ public function addEntityMovementUpdateToQueue(Entity $e){
$len = 0; $len = 0;
$packets = 1; $packets = 0;
$motionSent = false; $motionSent = false;
$moveSent = false; $moveSent = false;
$headSent = false;
if($e->speedX != 0 || $e->speedY != 0 || $e->speedZ != 0){ if($e->speedX != 0 || $e->speedY != 0 || $e->speedZ != 0){
$motion = new SetEntityMotionPacket(); $motion = new SetEntityMotionPacket();
$motion->eid = $e->eid; $motion->eid = $e->eid;
@ -1179,15 +1180,20 @@ class Player{
++$packets; ++$packets;
$moveSent = true; $moveSent = true;
} }
if($e->headYaw != $e->lastHeadYaw){
$headyaw = new RotateHeadPacket();
$headyaw->eid = $e->eid;
$headyaw->yaw = $e->headYaw;
$headyaw->encode();
$len += strlen($headyaw->buffer) + 1;
++$packets;
$headSent = true;
}
if($packets <= 0) return;
$headyaw = new RotateHeadPacket();
$headyaw->eid = $e->eid;
$headyaw->yaw = $e->headYaw;
$headyaw->encode();
$len = strlen($headyaw->buffer) + 1;
$MTU = $this->MTU - 24; $MTU = $this->MTU - 24;
if(($this->entityMovementQueueLength + $len) >= $MTU){ if(($this->entityMovementQueueLength + $len) >= $MTU){
console("force send");
$this->sendEntityMovementUpdateQueue(); $this->sendEntityMovementUpdateQueue();
} }
if($motionSent){ if($motionSent){
@ -1200,9 +1206,11 @@ class Player{
$move->reliability = 2; $move->reliability = 2;
$this->entityMovementQueue->data[] = $move; $this->entityMovementQueue->data[] = $move;
} }
$headyaw->messageIndex = $this->counter[3]++; if($headSent){
$headyaw->reliability = 2; $headyaw->messageIndex = $this->counter[3]++;
$this->entityMovementQueue->data[] = $headyaw; $headyaw->reliability = 2;
$this->entityMovementQueue->data[] = $headyaw;
}
$this->entityMovementQueueLength += 6*$packets + $len; $this->entityMovementQueueLength += 6*$packets + $len;
} }

View file

@ -621,10 +621,10 @@ class Entity extends Position
$this->onGround = $support; $this->onGround = $support;
if($this->hasGravity){ if($this->hasGravity){ //TODO causes setEntityMotion packet flood, fix
$this->speedY -= $this->inWater ? 0.02 : ($this->gravity); // TODO: replace with $gravity $this->speedY -= $this->inWater ? 0.02 : ($this->gravity);
$update = true; $update = true;
} elseif($this->lastX != $this->x || $this->lastZ != $this->z || $this->lastY != $this->z){ }elseif($this->lastX != $this->x || $this->lastZ != $this->z || $this->lastY != $this->z){
// $this->speedX = 0; // $this->speedX = 0;
// $this->speedY = 0; // $this->speedY = 0;
// $this->speedZ = 0; // $this->speedZ = 0;
@ -1238,7 +1238,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; //$this->lastHeadYaw = $this->headYaw;
} }
public function getPosition($round = false) public function getPosition($round = false)

View file

@ -106,6 +106,7 @@ class MobController
} }
public function rotateTick(){ //TODO handle more rotation public function rotateTick(){ //TODO handle more rotation
$this->entity->lastHeadYaw = $this->entity->headYaw;
$w180 = Utils::wrapAngleTo180($this->finalHeadYaw - $this->entity->headYaw); $w180 = Utils::wrapAngleTo180($this->finalHeadYaw - $this->entity->headYaw);
$w180min = min(abs($w180), 20)*Utils::getSign($w180); $w180min = min(abs($w180), 20)*Utils::getSign($w180);
$this->entity->headYaw = Utils::wrapAngleTo360($this->entity->headYaw + $w180min); $this->entity->headYaw = Utils::wrapAngleTo360($this->entity->headYaw + $w180min);