From e4267e7edf01804ab04b9950ebf4948aa85fccb1 Mon Sep 17 00:00:00 2001 From: p2r3 Date: Fri, 29 Aug 2025 00:29:47 +0300 Subject: [PATCH] fix storing wrong integer player position at negative coordinates --- src/main.c | 2 ++ src/procedures.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index 6a1b6fe..bfdd4cd 100644 --- a/src/main.c +++ b/src/main.c @@ -252,6 +252,8 @@ void handlePacket (int client_fd, int length, int packet_id, int state) { // Cast the values to short to get integer position short cx = x, cy = y, cz = z; + if (x < 0) cx -= 1; + if (z < 0) cz -= 1; // Determine the player's chunk coordinates short _x = (cx < 0 ? cx - 16 : cx) / 16, _z = (cz < 0 ? cz - 16 : cz) / 16; // Calculate distance between previous and current chunk coordinates diff --git a/src/procedures.c b/src/procedures.c index d953c9c..b2fbdb8 100644 --- a/src/procedures.c +++ b/src/procedures.c @@ -243,9 +243,9 @@ void spawnPlayer (PlayerData *player) { player->flags &= ~0x02; } else { // Not a new player // Calculate spawn position from player data - spawn_x = player->x > 0 ? (float)player->x + 0.5 : (float)player->x - 0.5; + spawn_x = (float)player->x + 0.5; spawn_y = player->y; - spawn_z = player->z > 0 ? (float)player->z + 0.5 : (float)player->z - 0.5; + spawn_z = (float)player->z + 0.5; spawn_yaw = player->yaw * 180 / 127; spawn_pitch = player->pitch * 90 / 127; }