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.
This commit is contained in:
ねらひかだ 2023-08-29 19:43:21 +09:00 committed by GitHub
parent 1a18e32011
commit 19e3d339f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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();