From 426728342fe650c1da78eba475e106639e7ccce1 Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Mon, 30 Oct 2023 07:48:10 +0300 Subject: [PATCH] more tweaks --- src/Player.php | 28 ++++++++++++++++++---------- src/entity/Entity.php | 8 ++++---- src/entity/ai/MobController.php | 1 + 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/Player.php b/src/Player.php index eddb1ea1..109a019e 100755 --- a/src/Player.php +++ b/src/Player.php @@ -1152,9 +1152,10 @@ class Player{ } public function addEntityMovementUpdateToQueue(Entity $e){ $len = 0; - $packets = 1; + $packets = 0; $motionSent = false; $moveSent = false; + $headSent = false; if($e->speedX != 0 || $e->speedY != 0 || $e->speedZ != 0){ $motion = new SetEntityMotionPacket(); $motion->eid = $e->eid; @@ -1179,15 +1180,20 @@ class Player{ ++$packets; $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; if(($this->entityMovementQueueLength + $len) >= $MTU){ + console("force send"); $this->sendEntityMovementUpdateQueue(); } if($motionSent){ @@ -1200,9 +1206,11 @@ class Player{ $move->reliability = 2; $this->entityMovementQueue->data[] = $move; } - $headyaw->messageIndex = $this->counter[3]++; - $headyaw->reliability = 2; - $this->entityMovementQueue->data[] = $headyaw; + if($headSent){ + $headyaw->messageIndex = $this->counter[3]++; + $headyaw->reliability = 2; + $this->entityMovementQueue->data[] = $headyaw; + } $this->entityMovementQueueLength += 6*$packets + $len; } diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 481e4f48..dd1b1cb9 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -621,10 +621,10 @@ class Entity extends Position $this->onGround = $support; - if($this->hasGravity){ - $this->speedY -= $this->inWater ? 0.02 : ($this->gravity); // TODO: replace with $gravity + if($this->hasGravity){ //TODO causes setEntityMotion packet flood, fix + $this->speedY -= $this->inWater ? 0.02 : ($this->gravity); $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->speedY = 0; // $this->speedZ = 0; @@ -1238,7 +1238,7 @@ class Entity extends Position $this->last[3] = $this->yaw; $this->last[4] = $this->pitch; $this->last[5] = microtime(true); - $this->lastHeadYaw = $this->headYaw; + //$this->lastHeadYaw = $this->headYaw; } public function getPosition($round = false) diff --git a/src/entity/ai/MobController.php b/src/entity/ai/MobController.php index 78d92078..728a4310 100644 --- a/src/entity/ai/MobController.php +++ b/src/entity/ai/MobController.php @@ -106,6 +106,7 @@ class MobController } public function rotateTick(){ //TODO handle more rotation + $this->entity->lastHeadYaw = $this->entity->headYaw; $w180 = Utils::wrapAngleTo180($this->finalHeadYaw - $this->entity->headYaw); $w180min = min(abs($w180), 20)*Utils::getSign($w180); $this->entity->headYaw = Utils::wrapAngleTo360($this->entity->headYaw + $w180min);