From 4c072e91cd34bd83cf25d20971e909e325776781 Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Sat, 3 Jan 2026 15:55:22 +0300 Subject: [PATCH] fixed player posiiton on bed, hopefully fixed players not receiving packets sometimes --- src/Player.php | 16 +++++++++++----- src/entity/Entity.php | 6 ++++-- src/material/block/misc/BedBlock.php | 2 ++ src/world/Explosion.php | 4 ++-- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/Player.php b/src/Player.php index 7758c880..4e53a623 100755 --- a/src/Player.php +++ b/src/Player.php @@ -274,9 +274,10 @@ class Player{ $this->data->set("bed-position", $this->bedPosition); } + /** - * @param Vector3 $pos - * + * @param Vector3 $pos position of the top block of the bed + * * @return boolean */ public function sleepOn(Position $pos){ @@ -291,9 +292,14 @@ class Player{ $this->setBedPosition($pos); $this->isSleeping = $pos; $this->sleepingTime = 0; - $this->teleport(new Position($pos->x + 0.5, $pos->y + 1, $pos->z + 0.5, $this->level), false, false, false, false); + $meta = $this->level->level->getBlockDamage($pos->x, $pos->y, $pos->z); + $xoff = BedBlock::PLAYER_BED_OFFS_X[$meta & 3]; + $zoff = BedBlock::PLAYER_BED_OFFS_Z[$meta & 3]; + $this->teleport(new Position($pos->x + $xoff, $pos->y + 0.9375, $pos->z + $zoff, $this->level), false, false, false, false); //TODO change player hitbox size after he starts sleeping if($this->entity instanceof Entity){ + $this->entity->forceUpdateMovement = true; + $this->entity->updateMovement(); $this->entity->updateMetadata(); } @@ -3468,8 +3474,8 @@ class Player{ $this->resendQueue[$count] =& $this->recoveryQueue[$count]; $this->lag[] = $time - $this->recoveryQueue[$count]->sendtime; unset($this->recoveryQueue[$count]); - }else{ - ++$this->packetStats[1]; //lost and wont be recovered + }else{ //lost and wont be recovered + ++$this->packetStats[1]; } } break; diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 0d3970c0..1323cae5 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -7,6 +7,7 @@ class Entity extends Position const CLASS_TYPE = - 1; const MIN_POSSIBLE_SPEED = 1/8000; //anything below will send 0 to player + public $forceUpdateMovement = false; public $searchForClosestPlayers = false; public $modifySpeedY = false; public $modifedSpeedY = 0.0; @@ -1029,7 +1030,8 @@ class Entity extends Position return false; } $now = microtime(true); - 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->isStatic === false && ($this->lastX != $this->x || $this->lastY != $this->y || $this->lastZ != $this->z || $this->lastYaw != $this->yaw || $this->lastPitch != $this->pitch || $this->lastHeadYaw != $this->headYaw || $this->forceUpdateMovement)){ + $this->forceUpdateMovement = false; if($this->class === ENTITY_PLAYER){ if($this->server->api->handle("entity.move", $this) === false){ if($this->class === ENTITY_PLAYER){ @@ -1043,7 +1045,7 @@ class Entity extends Position $pk = new MovePlayerPacket(); $pk->eid = $this->eid; $pk->x = $this->x; - $pk->y = $this->y; + $pk->y = $this->y - 1 - ($this->player->isSleeping ? 0.7375 : 0); $pk->z = $this->z; $pk->yaw = $this->yaw; $pk->pitch = $this->pitch; diff --git a/src/material/block/misc/BedBlock.php b/src/material/block/misc/BedBlock.php index 58fb6c2b..8c63f82b 100644 --- a/src/material/block/misc/BedBlock.php +++ b/src/material/block/misc/BedBlock.php @@ -14,6 +14,8 @@ class BedBlock extends TransparentBlock{ [0, -1], [1, 0] ]; + const PLAYER_BED_OFFS_X = [0.5, 0.1, 0.5, 0.9]; + const PLAYER_BED_OFFS_Z = [0.9, 0.5, 0.1, 0.5]; public function __construct($type = 0){ parent::__construct(BED_BLOCK, $type, "Bed Block"); $this->isActivable = true; diff --git a/src/world/Explosion.php b/src/world/Explosion.php index 25a05aef..abbbd233 100644 --- a/src/world/Explosion.php +++ b/src/world/Explosion.php @@ -97,7 +97,7 @@ class Explosion{ $pk->radius = $this->size; $pk->records = []; //ExplodePacket doesnt seem to use the records provided by this packet, so no need to send more data foreach ($this->level->players as $player){ - $player->blockQueueDataPacket($pk); + $player->blockQueueDataPacket(clone $pk); } return; } @@ -214,7 +214,7 @@ class Explosion{ $pk->radius = $this->size; $pk->records = []; //ExplodePacket doesnt seem to use the records provided by this packet, so no need to send more data foreach ($this->level->players as $player){ - $player->blockQueueDataPacket($pk); + $player->blockQueueDataPacket(clone $pk); } }