add daylight cycle and flight

This commit is contained in:
p2r3
2025-08-13 18:54:20 +03:00
parent e2267b15df
commit 62d46bb8d6
3 changed files with 32 additions and 0 deletions

6
main.c
View File

@@ -16,6 +16,8 @@
#include "src/packets.h"
#include "src/worldgen.h"
uint64_t world_time = 0;
void handlePacket (int client_fd, int length, int packet_id) {
int state = getClientState(client_fd);
@@ -79,6 +81,9 @@ void handlePacket (int client_fd, int length, int packet_id) {
}
sc_setHeldItem(client_fd, player->hotbar);
sc_playerAbilities(client_fd, 0x01 + 0x04); // invulnerability + flight
sc_updateTime(client_fd, world_time);
short _x = player->x / 16, _z = player->z / 16;
sc_setDefaultSpawnPosition(client_fd, 8, 80, 8);
sc_startWaitingForChunks(client_fd);
@@ -275,6 +280,7 @@ int main () {
clock_gettime(CLOCK_REALTIME, &time_now);
if (time_now.tv_sec - keepalive_last.tv_sec > 10) {
sc_keepAlive(client_fd);
sc_updateTime(client_fd, world_time += 200);
clock_gettime(CLOCK_REALTIME, &keepalive_last);
}
}

View File

@@ -230,6 +230,30 @@ int sc_setDefaultSpawnPosition (int client_fd, long x, long y, long z) {
}
// S->C Player Abilities (clientbound)
int sc_playerAbilities (int client_fd, uint8_t flags) {
writeVarInt(client_fd, 10);
writeByte(client_fd, 0x39);
writeByte(client_fd, flags);
writeFloat(client_fd, 0.05f);
writeFloat(client_fd, 0.1f);
}
// S->C Update Time
int sc_updateTime (int client_fd, uint64_t ticks) {
writeVarInt(client_fd, sizeVarInt(0x6A) + 17);
writeVarInt(client_fd, 0x6A);
writeUint64(client_fd, ticks);
writeUint64(client_fd, ticks);
writeByte(client_fd, true);
}
// S->C Game Event 13 (Start waiting for level chunks)
int sc_startWaitingForChunks (int client_fd) {
writeVarInt(client_fd, 6);

View File

@@ -19,6 +19,8 @@ int sc_loginPlay (int client_fd);
int sc_synchronizePlayerPosition (int client_fd, double x, double y, double z, float yaw, float pitch);
int sc_setDefaultSpawnPosition (int client_fd, long x, long y, long z);
int sc_startWaitingForChunks (int client_fd);
int sc_playerAbilities (int client_fd, uint8_t flags);
int sc_updateTime (int client_fd, uint64_t ticks);
int sc_setCenterChunk (int client_fd, int x, int y);
int sc_chunkDataAndUpdateLight (int client_fd, int _x, int _z);
int sc_keepAlive (int client_fd);