implement hunger system

This commit is contained in:
p2r3
2025-08-26 02:29:00 +03:00
parent 297047b6dd
commit 84fda79901
6 changed files with 206 additions and 51 deletions

View File

@@ -30,6 +30,9 @@
#define VIEW_DISTANCE 2
// Time between server ticks in microseconds (default = 1s)
#define TIME_BETWEEN_TICKS 1000000
// Calculated from TIME_BETWEEN_TICKS
#define TICKS_PER_SECOND (1000000 / TIME_BETWEEN_TICKS)
#define TICKS_TO_EAT (unsigned int)(1.6f * TICKS_PER_SECOND)
// How many visited chunks to "remember"
// The server will not re-send chunks that the player has recently been in
#define VISITED_HISTORY 4
@@ -88,16 +91,23 @@ typedef struct {
uint8_t grounded_y;
uint8_t health;
uint8_t hunger;
uint16_t saturation;
uint8_t hotbar;
uint16_t inventory_items[41];
uint16_t craft_items[9];
uint16_t cursor_item;
uint8_t inventory_count[41];
uint8_t craft_count[9];
uint8_t cursor_count;
// Usage depends on player's flags, see below
// When no flags are set, acts as cursor item ID
uint16_t flagval_16;
// Usage depends on player's flags, see below
// When no flags are set, acts as cursor item count
uint8_t flagval_8;
// 0x01 - attack cooldown
// 0x02 - has not spawned yet
// 0x04 - sneaking
// 0x08 - sprinting
// 0x10 - eating, makes extra8 act as eating timer
uint8_t flags;
} PlayerData;

View File

@@ -8,6 +8,7 @@ int cs_clientInformation (int client_fd);
int cs_pluginMessage (int client_fd);
int cs_playerAction (int client_fd);
int cs_useItemOn (int client_fd);
int cs_useItem (int client_fd);
int cs_setPlayerPositionAndRotation (int client_fd, double *x, double *y, double *z, float *yaw, float *pitch, uint8_t *on_ground);
int cs_setPlayerPosition (int client_fd, double *x, double *y, double *z, uint8_t *on_ground);
int cs_setPlayerRotation (int client_fd, float *yaw, float *pitch, uint8_t *on_ground);
@@ -16,7 +17,10 @@ int cs_setHeldItem (int client_fd);
int cs_clickContainer (int client_fd);
int cs_closeContainer (int client_fd);
int cs_clientStatus (int client_fd);
int cs_chat(int client_fd);
int cs_chat (int client_fd);
int cs_interact (int client_fd);
int cs_playerInput (int client_fd);
int cs_playerCommand (int client_fd);
// Clientbound packets
int sc_loginSuccess (int client_fd, uint8_t *uuid, char *name);
@@ -47,10 +51,8 @@ int sc_damageEvent (int client_fd, int id, int type);
int sc_setHealth (int client_fd, uint8_t health, uint8_t food);
int sc_respawn (int client_fd);
int sc_systemChat (int client_fd, char* message, uint16_t len);
int cs_interact (int client_fd);
int sc_entityEvent (int client_fd, int entity_id, uint8_t status);
int sc_removeEntity (int client_fd, int entity_id);
int cs_playerInput (int client_fd);
int sc_registries (int client_fd);
#endif