From 19e3d339f6c119fb30b49e2a502b69882fee310f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=AD=E3=82=89=E3=81=B2=E3=81=8B=E3=81=A0?= Date: Tue, 29 Aug 2023 19:43:21 +0900 Subject: [PATCH] InGamePacketHandler: subtract from raw position before rounding it (#6022) This allows better compensation for floating point errors introduced by the subtraction of the 1.62 height offset. For example, if the player is at y=7 exactly, their Y coordinate will be reported as 8.62, which, because of floating point errors, will be something like `8.619999999`. Subtracting `1.62` from this (really something like `1.62000000000005...`) leads to the calculated Y coordinate being slightly below 7. Rounding after subtracting this offset allows this to be rounded to 7 sharp. Similar errors appear in various other coordinates. --- src/network/mcpe/handler/InGamePacketHandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/network/mcpe/handler/InGamePacketHandler.php b/src/network/mcpe/handler/InGamePacketHandler.php index 729b5b51b..30841d806 100644 --- a/src/network/mcpe/handler/InGamePacketHandler.php +++ b/src/network/mcpe/handler/InGamePacketHandler.php @@ -201,7 +201,7 @@ class InGamePacketHandler extends PacketHandler{ } $hasMoved = $this->lastPlayerAuthInputPosition === null || !$this->lastPlayerAuthInputPosition->equals($rawPos); - $newPos = $rawPos->round(4)->subtract(0, 1.62, 0); + $newPos = $rawPos->subtract(0, 1.62, 0)->round(4); if($this->forceMoveSync && $hasMoved){ $curPos = $this->player->getLocation();