1
0
mirror of https://github.com/p2r3/bareiron.git synced 2025-10-01 23:25:09 +02:00

implement basic support for mobs

This commit is contained in:
p2r3
2025-08-22 02:29:59 +03:00
parent 5a0f8fd376
commit ca9edce43a
9 changed files with 205 additions and 41 deletions

View File

@@ -15,10 +15,19 @@
#define true 1
#define false 0
// TCP port, Minecraft's default is 25565
#define PORT 25565
// How many players to keep in memory, NOT the amount of concurrent players
// Even when offline, players who have logged on before take up a slot
#define MAX_PLAYERS 16
// How many mobs to allocate memory for
#define MAX_MOBS (MAX_PLAYERS)
// Server game mode: 0 - survival; 1 - creative; 2 - adventure; 3 - spectator
#define GAMEMODE 0
// Max render distance, determines how many chunks to send
#define VIEW_DISTANCE 2
// Time between server ticks in microseconds (default = 2s)
#define TIME_BETWEEN_TICKS 2000000
// How many visited chunks to "remember"
// The server will not re-send chunks that the player has recently been in
#define VISITED_HISTORY 4
@@ -77,6 +86,13 @@ typedef struct {
uint8_t craft_count[9];
} PlayerData;
typedef struct {
uint8_t type;
short x;
uint8_t y;
short z;
} MobData;
#pragma pack(pop)
extern BlockChange block_changes[20000];
@@ -84,4 +100,6 @@ extern int block_changes_count;
extern PlayerData player_data[MAX_PLAYERS];
extern MobData mob_data[MAX_MOBS];
#endif

View File

@@ -34,7 +34,7 @@ int sc_blockUpdate (int client_fd, int64_t x, int64_t y, int64_t z, uint8_t bloc
int sc_openScreen (int client_fd, uint8_t window, const char *title, uint16_t length);
int sc_acknowledgeBlockChange (int client_fd, int sequence);
int sc_playerInfoUpdateAddPlayer (int client_fd, PlayerData player);
int sc_spawnEntity (int client_fd, int id, uint8_t *uuid, int type, double x, double y, double z, double yaw, double pitch);
int sc_spawnEntity (int client_fd, int id, uint8_t *uuid, int type, double x, double y, double z, uint8_t yaw, uint8_t pitch);
int sc_spawnEntityPlayer (int client_fd, PlayerData player);
int sc_teleportEntity (int client_fd, int id, double x, double y, double z, float yaw, float pitch);
int sc_setHeadRotation (int client_fd, int id, uint8_t yaw);

View File

@@ -10,7 +10,7 @@ inline int mod_abs (int a, int b) {
return ((a % b) + b) % b;
}
inline int div_floor (int a, int b) {
return a < 0 ? (a - b) / b : a / b;
return a % b < 0 ? (a - b) / b : a / b;
}
ssize_t recv_all (int client_fd, void *buf, size_t n, uint8_t require_first);
@@ -36,6 +36,12 @@ void readString (int client_fd);
uint32_t fast_rand ();
uint64_t splitmix64 (uint64_t state);
#ifdef ESP_PLATFORM
#define get_program_time esp_timer_get_time
#else
int64_t get_program_time ();
#endif
extern int client_states[MAX_PLAYERS * 2];
void setClientState (int client_fd, int new_state);
@@ -61,4 +67,7 @@ uint16_t getMiningResult (uint16_t held_item, uint8_t block);
void bumpToolDurability (PlayerData *player);
void handlePlayerAction (PlayerData *player, int action, short x, short y, short z);
void spawnMob (uint8_t type, short x, uint8_t y, short z);
void handleServerTick (int64_t time_since_last_tick);
#endif

View File

@@ -23,7 +23,8 @@ typedef struct {
uint32_t getChunkHash (short x, short z);
uint8_t getChunkBiome (short x, short z);
int getHeightAt (int rx, int rz, int _x, int _z, uint32_t chunk_hash, uint8_t biome);
int getHeightAtFromHash (int rx, int rz, int _x, int _z, uint32_t chunk_hash, uint8_t biome);
int getHeightAt (int x, int z);
uint8_t getTerrainAt (int x, int y, int z, ChunkAnchor anchor);
uint8_t getBlockAt (int x, int y, int z);