mirror of https://github.com/basinserver/basin/
integrate packet handlers, most present implementations updated
This commit is contained in:
parent
7b819697ce
commit
3d6fe21982
|
@ -15,6 +15,6 @@ void init_base_commands();
|
|||
|
||||
void registerCommand(char* command, void (*callback)(struct player* player, char** args, size_t args_count));
|
||||
|
||||
void callCommand(struct player* player, char* command);
|
||||
void callCommand(struct player* player, struct mempool* pool, char* command);
|
||||
|
||||
#endif /* COMMAND_H_ */
|
||||
|
|
|
@ -403,16 +403,16 @@ struct entity {
|
|||
double x;
|
||||
double y;
|
||||
double z;
|
||||
double lx;
|
||||
double ly;
|
||||
double lz;
|
||||
double last_x;
|
||||
double last_y;
|
||||
double last_z;
|
||||
uint32_t type;
|
||||
float yaw;
|
||||
float pitch;
|
||||
float lyaw;
|
||||
float lpitch;
|
||||
float last_yaw;
|
||||
float last_pitch;
|
||||
float headpitch;
|
||||
int onGround;
|
||||
int on_ground;
|
||||
int collidedVertically;
|
||||
int collidedHorizontally;
|
||||
double motX;
|
||||
|
|
|
@ -49,7 +49,7 @@ void broadcastf(char* color, char* fmt, ...);
|
|||
#define BEGIN_BROADCAST_DIST(distfrom, dist) pthread_rwlock_rdlock(&(players)->rwlock); ITER_MAP(distfrom->world->players) { struct player* bc_player = (struct player*)value; if(entity_distsq(bc_player->entity, distfrom) < dist * dist) {
|
||||
#define BEGIN_BROADCAST_DISTXYZ(x, y, z, players, dist) pthread_rwlock_rdlock(&(players)->rwlock); ITER_MAP(players) { struct player* bc_player = (struct player*)value; if (entity_distsq_block(bc_player->entity, x, y, z) < dist * dist) {
|
||||
#define BEGIN_BROADCAST_EXCEPT(players, except) pthread_rwlock_rdlock(&(players)->rwlock); ITER_MAP(players) { struct player* bc_player = (struct player*)value; if (bc_player != except) {
|
||||
#define BEGIN_BROADCAST_EXCEPT_DIST(except, distfrom, dist) pthread_rwlock_rdlock(&(players)->rwlock); ITER_MAP(distfrom->world->players) { struct player* bc_player = (struct player*)value; if (bc_player != except && entity_distsq(bc_player->entity, distfrom) < dist * dist) {
|
||||
#define BEGIN_BROADCAST_EXCEPT_DIST(except, distfrom, dist) pthread_rwlock_rdlock(&(distfrom->world->players)->rwlock); ITER_MAP(distfrom->world->players) { struct player* bc_player = (struct player*)value; if (bc_player != except && entity_distsq(bc_player->entity, distfrom) < dist * dist) {
|
||||
#define END_BROADCAST(players) } ITER_MAP_END(); pthread_rwlock_unlock(&(players)->rwlock); }
|
||||
|
||||
/*
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#include <stdlib.h>
|
||||
#include <pthread.h>
|
||||
|
||||
size_t tick_counter;
|
||||
struct config* cfg;
|
||||
struct mempool* global_pool;
|
||||
struct logsess* delog;
|
||||
|
|
|
@ -51,7 +51,7 @@ struct inventory {
|
|||
int window;
|
||||
struct hashmap* watching_players;
|
||||
struct tile_entity* tile;
|
||||
pthread_rwlock_t rwlock;
|
||||
pthread_mutex_t mutex;
|
||||
};
|
||||
|
||||
struct player;
|
||||
|
|
|
@ -1280,6 +1280,4 @@ ssize_t packet_read(struct connection* conn, unsigned char* buf, size_t buflen,
|
|||
|
||||
ssize_t packet_write(struct connection* conn, struct packet* packet);
|
||||
|
||||
void freePacket(int state, int dir, struct packet* packet);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -14,7 +14,8 @@
|
|||
|
||||
struct player {
|
||||
struct mempool* pool;
|
||||
struct conn* conn;
|
||||
struct server* server;
|
||||
struct conn* conn;
|
||||
struct world* world;
|
||||
struct entity* entity;
|
||||
|
||||
|
@ -25,6 +26,8 @@ struct player {
|
|||
struct hashmap* loaded_entities;
|
||||
struct queue* outgoing_packets;
|
||||
struct queue* incoming_packets;
|
||||
uint32_t next_keep_alive;
|
||||
uint8_t spawned_in;
|
||||
|
||||
struct inventory* inventory;
|
||||
struct inventory* open_inventory;
|
||||
|
@ -43,7 +46,7 @@ struct player {
|
|||
int32_t xptotal;
|
||||
int32_t xplevel;
|
||||
int32_t score;
|
||||
size_t lastTeleportID;
|
||||
size_t last_teleport_id;
|
||||
int8_t sleeping;
|
||||
int16_t fire;
|
||||
//TODO: enderitems inventory
|
||||
|
@ -63,7 +66,7 @@ struct player {
|
|||
float saturation;
|
||||
};
|
||||
|
||||
struct player* player_new(struct mempool* parent, struct conn* conn, struct world* world, struct entity* entity, char* name, struct uuid uuid, uint8_t gamemode);
|
||||
struct player* player_new(struct mempool* parent, struct server* server, struct conn* conn, struct world* world, struct entity* entity, char* name, struct uuid uuid, uint8_t gamemode);
|
||||
|
||||
void player_hungerUpdate(struct player* player);
|
||||
|
||||
|
|
|
@ -8,38 +8,38 @@
|
|||
#include <basin/packet.h>
|
||||
#include <basin/player.h>
|
||||
|
||||
typedef void (*packet_handler)(struct player* player, void* packet);
|
||||
typedef void (*packet_handler)(struct player* player, struct mempool* pool, void* packet);
|
||||
|
||||
void player_packet_handle_teleportconfirm(struct player* player, struct pkt_play_server_teleportconfirm* packet);
|
||||
void player_packet_handle_tabcomplete(struct player* player, struct pkt_play_server_tabcomplete* packet);
|
||||
void player_packet_handle_chatmessage(struct player* player, struct pkt_play_server_chatmessage* packet);
|
||||
void player_packet_handle_clientstatus(struct player* player, struct pkt_play_server_clientstatus* packet);
|
||||
void player_packet_handle_clientsettings(struct player* player, struct pkt_play_server_clientsettings* packet);
|
||||
void player_packet_handle_confirmtransaction(struct player* player, struct pkt_play_server_confirmtransaction* packet);
|
||||
void player_packet_handle_enchantitem(struct player* player, struct pkt_play_server_enchantitem* packet);
|
||||
void player_packet_handle_clickwindow(struct player* player, struct pkt_play_server_clickwindow* packet);
|
||||
void player_packet_handle_closewindow(struct player* player, struct pkt_play_server_closewindow* packet);
|
||||
void player_packet_handle_pluginmessage(struct player* player, struct pkt_play_server_pluginmessage* packet);
|
||||
void player_packet_handle_useentity(struct player* player, struct pkt_play_server_useentity* packet);
|
||||
void player_packet_handle_keepalive(struct player* player, struct pkt_play_server_keepalive* packet);
|
||||
void player_packet_handle_playerposition(struct player* player, struct pkt_play_server_playerposition* packet);
|
||||
void player_packet_handle_playerpositionandlook(struct player* player, struct pkt_play_server_playerpositionandlook* packet);
|
||||
void player_packet_handle_playerlook(struct player* player, struct pkt_play_server_playerlook* packet);
|
||||
void player_packet_handle_player(struct player* player, struct pkt_play_server_player* packet);
|
||||
void player_packet_handle_vehiclemove(struct player* player, struct pkt_play_server_vehiclemove* packet);
|
||||
void player_packet_handle_steerboat(struct player* player, struct pkt_play_server_steerboat* packet);
|
||||
void player_packet_handle_playerabilities(struct player* player, struct pkt_play_server_playerabilities* packet);
|
||||
void player_packet_handle_playerdigging(struct player* player, struct pkt_play_server_playerdigging* packet);
|
||||
void player_packet_handle_entityaction(struct player* player, struct pkt_play_server_entityaction* packet);
|
||||
void player_packet_handle_steervehicle(struct player* player, struct pkt_play_server_steervehicle* packet);
|
||||
void player_packet_handle_resourcepackstatus(struct player* player, struct pkt_play_server_resourcepackstatus* packet);
|
||||
void player_packet_handle_helditemchange(struct player* player, struct pkt_play_server_helditemchange* packet);
|
||||
void player_packet_handle_creativeinventoryaction(struct player* player, struct pkt_play_server_creativeinventoryaction* packet);
|
||||
void player_packet_handle_updatesign(struct player* player, struct pkt_play_server_updatesign* packet);
|
||||
void player_packet_handle_animation(struct player* player, struct pkt_play_server_animation* packet);
|
||||
void player_packet_handle_spectate(struct player* player, struct pkt_play_server_spectate* packet);
|
||||
void player_packet_handle_playerblockplacement(struct player* player, struct pkt_play_server_playerblockplacement* packet);
|
||||
void player_packet_handle_useitem(struct player* player, struct pkt_play_server_useitem* packet);
|
||||
void player_packet_handle_teleportconfirm(struct player* player, struct mempool* pool, struct pkt_play_server_teleportconfirm* packet);
|
||||
void player_packet_handle_tabcomplete(struct player* player, struct mempool* pool, struct pkt_play_server_tabcomplete* packet);
|
||||
void player_packet_handle_chatmessage(struct player* player, struct mempool* pool, struct pkt_play_server_chatmessage* packet);
|
||||
void player_packet_handle_clientstatus(struct player* player, struct mempool* pool, struct pkt_play_server_clientstatus* packet);
|
||||
void player_packet_handle_clientsettings(struct player* player, struct mempool* pool, struct pkt_play_server_clientsettings* packet);
|
||||
void player_packet_handle_confirmtransaction(struct player* player, struct mempool* pool, struct pkt_play_server_confirmtransaction* packet);
|
||||
void player_packet_handle_enchantitem(struct player* player, struct mempool* pool, struct pkt_play_server_enchantitem* packet);
|
||||
void player_packet_handle_clickwindow(struct player* player, struct mempool* pool, struct pkt_play_server_clickwindow* packet);
|
||||
void player_packet_handle_closewindow(struct player* player, struct mempool* pool, struct pkt_play_server_closewindow* packet);
|
||||
void player_packet_handle_pluginmessage(struct player* player, struct mempool* pool, struct pkt_play_server_pluginmessage* packet);
|
||||
void player_packet_handle_useentity(struct player* player, struct mempool* pool, struct pkt_play_server_useentity* packet);
|
||||
void player_packet_handle_keepalive(struct player* player, struct mempool* pool, struct pkt_play_server_keepalive* packet);
|
||||
void player_packet_handle_playerposition(struct player* player, struct mempool* pool, struct pkt_play_server_playerposition* packet);
|
||||
void player_packet_handle_playerpositionandlook(struct player* player, struct mempool* pool, struct pkt_play_server_playerpositionandlook* packet);
|
||||
void player_packet_handle_playerlook(struct player* player, struct mempool* pool, struct pkt_play_server_playerlook* packet);
|
||||
void player_packet_handle_player(struct player* player, struct mempool* pool, struct pkt_play_server_player* packet);
|
||||
void player_packet_handle_vehiclemove(struct player* player, struct mempool* pool, struct pkt_play_server_vehiclemove* packet);
|
||||
void player_packet_handle_steerboat(struct player* player, struct mempool* pool, struct pkt_play_server_steerboat* packet);
|
||||
void player_packet_handle_playerabilities(struct player* player, struct mempool* pool, struct pkt_play_server_playerabilities* packet);
|
||||
void player_packet_handle_playerdigging(struct player* player, struct mempool* pool, struct pkt_play_server_playerdigging* packet);
|
||||
void player_packet_handle_entityaction(struct player* player, struct mempool* pool, struct pkt_play_server_entityaction* packet);
|
||||
void player_packet_handle_steervehicle(struct player* player, struct mempool* pool, struct pkt_play_server_steervehicle* packet);
|
||||
void player_packet_handle_resourcepackstatus(struct player* player, struct mempool* pool, struct pkt_play_server_resourcepackstatus* packet);
|
||||
void player_packet_handle_helditemchange(struct player* player, struct mempool* pool, struct pkt_play_server_helditemchange* packet);
|
||||
void player_packet_handle_creativeinventoryaction(struct player* player, struct mempool* pool, struct pkt_play_server_creativeinventoryaction* packet);
|
||||
void player_packet_handle_updatesign(struct player* player, struct mempool* pool, struct pkt_play_server_updatesign* packet);
|
||||
void player_packet_handle_animation(struct player* player, struct mempool* pool, struct pkt_play_server_animation* packet);
|
||||
void player_packet_handle_spectate(struct player* player, struct mempool* pool, struct pkt_play_server_spectate* packet);
|
||||
void player_packet_handle_playerblockplacement(struct player* player, struct mempool* pool, struct pkt_play_server_playerblockplacement* packet);
|
||||
void player_packet_handle_useitem(struct player* player, struct mempool* pool, struct pkt_play_server_useitem* packet);
|
||||
|
||||
packet_handler player_packet_handlers[256] = {
|
||||
(packet_handler) player_packet_handle_teleportconfirm,
|
||||
|
|
|
@ -28,6 +28,7 @@ struct server {
|
|||
struct queue* prepared_connections;
|
||||
struct hashmap* players_by_entity_id;
|
||||
uint32_t next_entity_id;
|
||||
size_t tick_counter;
|
||||
// struct queue* playersToLoad;
|
||||
|
||||
};
|
||||
|
|
|
@ -58,7 +58,7 @@ struct world {
|
|||
struct hashmap* chunks;
|
||||
pthread_mutex_t tick_mut;
|
||||
pthread_cond_t tick_cond;
|
||||
char* levelType;
|
||||
char* level_type;
|
||||
struct encpos spawnpos;
|
||||
int32_t dimension;
|
||||
uint64_t time;
|
||||
|
|
|
@ -201,7 +201,7 @@ void registerCommand(char* command, command_callback callback) {
|
|||
add_collection(registered_commands, com);
|
||||
}
|
||||
|
||||
void callCommand(struct player* player, char* command) {
|
||||
void callCommand(struct player* player, struct mempool* pool, char* command) {
|
||||
if (registered_commands == NULL) return;
|
||||
size_t sl = strlen(command);
|
||||
size_t arg_count = 0;
|
||||
|
|
78
src/entity.c
78
src/entity.c
|
@ -69,7 +69,7 @@ int onTick_tnt(struct world* world, struct entity* ent) {
|
|||
|
||||
int onTick_fallingblock(struct world* world, struct entity* ent) {
|
||||
// TODO: mc has some methods to prevent dupes here, we should see if basin is afflicted
|
||||
if (ent->onGround && ent->age > 1) {
|
||||
if (ent->on_ground && ent->age > 1) {
|
||||
block b = world_get_block(world, (int32_t) floor(ent->x), (int32_t) floor(ent->y), (int32_t) floor(ent->z));
|
||||
if (!falling_canFallThrough(b)) {
|
||||
struct slot sl;
|
||||
|
@ -221,9 +221,9 @@ int tick_arrow(struct world* world, struct entity* entity) {
|
|||
entity->data.arrow.ticksInGround = 1;
|
||||
entity->data.arrow.isCritical = 0;
|
||||
entity->immovable = 1;
|
||||
entity->lx = 0.;
|
||||
entity->ly = 0.;
|
||||
entity->lz = 0.;
|
||||
entity->last_x = 0.;
|
||||
entity->last_y = 0.;
|
||||
entity->last_z = 0.;
|
||||
}
|
||||
} else {
|
||||
if (entity->data.arrow.ticksInGround == 1) {
|
||||
|
@ -245,21 +245,21 @@ int tick_arrow(struct world* world, struct entity* entity) {
|
|||
entity->yaw = atan2f(entity->motX, entity->motZ) * 180. / M_PI;
|
||||
entity->pitch = atan2f(entity->motY, dhz) * 180. / M_PI;
|
||||
//printf("desired %f, %f, %f\n", entity->pitch, entity->motY, dhz);
|
||||
//printf("yaw = %f, lyaw = %f\npitch = %f, lpitch = %f\n", entity->yaw, entity->lyaw, entity->pitch, entity->lpitch);
|
||||
if ((entity->lyaw == 0. && entity->lpitch == 0.)) {
|
||||
entity->lyaw = entity->yaw;
|
||||
entity->lpitch = entity->pitch;
|
||||
//printf("yaw = %f, last_yaw = %f\npitch = %f, last_pitch = %f\n", entity->yaw, entity->last_yaw, entity->pitch, entity->last_pitch);
|
||||
if ((entity->last_yaw == 0. && entity->last_pitch == 0.)) {
|
||||
entity->last_yaw = entity->yaw;
|
||||
entity->last_pitch = entity->pitch;
|
||||
} else {
|
||||
while (entity->pitch - entity->lpitch < -180.)
|
||||
entity->lpitch -= 360.;
|
||||
while (entity->pitch - entity->lpitch >= 180.)
|
||||
entity->lpitch += 360.;
|
||||
while (entity->yaw - entity->lyaw < -180.)
|
||||
entity->lyaw -= 360.;
|
||||
while (entity->yaw - entity->lyaw >= 180.)
|
||||
entity->lyaw += 360.;
|
||||
entity->pitch = entity->lpitch + (entity->pitch - entity->lpitch) * .2;
|
||||
entity->yaw = entity->lyaw + (entity->yaw - entity->lyaw) * .2;
|
||||
while (entity->pitch - entity->last_pitch < -180.)
|
||||
entity->last_pitch -= 360.;
|
||||
while (entity->pitch - entity->last_pitch >= 180.)
|
||||
entity->last_pitch += 360.;
|
||||
while (entity->yaw - entity->last_yaw < -180.)
|
||||
entity->last_yaw -= 360.;
|
||||
while (entity->yaw - entity->last_yaw >= 180.)
|
||||
entity->last_yaw += 360.;
|
||||
entity->pitch = entity->last_pitch + (entity->pitch - entity->last_pitch) * .2;
|
||||
entity->yaw = entity->last_yaw + (entity->yaw - entity->last_yaw) * .2;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
@ -494,7 +494,7 @@ void getEntityCollision(struct entity* ent, struct boundingbox* bb) {
|
|||
|
||||
void jump(struct entity* entity) {
|
||||
if (entity->inWater || entity->inLava) entity->motY += .04;
|
||||
else if (entity->onGround) {
|
||||
else if (entity->on_ground) {
|
||||
entity->motY = .42;
|
||||
//entity sprinting jump?
|
||||
}
|
||||
|
@ -508,16 +508,16 @@ struct entity* newEntity(int32_t id, double x, double y, double z, uint32_t type
|
|||
e->x = x;
|
||||
e->y = y;
|
||||
e->z = z;
|
||||
e->lx = x;
|
||||
e->ly = y;
|
||||
e->lz = z;
|
||||
e->last_x = x;
|
||||
e->last_y = y;
|
||||
e->last_z = z;
|
||||
e->type = type;
|
||||
e->yaw = yaw;
|
||||
e->pitch = pitch;
|
||||
e->lyaw = yaw;
|
||||
e->lpitch = pitch;
|
||||
e->last_yaw = yaw;
|
||||
e->last_pitch = pitch;
|
||||
e->headpitch = 0.;
|
||||
e->onGround = 0;
|
||||
e->on_ground = 0;
|
||||
e->motX = 0.;
|
||||
e->motY = 0.;
|
||||
e->motZ = 0.;
|
||||
|
@ -1052,7 +1052,7 @@ int moveEntity(struct entity* entity, double* mx, double* my, double* mz, float
|
|||
pbb.maxZ += nz;
|
||||
entity->collidedHorizontally = *mx != nx || *mz != nz;
|
||||
entity->collidedVertically = *my != ny;
|
||||
entity->onGround = entity->collidedVertically && *my < 0.;
|
||||
entity->on_ground = entity->collidedVertically && *my < 0.;
|
||||
int32_t bx = floor(entity->x);
|
||||
int32_t by = floor(entity->y - .20000000298023224);
|
||||
int32_t bz = floor(entity->z);
|
||||
|
@ -1111,7 +1111,7 @@ void applyKnockback(struct entity* entity, float yaw, float strength) {
|
|||
entity->motZ /= 2.;
|
||||
entity->motX -= xr / m * strength;
|
||||
entity->motZ -= zr / m * strength;
|
||||
if (entity->onGround) {
|
||||
if (entity->on_ground) {
|
||||
entity->motY /= 2.;
|
||||
entity->motY += strength;
|
||||
if (entity->motY > .4) entity->motY = .4;
|
||||
|
@ -1143,7 +1143,7 @@ int damageEntityWithItem(struct entity* attacked, struct entity* attacker, uint8
|
|||
damage *= .2 + as * as * .8;
|
||||
knockback_strength *= .2 + as * as * .8;
|
||||
}
|
||||
if (attacker->y > attacked->y && (attacker->ly - attacker->y) > 0 && !attacker->onGround && !attacker->sprinting) { // todo water/ladder
|
||||
if (attacker->y > attacked->y && (attacker->last_y - attacker->y) > 0 && !attacker->on_ground && !attacker->sprinting) { // todo water/ladder
|
||||
damage *= 1.5;
|
||||
}
|
||||
BEGIN_HASHMAP_ITERATION (plugins)
|
||||
|
@ -1371,11 +1371,11 @@ void pushOutOfBlocks(struct entity* ent) {
|
|||
|
||||
void tick_entity(struct world* world, struct entity* entity) {
|
||||
if (entity->type != ENT_PLAYER) {
|
||||
entity->lx = entity->x;
|
||||
entity->ly = entity->y;
|
||||
entity->lz = entity->z;
|
||||
entity->lyaw = entity->yaw;
|
||||
entity->lpitch = entity->pitch;
|
||||
entity->last_x = entity->x;
|
||||
entity->last_y = entity->y;
|
||||
entity->last_z = entity->z;
|
||||
entity->last_yaw = entity->yaw;
|
||||
entity->last_pitch = entity->pitch;
|
||||
}
|
||||
entity->age++;
|
||||
if (entity->invincibilityTicks > 0) entity->invincibilityTicks--;
|
||||
|
@ -1428,7 +1428,7 @@ void tick_entity(struct world* world, struct entity* entity) {
|
|||
}
|
||||
if (gravity != 0. && !entity->immovable) entity->motY -= gravity;
|
||||
if (!ar) {
|
||||
if (entity->onGround) {
|
||||
if (entity->on_ground) {
|
||||
struct block_info* bi = getBlockInfo(world_get_block(entity->world, (int32_t) floor(entity->x), (int32_t) floor(entity->y) - 1, (int32_t) floor(entity->z)));
|
||||
if (bi != NULL) friction = bi->slipperiness * .98;
|
||||
}
|
||||
|
@ -1439,7 +1439,7 @@ void tick_entity(struct world* world, struct entity* entity) {
|
|||
if (fabs(entity->motX) < .0001) entity->motX = 0.;
|
||||
if (fabs(entity->motY) < .0001) entity->motY = 0.;
|
||||
if (fabs(entity->motZ) < .0001) entity->motZ = 0.;
|
||||
if (entity->type == ENT_ITEM && entity->onGround && entity->motX == 0. && entity->motY == 0. && entity->motZ == 0.) entity->motY *= -.5;
|
||||
if (entity->type == ENT_ITEM && entity->on_ground && entity->motX == 0. && entity->motY == 0. && entity->motZ == 0.) entity->motY *= -.5;
|
||||
}
|
||||
if (entity->type == ENT_ITEM || entity->type == ENT_XPORB) pushOutOfBlocks(entity);
|
||||
if (hasFlag(getEntityInfo(entity->type), "livingbase")) {
|
||||
|
@ -1452,8 +1452,8 @@ void tick_entity(struct world* world, struct entity* entity) {
|
|||
damageEntity(entity, 4., 1);
|
||||
//TODO: fire
|
||||
}
|
||||
if (!entity->onGround) {
|
||||
float dy = entity->ly - entity->y;
|
||||
if (!entity->on_ground) {
|
||||
float dy = entity->last_y - entity->y;
|
||||
if (dy > 0.) {
|
||||
entity->fallDistance += dy;
|
||||
}
|
||||
|
@ -1467,8 +1467,8 @@ void tick_entity(struct world* world, struct entity* entity) {
|
|||
bfd: ;
|
||||
}
|
||||
if (entity->type != ENT_PLAYER) {
|
||||
double md = entity_distsq_block(entity, entity->lx, entity->ly, entity->lz);
|
||||
double mp = (entity->yaw - entity->lyaw) * (entity->yaw - entity->lyaw) + (entity->pitch - entity->lpitch) * (entity->pitch - entity->lpitch);
|
||||
double md = entity_distsq_block(entity, entity->last_x, entity->last_y, entity->last_z);
|
||||
double mp = (entity->yaw - entity->last_yaw) * (entity->yaw - entity->last_yaw) + (entity->pitch - entity->last_pitch) * (entity->pitch - entity->last_pitch);
|
||||
if (md > .001 || mp > .01) {
|
||||
BEGIN_HASHMAP_ITERATION(entity->loadingPlayers);
|
||||
player_send_entity_move(value, entity);
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#include <unistd.h>
|
||||
|
||||
struct inventory* inventory_new(struct mempool* pool, int type, int id, size_t slots, char* title) {
|
||||
struct inventory* inv = pcalloc(sizeof(struct inventory));
|
||||
struct inventory* inv = pcalloc(pool, sizeof(struct inventory));
|
||||
inv->pool = pool;
|
||||
inv->title = title;
|
||||
inv->slot_count = slots;
|
||||
|
@ -31,8 +31,8 @@ struct inventory* inventory_new(struct mempool* pool, int type, int id, size_t s
|
|||
inv->type = type;
|
||||
inv->window = id;
|
||||
inv->watching_players = hashmap_thread_new(8, inv->pool);
|
||||
pthread_rwlock_init(&inv->rwlock, NULL);
|
||||
phook(inv->pool, (void (*)(void*)) pthread_rwlock_destroy, &inv->rwlock);
|
||||
pthread_mutex_init(&inv->mutex, NULL);
|
||||
phook(inv->pool, (void (*)(void*)) pthread_mutex_destroy, &inv->mutex);
|
||||
return inv;
|
||||
}
|
||||
|
||||
|
|
|
@ -619,8 +619,8 @@ void onItemUse_bow(struct world* world, struct player* player, uint8_t slot_inde
|
|||
float sr = sqrtf(x * x + z * z);
|
||||
arrow->yaw = atan2f(x, z) * 180. / M_PI;
|
||||
arrow->pitch = atan2f(y, sr) * 180. / M_PI;
|
||||
arrow->lyaw = arrow->yaw;
|
||||
arrow->lpitch = arrow->pitch;
|
||||
arrow->last_yaw = arrow->yaw;
|
||||
arrow->last_pitch = arrow->pitch;
|
||||
//arrow->motX += player->entity->motX;
|
||||
//arrow->motZ += player->entity->motZ;
|
||||
//if (!player->entity->onGround) arrow->motY += player->entity->motY;
|
||||
|
|
|
@ -66,7 +66,7 @@ int work_joinServer(struct connection* conn, struct mempool* pool, char* usernam
|
|||
resp->data.play_client.joingame.dimension = conn->server->overworld->dimension;
|
||||
resp->data.play_client.joingame.difficulty = (uint8_t) conn->server->difficulty;
|
||||
resp->data.play_client.joingame.max_players = (uint8_t) conn->server->max_players;
|
||||
resp->data.play_client.joingame.level_type = conn->server->overworld->levelType;
|
||||
resp->data.play_client.joingame.level_type = conn->server->overworld->level_type;
|
||||
resp->data.play_client.joingame.reduced_debug_info = 0; // TODO
|
||||
if (packet_write(conn, resp) < 0) {
|
||||
return 1;
|
||||
|
|
49
src/player.c
49
src/player.c
|
@ -23,12 +23,13 @@
|
|||
#include <avuna/pmem.h>
|
||||
#include <math.h>
|
||||
|
||||
struct player* player_new(struct mempool* parent, struct conn* conn, struct world* world, struct entity* entity, char* name, struct uuid uuid, uint8_t gamemode) {
|
||||
struct player* player_new(struct mempool* parent, struct server* server, struct conn* conn, struct world* world, struct entity* entity, char* name, struct uuid uuid, uint8_t gamemode) {
|
||||
struct mempool* pool = mempool_new();
|
||||
pchild(parent, pool);
|
||||
struct player* player = pcalloc(pool, sizeof(struct player));
|
||||
player->pool = pool;
|
||||
player->conn = conn;
|
||||
player->server = server;
|
||||
player->conn = conn;
|
||||
player->world = world;
|
||||
player->entity = entity;
|
||||
player->name = name;
|
||||
|
@ -53,13 +54,13 @@ struct player* player_new(struct mempool* parent, struct conn* conn, struct worl
|
|||
}
|
||||
|
||||
void player_send_entity_move(struct player* player, struct entity* ent) {
|
||||
double md = entity_distsq_block(ent, ent->lx, ent->ly, ent->lz);
|
||||
double mp = (ent->yaw - ent->lyaw) * (ent->yaw - ent->lyaw) + (ent->pitch - ent->lpitch) * (ent->pitch - ent->lpitch);
|
||||
double md = entity_distsq_block(ent, ent->last_x, ent->last_y, ent->last_z);
|
||||
double mp = (ent->yaw - ent->last_yaw) * (ent->yaw - ent->last_yaw) + (ent->pitch - ent->last_pitch) * (ent->pitch - ent->last_pitch);
|
||||
|
||||
//printf("mp = %f, md = %f\n", mp, md);
|
||||
if ((md > .001 || mp > .01 || ent->type == ENT_PLAYER)) {
|
||||
struct packet* pkt = xmalloc(sizeof(struct packet));
|
||||
int ft = tick_counter % 200 == 0 || (ent->type == ENT_PLAYER && ent->data.player.player->lastTeleportID != 0);
|
||||
int ft = tick_counter % 200 == 0 || (ent->type == ENT_PLAYER && ent->data.player.player->last_teleport_id != 0);
|
||||
if (!ft && md <= .001 && mp <= .01) {
|
||||
pkt->id = PKT_PLAY_CLIENT_ENTITY;
|
||||
pkt->data.play_client.entity.entity_id = ent->id;
|
||||
|
@ -69,7 +70,7 @@ void player_send_entity_move(struct player* player, struct entity* ent) {
|
|||
pkt->data.play_client.entitylook.entity_id = ent->id;
|
||||
pkt->data.play_client.entitylook.yaw = (uint8_t)((ent->yaw / 360.) * 256.);
|
||||
pkt->data.play_client.entitylook.pitch = (uint8_t)((ent->pitch / 360.) * 256.);
|
||||
pkt->data.play_client.entitylook.on_ground = ent->onGround;
|
||||
pkt->data.play_client.entitylook.on_ground = ent->on_ground;
|
||||
add_queue(player->outgoing_packets, pkt);
|
||||
pkt = xmalloc(sizeof(struct packet));
|
||||
pkt->id = PKT_PLAY_CLIENT_ENTITYHEADLOOK;
|
||||
|
@ -79,20 +80,20 @@ void player_send_entity_move(struct player* player, struct entity* ent) {
|
|||
} else if (!ft && mp <= .01 && md > .001 && md < 64.) {
|
||||
pkt->id = PKT_PLAY_CLIENT_ENTITYRELATIVEMOVE;
|
||||
pkt->data.play_client.entityrelativemove.entity_id = ent->id;
|
||||
pkt->data.play_client.entityrelativemove.delta_x = (int16_t)((ent->x * 32. - ent->lx * 32.) * 128.);
|
||||
pkt->data.play_client.entityrelativemove.delta_y = (int16_t)((ent->y * 32. - ent->ly * 32.) * 128.);
|
||||
pkt->data.play_client.entityrelativemove.delta_z = (int16_t)((ent->z * 32. - ent->lz * 32.) * 128.);
|
||||
pkt->data.play_client.entityrelativemove.on_ground = ent->onGround;
|
||||
pkt->data.play_client.entityrelativemove.delta_x = (int16_t)((ent->x * 32. - ent->last_x * 32.) * 128.);
|
||||
pkt->data.play_client.entityrelativemove.delta_y = (int16_t)((ent->y * 32. - ent->last_y * 32.) * 128.);
|
||||
pkt->data.play_client.entityrelativemove.delta_z = (int16_t)((ent->z * 32. - ent->last_z * 32.) * 128.);
|
||||
pkt->data.play_client.entityrelativemove.on_ground = ent->on_ground;
|
||||
add_queue(player->outgoing_packets, pkt);
|
||||
} else if (!ft && mp > .01 && md > .001 && md < 64.) {
|
||||
pkt->id = PKT_PLAY_CLIENT_ENTITYLOOKANDRELATIVEMOVE;
|
||||
pkt->data.play_client.entitylookandrelativemove.entity_id = ent->id;
|
||||
pkt->data.play_client.entitylookandrelativemove.delta_x = (int16_t)((ent->x * 32. - ent->lx * 32.) * 128.);
|
||||
pkt->data.play_client.entitylookandrelativemove.delta_y = (int16_t)((ent->y * 32. - ent->ly * 32.) * 128.);
|
||||
pkt->data.play_client.entitylookandrelativemove.delta_z = (int16_t)((ent->z * 32. - ent->lz * 32.) * 128.);
|
||||
pkt->data.play_client.entitylookandrelativemove.delta_x = (int16_t)((ent->x * 32. - ent->last_x * 32.) * 128.);
|
||||
pkt->data.play_client.entitylookandrelativemove.delta_y = (int16_t)((ent->y * 32. - ent->last_y * 32.) * 128.);
|
||||
pkt->data.play_client.entitylookandrelativemove.delta_z = (int16_t)((ent->z * 32. - ent->last_z * 32.) * 128.);
|
||||
pkt->data.play_client.entitylookandrelativemove.yaw = (uint8_t)((ent->yaw / 360.) * 256.);
|
||||
pkt->data.play_client.entitylookandrelativemove.pitch = (uint8_t)((ent->pitch / 360.) * 256.);
|
||||
pkt->data.play_client.entitylookandrelativemove.on_ground = ent->onGround;
|
||||
pkt->data.play_client.entitylookandrelativemove.on_ground = ent->on_ground;
|
||||
add_queue(player->outgoing_packets, pkt);
|
||||
pkt = xmalloc(sizeof(struct packet));
|
||||
pkt->id = PKT_PLAY_CLIENT_ENTITYHEADLOOK;
|
||||
|
@ -107,7 +108,7 @@ void player_send_entity_move(struct player* player, struct entity* ent) {
|
|||
pkt->data.play_client.entityteleport.z = ent->z;
|
||||
pkt->data.play_client.entityteleport.yaw = (uint8_t)((ent->yaw / 360.) * 256.);
|
||||
pkt->data.play_client.entityteleport.pitch = (uint8_t)((ent->pitch / 360.) * 256.);
|
||||
pkt->data.play_client.entityteleport.on_ground = ent->onGround;
|
||||
pkt->data.play_client.entityteleport.on_ground = ent->on_ground;
|
||||
add_queue(player->outgoing_packets, pkt);
|
||||
pkt = xmalloc(sizeof(struct packet));
|
||||
pkt->id = PKT_PLAY_CLIENT_ENTITYHEADLOOK;
|
||||
|
@ -161,10 +162,10 @@ void player_tick(struct world* world, struct player* player) {
|
|||
add_queue(player->outgoing_packets, pkt);
|
||||
}
|
||||
if (player->gamemode != 1 && player->gamemode != 3) {
|
||||
float dt = entity_dist_block(player->entity, player->entity->lx, player->entity->ly, player->entity->lz);
|
||||
float dt = entity_dist_block(player->entity, player->entity->last_x, player->entity->last_y, player->entity->last_z);
|
||||
if (dt > 0.) {
|
||||
if (player->entity->inWater) player->foodExhaustion += .01 * dt;
|
||||
else if (player->entity->onGround) {
|
||||
else if (player->entity->on_ground) {
|
||||
if (player->entity->sprinting) player->foodExhaustion += .1 * dt;
|
||||
}
|
||||
}
|
||||
|
@ -205,8 +206,8 @@ void player_tick(struct world* world, struct player* player) {
|
|||
beginProfilerSection("chunks");
|
||||
int32_t pcx = ((int32_t) player->entity->x >> 4);
|
||||
int32_t pcz = ((int32_t) player->entity->z >> 4);
|
||||
int32_t lpcx = ((int32_t) player->entity->lx >> 4);
|
||||
int32_t lpcz = ((int32_t) player->entity->lz >> 4);
|
||||
int32_t lpcx = ((int32_t) player->entity->last_x >> 4);
|
||||
int32_t lpcz = ((int32_t) player->entity->last_z >> 4);
|
||||
if (player->loaded_chunks->entry_count == 0 || player->triggerRechunk) { // || tick_counter % 200 == 0
|
||||
beginProfilerSection("chunkLoading_tick");
|
||||
pthread_mutex_lock(&player->chunkRequests->data_mutex);
|
||||
|
@ -340,7 +341,7 @@ void player_tick(struct world* world, struct player* player) {
|
|||
}
|
||||
}
|
||||
//if in water and not in aqua affintity enchant ds /= 5.;
|
||||
if (!player->entity->onGround) ds /= 5.;
|
||||
if (!player->entity->on_ground) ds /= 5.;
|
||||
digspeed = ds / (bi->hardness * ((hasProperTool || rnt) ? 30. : 100.));
|
||||
}
|
||||
player->digging += (player->digging == 0. ? 2. : 1.) * digspeed;
|
||||
|
@ -468,9 +469,9 @@ void player_teleport(struct player* player, double x, double y, double z) {
|
|||
player->entity->x = x;
|
||||
player->entity->y = y;
|
||||
player->entity->z = z;
|
||||
player->entity->lx = x;
|
||||
player->entity->ly = y;
|
||||
player->entity->lz = z;
|
||||
player->entity->last_x = x;
|
||||
player->entity->last_y = y;
|
||||
player->entity->last_z = z;
|
||||
player->triggerRechunk = 1;
|
||||
player->spawnedIn = 0;
|
||||
struct packet* pkt = xmalloc(sizeof(struct packet));
|
||||
|
@ -489,7 +490,7 @@ void player_teleport(struct player* player, double x, double y, double z) {
|
|||
pkt->data.play_client.playerpositionandlook.pitch = player->entity->pitch;
|
||||
pkt->data.play_client.playerpositionandlook.flags = 0x0;
|
||||
pkt->data.play_client.playerpositionandlook.teleport_id = tick_counter;
|
||||
player->lastTeleportID = pkt->data.play_client.playerpositionandlook.teleport_id;
|
||||
player->last_teleport_id = pkt->data.play_client.playerpositionandlook.teleport_id;
|
||||
add_queue(player->outgoing_packets, pkt);
|
||||
/*BEGIN_HASHMAP_ITERATION(player->entity->loadingPlayers)
|
||||
struct player* bp = value;
|
||||
|
|
1982
src/player_packet.c
1982
src/player_packet.c
File diff suppressed because it is too large
Load Diff
|
@ -800,7 +800,7 @@ int world_load(struct world* world, char* path) {
|
|||
if (nbt_read(world->pool, &world->level, decompressed_level, (size_t) decompressed_size) < 0) return -1;
|
||||
pprefree(world->pool, decompressed_level);
|
||||
struct nbt_tag* data = nbt_get(world->level, "Data");
|
||||
world->levelType = nbt_get(data, "generatorName")->data.nbt_string;
|
||||
world->level_type = nbt_get(data, "generatorName")->data.nbt_string;
|
||||
world->spawnpos.x = nbt_get(data, "SpawnX")->data.nbt_int;
|
||||
world->spawnpos.y = nbt_get(data, "SpawnY")->data.nbt_int;
|
||||
world->spawnpos.z = nbt_get(data, "SpawnZ")->data.nbt_int;
|
||||
|
|
Loading…
Reference in New Issue