diff --git a/include/globals.h b/include/globals.h index 69757cd4..bfb69674 100644 --- a/include/globals.h +++ b/include/globals.h @@ -3,6 +3,7 @@ #include #include +#include #ifdef ESP_PLATFORM #define WIFI_SSID "your-ssid" @@ -212,6 +213,7 @@ typedef struct { int8_t yaw; int8_t pitch; uint8_t grounded_y; + bool falling; uint8_t health; uint8_t hunger; uint16_t saturation; diff --git a/src/main.c b/src/main.c index bc68191f..f5c7b979 100644 --- a/src/main.c +++ b/src/main.c @@ -225,6 +225,7 @@ void handlePacket (int client_fd, int length, int packet_id, int state) { // Handle fall damage if (on_ground) { int16_t damage = player->grounded_y - player->y - 3; + player -> falling = false; if (damage > 0 && (GAMEMODE == 0 || GAMEMODE == 2) && !swimming) { hurtEntity(client_fd, -1, D_fall, damage); } @@ -324,6 +325,11 @@ void handlePacket (int client_fd, int length, int packet_id, int state) { sc_synchronizePlayerPosition(client_fd, cx, 255, cz, player->yaw * 180 / 127, player->pitch * 90 / 127); } + // Check if Player is falling + //-0.27 due to players jumping 1.25 blocks + if(player -> y > y || (player -> y != player-> grounded_y && player -> y > y- 0.27)) { + player -> falling = true; + } // Update position in player data player->x = cx; player->y = cy; @@ -443,7 +449,7 @@ void handlePacket (int client_fd, int length, int packet_id, int state) { case 0x34: if (state == STATE_PLAY) cs_setHeldItem(client_fd); break; - + case 0x3C: if (state == STATE_PLAY) cs_swingArm(client_fd); break; @@ -546,7 +552,7 @@ int main () { (const char*)&opt, sizeof(opt)) < 0) { #else if (setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) < 0) { -#endif +#endif perror("socket options failed"); exit(EXIT_FAILURE); } @@ -720,7 +726,7 @@ int main () { } close(server_fd); - + #ifdef _WIN32 //cleanup windows socket WSACleanup(); #endif diff --git a/src/procedures.c b/src/procedures.c index 9f7af8f0..b3091716 100644 --- a/src/procedures.c +++ b/src/procedures.c @@ -60,6 +60,7 @@ void resetPlayerData (PlayerData *player) { player->y = 80; player->flags |= 0x02; player->grounded_y = 0; + player->falling = false; for (int i = 0; i < 41; i ++) { player->inventory_items[i] = 0; player->inventory_count[i] = 0; @@ -1490,6 +1491,12 @@ void hurtEntity (int entity_id, int attacker_id, uint8_t damage_type, uint8_t da else if (held_item == I_diamond_sword) damage *= 7; else if (held_item == I_netherite_sword) damage *= 8; + // Critical hits handling + if(player -> falling == true){ + sc_entityAnimation(attacker_id,entity_id,4); //id 4 being critical particles + damage += damage / 2; + } + // Enable attack cooldown player->flags |= 0x01; player->flagval_8 = 0;