Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <stdint.h>
#include <unistd.h>
#include <stdbool.h>

#ifdef ESP_PLATFORM
#define WIFI_SSID "your-ssid"
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 9 additions & 3 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -720,7 +726,7 @@ int main () {
}

close(server_fd);

#ifdef _WIN32 //cleanup windows socket
WSACleanup();
#endif
Expand Down
7 changes: 7 additions & 0 deletions src/procedures.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down