mirror of https://github.com/basinserver/basin/
rename player functions
This commit is contained in:
parent
9b71e664a1
commit
efd1e79798
|
@ -57,7 +57,6 @@ struct player {
|
|||
uint8_t spawnedIn;
|
||||
size_t llTick;
|
||||
uint8_t triggerRechunk;
|
||||
uint32_t protocol_version;
|
||||
uint16_t chunksSent;
|
||||
float reachDistance;
|
||||
acstate_t acstate;
|
||||
|
@ -68,15 +67,15 @@ struct player {
|
|||
|
||||
void player_hungerUpdate(struct player* player);
|
||||
|
||||
void sendEntityMove(struct player* player, struct entity* ent);
|
||||
void player_send_entity_move(struct player* player, struct entity* ent);
|
||||
|
||||
struct player* newPlayer(struct entity* entity, char* name, struct uuid, struct conn* conn, uint8_t gamemode);
|
||||
struct player* player_new(struct entity* entity, char* name, struct uuid uuid, struct conn* conn, uint8_t gamemode);
|
||||
|
||||
void player_receive_packet(struct player* player, struct packet* inp);
|
||||
|
||||
void tick_player(struct world* world, struct player* player);
|
||||
void player_tick(struct world* world, struct player* player);
|
||||
|
||||
void kickPlayer(struct player* player, char* message);
|
||||
void player_kick(struct player* player, char* message);
|
||||
|
||||
int player_onGround(struct player* player);
|
||||
|
||||
|
@ -84,14 +83,14 @@ void player_closeWindow(struct player* player, uint16_t windowID);
|
|||
|
||||
float player_getAttackStrength(struct player* player, float adjust);
|
||||
|
||||
void teleportPlayer(struct player* player, double x, double y, double z);
|
||||
void player_teleport(struct player* player, double x, double y, double z);
|
||||
|
||||
struct player* getPlayerByName(char* name);
|
||||
struct player* player_get_by_name(char* name);
|
||||
|
||||
void setPlayerGamemode(struct player* player, int gamemode);
|
||||
void player_set_gamemode(struct player* player, int gamemode);
|
||||
|
||||
void freePlayer(struct player* player);
|
||||
void player_free(struct player* player);
|
||||
|
||||
block canPlayerPlaceBlock(struct player* player, uint16_t blk, int32_t x, int32_t y, int32_t z, uint8_t face);
|
||||
block player_can_place_block(struct player* player, uint16_t blk, int32_t x, int32_t y, int32_t z, uint8_t face);
|
||||
|
||||
#endif /* PLAYER_H_ */
|
||||
|
|
|
@ -12,7 +12,7 @@ int ac_chat(struct player* player, char* msg) {
|
|||
|
||||
for (char* p = msg; *p; p++) {
|
||||
if (*p < 32 || *p == 127 || *p == 0xA7) {
|
||||
kickPlayer(player, "Invalid chat message");
|
||||
player_kick(player, "Invalid chat message");
|
||||
AC_END(1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,15 +22,15 @@ void command_gamemode(struct player* player, char** args, size_t args_count) {
|
|||
return;
|
||||
}
|
||||
struct player* target = player;
|
||||
if (args_count == 2) target = getPlayerByName(args[1]);
|
||||
if (args_count == 2) target = player_get_by_name(args[1]);
|
||||
if (target == NULL) {
|
||||
sendMessageToPlayer(player, "[ERROR] No such player found.", "red");
|
||||
return;
|
||||
}
|
||||
if (streq_nocase(args[0], "0") || streq_nocase(args[0], "survival")) {
|
||||
setPlayerGamemode(target, 0);
|
||||
player_set_gamemode(target, 0);
|
||||
} else if (streq_nocase(args[0], "1") || streq_nocase(args[0], "creative")) {
|
||||
setPlayerGamemode(target, 1);
|
||||
player_set_gamemode(target, 1);
|
||||
} else {
|
||||
sendMessageToPlayer(target, "[ERROR] No such gamemode found.", "red");
|
||||
return;
|
||||
|
@ -45,16 +45,16 @@ void command_tp(struct player* player, char** args, size_t args_count) {
|
|||
return;
|
||||
}
|
||||
if (args_count >= 3) {
|
||||
struct player* from = args_count == 3 ? player : getPlayerByName(args[0]);
|
||||
struct player* from = args_count == 3 ? player : player_get_by_name(args[0]);
|
||||
if (from == NULL) {
|
||||
sendMessageToPlayer(player, "[ERROR] No such player found.", "red");
|
||||
return;
|
||||
}
|
||||
int32_t ai = args_count == 4 ? 1 : 0;
|
||||
teleportPlayer(from, strtol(args[ai++], NULL, 10), strtol(args[ai++], NULL, 10), strtol(args[ai++], NULL, 10));
|
||||
player_teleport(from, strtol(args[ai++], NULL, 10), strtol(args[ai++], NULL, 10), strtol(args[ai++], NULL, 10));
|
||||
} else {
|
||||
struct player* from = args_count == 1 ? player : getPlayerByName(args[0]);
|
||||
struct player* to = args_count == 1 ? getPlayerByName(args[0]) : getPlayerByName(args[1]);
|
||||
struct player* from = args_count == 1 ? player : player_get_by_name(args[0]);
|
||||
struct player* to = args_count == 1 ? player_get_by_name(args[0]) : player_get_by_name(args[1]);
|
||||
if (from == NULL || to == NULL) {
|
||||
sendMessageToPlayer(player, "[ERROR] No such player found.", "red");
|
||||
return;
|
||||
|
@ -63,7 +63,7 @@ void command_tp(struct player* player, char** args, size_t args_count) {
|
|||
sendMessageToPlayer(player, "[ERROR] Players in different worlds!", "red");
|
||||
return;
|
||||
}
|
||||
teleportPlayer(from, to->entity->x, to->entity->y, to->entity->z);
|
||||
player_teleport(from, to->entity->x, to->entity->y, to->entity->z);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -73,13 +73,13 @@ void command_kick(struct player* player, char** args, size_t args_count) {
|
|||
sendMessageToPlayer(player, "Usage: /kick <player> OR /kick <player> \"<reason>\"", "red");
|
||||
return;
|
||||
}
|
||||
struct player* target = getPlayerByName(args[0]);
|
||||
struct player* target = player_get_by_name(args[0]);
|
||||
if (target == NULL) {
|
||||
sendMessageToPlayer(player, "[ERROR] No such player found.", "red");
|
||||
return;
|
||||
}
|
||||
char* reason = args_count == 1 ? "You have been kicked" : args[1];
|
||||
kickPlayer(target, reason);
|
||||
player_kick(target, reason);
|
||||
}
|
||||
|
||||
void command_say(struct player* player, char** args, size_t args_count) {
|
||||
|
@ -132,7 +132,8 @@ void command_spawn(struct player* player, char** args, size_t args_count) {
|
|||
sendMessageToPlayer(player, "red", "Usage: /spawn");
|
||||
return;
|
||||
}
|
||||
teleportPlayer(player, (double) player->world->spawnpos.x + .5, (double) player->world->spawnpos.y, (double) player->world->spawnpos.z + .5);
|
||||
player_teleport(player, (double) player->world->spawnpos.x + .5, (double) player->world->spawnpos.y,
|
||||
(double) player->world->spawnpos.z + .5);
|
||||
}
|
||||
|
||||
void command_printprofile(struct player* player, char** args, size_t args_count) {
|
||||
|
@ -151,7 +152,7 @@ void command_kill(struct player* player, char** args, size_t args_count) {
|
|||
sendMsgToPlayerf(player, "red", "Usage: /kill <player>");
|
||||
return;
|
||||
}
|
||||
player = getPlayerByName(args[0]);
|
||||
player = player_get_by_name(args[0]);
|
||||
if (player == NULL) {
|
||||
sendMessageToPlayer(player, "[ERROR] No such player found.", "red");
|
||||
return;
|
||||
|
|
|
@ -1471,7 +1471,7 @@ void tick_entity(struct world* world, struct entity* entity) {
|
|||
double mp = (entity->yaw - entity->lyaw) * (entity->yaw - entity->lyaw) + (entity->pitch - entity->lpitch) * (entity->pitch - entity->lpitch);
|
||||
if (md > .001 || mp > .01) {
|
||||
BEGIN_HASHMAP_ITERATION(entity->loadingPlayers);
|
||||
sendEntityMove(value, entity);
|
||||
player_send_entity_move(value, entity);
|
||||
END_HASHMAP_ITERATION(entity->loadingPlayers);
|
||||
}
|
||||
}
|
||||
|
|
28
src/item.c
28
src/item.c
|
@ -36,8 +36,8 @@ int onItemInteract_bed(struct world* world, struct player* player, uint8_t slot_
|
|||
block b = BLK_BED | h;
|
||||
block b2 = b;
|
||||
b2 |= 0b1000;
|
||||
if (canPlayerPlaceBlock(player, b, x, y, z, face) && !setBlockWorld_noupdate(player->world, b, x, y, z)) {
|
||||
if (!canPlayerPlaceBlock(player, b2, x2, y2, z2, face) || setBlockWorld(player->world, b2, x2, y2, z2)) {
|
||||
if (player_can_place_block(player, b, x, y, z, face) && !setBlockWorld_noupdate(player->world, b, x, y, z)) {
|
||||
if (!player_can_place_block(player, b2, x2, y2, z2, face) || setBlockWorld(player->world, b2, x2, y2, z2)) {
|
||||
setBlockWorld(player->world, pre, x, y, z);
|
||||
setBlockWorld(player->world, pre2, x2, y2, z2);
|
||||
setSlot(player, player->inventory, 36 + player->currentItem, slot, 1, 1);
|
||||
|
@ -68,7 +68,7 @@ int onItemInteract_painting(struct world* world, struct player* player, uint8_t
|
|||
int32_t oy = y;
|
||||
int32_t oz = z;
|
||||
offsetCoordByFace(&ox, &oy, &oz, face);
|
||||
if (face != YP && face != YN && canPlayerPlaceBlock(player, ITM_PAINTING, ox, oy, oz, face)) {
|
||||
if (face != YP && face != YN && player_can_place_block(player, ITM_PAINTING, ox, oy, oz, face)) {
|
||||
struct entity* ent = newEntity(nextEntityID++, (double) ox, (double) oy, (double) oz, ENT_PAINTING, 0., 0.);
|
||||
if (face == NORTH) ent->data.painting.direction = 2;
|
||||
if (face == SOUTH) ent->data.painting.direction = 0;
|
||||
|
@ -219,8 +219,8 @@ int onItemInteract_door(struct world* world, struct player* player, uint8_t slot
|
|||
b2 |= 0x01;
|
||||
}
|
||||
b2 |= 0b1000;
|
||||
if (canPlayerPlaceBlock(player, b, x, y, z, face) && !setBlockWorld_noupdate(player->world, b, x, y, z)) {
|
||||
if (!canPlayerPlaceBlock(player, b2, x, y + 1, z, face) || setBlockWorld(player->world, b2, x, y + 1, z)) {
|
||||
if (player_can_place_block(player, b, x, y, z, face) && !setBlockWorld_noupdate(player->world, b, x, y, z)) {
|
||||
if (!player_can_place_block(player, b2, x, y + 1, z, face) || setBlockWorld(player->world, b2, x, y + 1, z)) {
|
||||
setBlockWorld(player->world, pre, x, y, z);
|
||||
setBlockWorld(player->world, pre2, x, y + 1, z);
|
||||
setSlot(player, player->inventory, 36 + player->currentItem, slot, 1, 1);
|
||||
|
@ -282,7 +282,7 @@ int onItemInteract_itemblock(struct world* world, struct player* player, uint8_t
|
|||
} else if (slot->item == ITM_COMPARATOR) {
|
||||
b = BLK_COMPARATOR;
|
||||
}
|
||||
if (canPlayerPlaceBlock(player, b, x, y, z, face)) {
|
||||
if (player_can_place_block(player, b, x, y, z, face)) {
|
||||
if (setBlockWorld(player->world, b, x, y, z)) {
|
||||
setBlockWorld(player->world, pre, x, y, z);
|
||||
setSlot(player, player->inventory, 36 + player->currentItem, slot, 1, 1);
|
||||
|
@ -334,7 +334,7 @@ int onItemInteract_flintandsteel(struct world* world, struct player* player, uin
|
|||
if (slot == NULL) return 0;
|
||||
offsetCoordByFace(&x, &y, &z, face);
|
||||
if (getBlockWorld(world, x, y, z) != 0) return 0;
|
||||
if (!canPlayerPlaceBlock(player, BLK_FIRE, x, y, z, face)) return 0;
|
||||
if (!player_can_place_block(player, BLK_FIRE, x, y, z, face)) return 0;
|
||||
struct item_info* ii = getItemInfo(slot->item);
|
||||
if (ii == NULL) return 0;
|
||||
if (player->gamemode != 1 && ++slot->damage >= ii->maxDamage) {
|
||||
|
@ -369,7 +369,7 @@ int onItemInteract_spawnegg(struct world* world, struct player* player, uint8_t
|
|||
int onItemInteract_reeds(struct world* world, struct player* player, uint8_t slot_index, struct slot* slot, int32_t x, int32_t y, int32_t z, uint8_t face) {
|
||||
if (slot == NULL) return 0;
|
||||
if (!getBlockInfo(getBlockWorld(world, x, y, z))->material->replacable) offsetCoordByFace(&x, &y, &z, face);
|
||||
if (!canPlayerPlaceBlock(player, BLK_REEDS, x, y, z, face)) return 0;
|
||||
if (!player_can_place_block(player, BLK_REEDS, x, y, z, face)) return 0;
|
||||
if (getBlockWorld(world, x, y, z) != 0) return 0;
|
||||
if (!canBePlaced_reeds(world, BLK_REEDS, x, y, z)) return 0;
|
||||
struct item_info* ii = getItemInfo(slot->item);
|
||||
|
@ -391,7 +391,7 @@ int onItemInteract_bucket(struct world* world, struct player* player, uint8_t sl
|
|||
uint16_t ba = b >> 4;
|
||||
if (slot->item == ITM_BUCKETWATER) {
|
||||
if (b != 0 && !bi->material->replacable && ba != BLK_WATER >> 4 && ba != BLK_WATER_1 >> 4) return 0;
|
||||
if (!canPlayerPlaceBlock(player, BLK_WATER_1, x, y, z, face)) return 0;
|
||||
if (!player_can_place_block(player, BLK_WATER_1, x, y, z, face)) return 0;
|
||||
setBlockWorld(world, BLK_WATER_1, x, y, z);
|
||||
if (player->gamemode != 1) {
|
||||
slot->item = ITM_BUCKET;
|
||||
|
@ -399,7 +399,7 @@ int onItemInteract_bucket(struct world* world, struct player* player, uint8_t sl
|
|||
}
|
||||
} else if (slot->item == ITM_BUCKETLAVA) {
|
||||
if (b != 0 && !bi->material->replacable && ba != BLK_LAVA >> 4 && ba != BLK_LAVA_1 >> 4) return 0;
|
||||
if (!canPlayerPlaceBlock(player, BLK_LAVA_1, x, y, z, face)) return 0;
|
||||
if (!player_can_place_block(player, BLK_LAVA_1, x, y, z, face)) return 0;
|
||||
setBlockWorld(world, BLK_LAVA_1, x, y, z);
|
||||
if (player->gamemode != 1) {
|
||||
slot->item = ITM_BUCKET;
|
||||
|
@ -426,7 +426,7 @@ int onItemInteract_bucket(struct world* world, struct player* player, uint8_t sl
|
|||
|
||||
int onItemInteract_bonemeal(struct world* world, struct player* player, uint8_t slot_index, struct slot* slot, int32_t x, int32_t y, int32_t z, uint8_t face) {
|
||||
if (slot == NULL) return 0;
|
||||
if (!canPlayerPlaceBlock(player, ITM_DYEPOWDER_BLACK, x, y, z, face)) return 0;
|
||||
if (!player_can_place_block(player, ITM_DYEPOWDER_BLACK, x, y, z, face)) return 0;
|
||||
block b = getBlockWorld(world, x, y, z);
|
||||
uint16_t ba = b >> 4;
|
||||
if (ba == (BLK_CROPS >> 4) || (ba == BLK_PUMPKINSTEM >> 4) || (ba == BLK_PUMPKINSTEM_1 >> 4) || (ba == BLK_CARROTS >> 4) || (ba == BLK_POTATOES >> 4) || (ba == BLK_BEETROOTS >> 4) || (ba == BLK_COCOA >> 4)) {
|
||||
|
@ -483,7 +483,7 @@ int onItemInteract_bonemeal(struct world* world, struct player* player, uint8_t
|
|||
int onItemInteract_seeds(struct world* world, struct player* player, uint8_t slot_index, struct slot* slot, int32_t x, int32_t y, int32_t z, uint8_t face) {
|
||||
if (slot == NULL) return 0;
|
||||
if (!getBlockInfo(getBlockWorld(world, x, y, z))->material->replacable) offsetCoordByFace(&x, &y, &z, face);
|
||||
if (!canPlayerPlaceBlock(player, ITM_DYEPOWDER_BLACK, x, y, z, face)) return 0;
|
||||
if (!player_can_place_block(player, ITM_DYEPOWDER_BLACK, x, y, z, face)) return 0;
|
||||
block b = getBlockWorld(world, x, y, z);
|
||||
if (slot->item == ITM_DYEPOWDER_BLACK) {
|
||||
if (slot->damage == 3 && (face == 1 || face == 0 || b != BLK_LOG_JUNGLE)) return 0;
|
||||
|
@ -515,7 +515,7 @@ int onItemInteract_hoe(struct world* world, struct player* player, uint8_t slot_
|
|||
if (ii == NULL) return 0;
|
||||
block b = getBlockWorld(world, x, y, z);
|
||||
if (b == BLK_DIRT || b == BLK_GRASS) {
|
||||
if (!canPlayerPlaceBlock(player, slot->item, x, y, z, face)) return 0;
|
||||
if (!player_can_place_block(player, slot->item, x, y, z, face)) return 0;
|
||||
if (player->gamemode != 1 && ++slot->damage >= ii->maxDamage) {
|
||||
slot = NULL;
|
||||
}
|
||||
|
@ -531,7 +531,7 @@ int onItemInteract_shovel(struct world* world, struct player* player, uint8_t sl
|
|||
if (ii == NULL) return 0;
|
||||
block b = getBlockWorld(world, x, y, z);
|
||||
if (b == BLK_GRASS) {
|
||||
if (!canPlayerPlaceBlock(player, slot->item, x, y, z, face)) return 0;
|
||||
if (!player_can_place_block(player, slot->item, x, y, z, face)) return 0;
|
||||
if (player->gamemode != 1 && ++slot->damage >= ii->maxDamage) {
|
||||
slot = NULL;
|
||||
}
|
||||
|
|
|
@ -55,7 +55,8 @@ int work_joinServer(struct connection* conn, struct mempool* pool, char* usernam
|
|||
}
|
||||
conn->protocol_state = STATE_PLAY;
|
||||
struct entity* ep = newEntity(nextEntityID++, (double) conn->server->overworld->spawnpos.x + .5, (double) conn->server->overworld->spawnpos.y, (double) conn->server->overworld->spawnpos.z + .5, ENT_PLAYER, 0., 0.);
|
||||
struct player* player = newPlayer(ep, str_dup(resp->data.login_client.loginsuccess.username, 1, pool), uuid, conn, 0); // TODO default gamemode
|
||||
struct player* player = player_new(ep, str_dup(resp->data.login_client.loginsuccess.username, 1, pool), uuid, conn,
|
||||
0); // TODO default gamemode
|
||||
player->protocol_version = conn->protocol_version;
|
||||
conn->player = player;
|
||||
hashmap_putint(conn->server->players_by_entity_id, (uint64_t) player->entity->id, player);
|
||||
|
@ -326,7 +327,7 @@ int handle_encryption_response(struct connection* conn, struct packet* packet) {
|
|||
ITER_MAP(conn->server->players_by_entity_id) {
|
||||
struct player* player = (struct player*) value;
|
||||
if (str_eq(name, player->name)) {
|
||||
kickPlayer(player, "You have logged in from another location!");
|
||||
player_kick(player, "You have logged in from another location!");
|
||||
goto post_map_iteration;
|
||||
}
|
||||
ITER_MAP_END();
|
||||
|
|
|
@ -66,7 +66,7 @@ void main_tick() {
|
|||
if (def == NULL) continue;
|
||||
if (def->defunct++ >= 21) {
|
||||
freeEntity(def->entity);
|
||||
freePlayer(def);
|
||||
player_free(def);
|
||||
defunctPlayers->data[i] = NULL;
|
||||
defunctPlayers->count--;
|
||||
if (i == defunctPlayers->size - 1) defunctPlayers->size--;
|
||||
|
|
43
src/player.c
43
src/player.c
|
@ -22,7 +22,7 @@
|
|||
#include <avuna/string.h>
|
||||
#include <math.h>
|
||||
|
||||
struct player* newPlayer(struct entity* entity, char* name, struct uuid uuid, struct conn* conn, uint8_t gamemode) {
|
||||
struct player* player_new(struct entity* entity, char* name, struct uuid uuid, struct conn* conn, uint8_t gamemode) {
|
||||
struct player* player = xmalloc(sizeof(struct player));
|
||||
entity->data.player.player = player;
|
||||
player->entity = entity;
|
||||
|
@ -79,7 +79,7 @@ struct player* newPlayer(struct entity* entity, char* name, struct uuid uuid, st
|
|||
return player;
|
||||
}
|
||||
|
||||
void sendEntityMove(struct player* player, struct entity* ent) {
|
||||
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);
|
||||
|
||||
|
@ -181,7 +181,7 @@ void player_receive_packet(struct player* player, struct packet* inp) {
|
|||
player->entity->lpitch = player->entity->pitch;
|
||||
player->entity->onGround = pkt.on_ground;
|
||||
BEGIN_BROADCAST(player->entity->loadingPlayers)
|
||||
sendEntityMove(bc_player, player->entity);
|
||||
player_send_entity_move(bc_player, player->entity);
|
||||
END_BROADCAST(player->entity->loadingPlayers)
|
||||
} else if (inp->id == PKT_PLAY_SERVER_PLAYERPOSITION) {
|
||||
if (player->lastTeleportID != 0) goto cont;
|
||||
|
@ -198,7 +198,7 @@ void player_receive_packet(struct player* player, struct packet* inp) {
|
|||
double my = pkt.feet_y - ly;
|
||||
double mz = pkt.z - lz;
|
||||
if (moveEntity(player->entity, &mx, &my, &mz, .05)) {
|
||||
teleportPlayer(player, lx, ly, lz);
|
||||
player_teleport(player, lx, ly, lz);
|
||||
} else {
|
||||
player->entity->lx = lx;
|
||||
player->entity->ly = ly;
|
||||
|
@ -211,11 +211,11 @@ void player_receive_packet(struct player* player, struct packet* inp) {
|
|||
float d3 = dx * dx + dy * dy + dz * dz;
|
||||
if (!player->spawnedIn && d3 > 0.00000001) player->spawnedIn = 1;
|
||||
if (d3 > 5. * 5. * 5.) {
|
||||
teleportPlayer(player, player->entity->lx, player->entity->ly, player->entity->lz);
|
||||
kickPlayer(player, "You attempted to move too fast!");
|
||||
player_teleport(player, player->entity->lx, player->entity->ly, player->entity->lz);
|
||||
player_kick(player, "You attempted to move too fast!");
|
||||
} else {
|
||||
BEGIN_BROADCAST(player->entity->loadingPlayers)
|
||||
sendEntityMove(bc_player, player->entity);
|
||||
player_send_entity_move(bc_player, player->entity);
|
||||
END_BROADCAST(player->entity->loadingPlayers)
|
||||
}
|
||||
} else if (inp->id == PKT_PLAY_SERVER_PLAYERLOOK) {
|
||||
|
@ -233,7 +233,7 @@ void player_receive_packet(struct player* player, struct packet* inp) {
|
|||
player->entity->yaw = pkt.yaw;
|
||||
player->entity->pitch = pkt.pitch;
|
||||
BEGIN_BROADCAST(player->entity->loadingPlayers)
|
||||
sendEntityMove(bc_player, player->entity);
|
||||
player_send_entity_move(bc_player, player->entity);
|
||||
END_BROADCAST(player->entity->loadingPlayers)
|
||||
} else if (inp->id == PKT_PLAY_SERVER_PLAYERPOSITIONANDLOOK) {
|
||||
if (player->lastTeleportID != 0) goto cont;
|
||||
|
@ -250,7 +250,7 @@ void player_receive_packet(struct player* player, struct packet* inp) {
|
|||
double my = pkt.feet_y - ly;
|
||||
double mz = pkt.z - lz;
|
||||
if (moveEntity(player->entity, &mx, &my, &mz, .05)) {
|
||||
teleportPlayer(player, lx, ly, lz);
|
||||
player_teleport(player, lx, ly, lz);
|
||||
} else {
|
||||
player->entity->lx = lx;
|
||||
player->entity->ly = ly;
|
||||
|
@ -265,11 +265,11 @@ void player_receive_packet(struct player* player, struct packet* inp) {
|
|||
float d3 = dx * dx + dy * dy + dz * dz;
|
||||
if (!player->spawnedIn && d3 > 0.00000001) player->spawnedIn = 1;
|
||||
if (d3 > 5. * 5. * 5.) {
|
||||
teleportPlayer(player, player->entity->lx, player->entity->ly, player->entity->lz);
|
||||
player_teleport(player, player->entity->lx, player->entity->ly, player->entity->lz);
|
||||
printf("Player '%s' attempted to move too fast!\n", player->name);
|
||||
} else {
|
||||
BEGIN_BROADCAST(player->entity->loadingPlayers)
|
||||
sendEntityMove(bc_player, player->entity);
|
||||
player_send_entity_move(bc_player, player->entity);
|
||||
END_BROADCAST(player->entity->loadingPlayers)
|
||||
}
|
||||
} else if (inp->id == PKT_PLAY_SERVER_ANIMATION) {
|
||||
|
@ -531,7 +531,7 @@ void player_receive_packet(struct player* player, struct packet* inp) {
|
|||
//}
|
||||
//}
|
||||
if (!bad) {
|
||||
if ((tbb = canPlayerPlaceBlock(player, tbb, x, y, z, face))) {
|
||||
if ((tbb = player_can_place_block(player, tbb, x, y, z, face))) {
|
||||
if (setBlockWorld(player->world, tbb, x, y, z)) {
|
||||
setBlockWorld(player->world, b2, x, y, z);
|
||||
setSlot(player, player->inventory, 36 + player->currentItem, ci, 1, 1);
|
||||
|
@ -1051,8 +1051,9 @@ void player_receive_packet(struct player* player, struct packet* inp) {
|
|||
pkt->data.play_client.respawn.gamemode = player->gamemode;
|
||||
pkt->data.play_client.respawn.level_type = xstrdup(player->world->levelType, 0);
|
||||
add_queue(player->outgoingPacket, pkt);
|
||||
teleportPlayer(player, (double) player->world->spawnpos.x + .5, (double) player->world->spawnpos.y, (double) player->world->spawnpos.z + .5); // TODO: make overworld
|
||||
setPlayerGamemode(player, -1);
|
||||
player_teleport(player, (double) player->world->spawnpos.x + .5, (double) player->world->spawnpos.y,
|
||||
(double) player->world->spawnpos.z + .5); // TODO: make overworld
|
||||
player_set_gamemode(player, -1);
|
||||
BEGIN_HASHMAP_ITERATION (plugins)
|
||||
struct plugin* plugin = value;
|
||||
if (plugin->onPlayerSpawn != NULL) (*plugin->onPlayerSpawn)(player->world, player);
|
||||
|
@ -1092,7 +1093,7 @@ void player_hungerUpdate(struct player* player) {
|
|||
add_queue(player->outgoingPacket, pkt);
|
||||
}
|
||||
|
||||
void tick_player(struct world* world, struct player* player) {
|
||||
void player_tick(struct world* world, struct player* player) {
|
||||
if (player->defunct) {
|
||||
put_hashmap(players, player->entity->id, NULL);
|
||||
BEGIN_BROADCAST (players)
|
||||
|
@ -1403,7 +1404,7 @@ int player_onGround(struct player* player) {
|
|||
return fabs(-.08 - ny) > .001;
|
||||
}
|
||||
|
||||
void kickPlayer(struct player* player, char* message) {
|
||||
void player_kick(struct player* player, char* message) {
|
||||
struct packet* pkt = xmalloc(sizeof(struct packet));
|
||||
pkt->id = PKT_PLAY_CLIENT_DISCONNECT;
|
||||
size_t sl = strlen(message);
|
||||
|
@ -1429,7 +1430,7 @@ float player_getAttackStrength(struct player* player, float adjust) {
|
|||
return str;
|
||||
}
|
||||
|
||||
void teleportPlayer(struct player* player, double x, double y, double z) {
|
||||
void player_teleport(struct player* player, double x, double y, double z) {
|
||||
player->entity->x = x;
|
||||
player->entity->y = y;
|
||||
player->entity->z = z;
|
||||
|
@ -1484,7 +1485,7 @@ void teleportPlayer(struct player* player, double x, double y, double z) {
|
|||
// if (player->tps > 0) player->tps--;
|
||||
}
|
||||
|
||||
struct player* getPlayerByName(char* name) {
|
||||
struct player* player_get_by_name(char* name) {
|
||||
BEGIN_HASHMAP_ITERATION (players)
|
||||
struct player* player = (struct player*) value;
|
||||
if (player != NULL && streq_nocase(name, player->name)) {
|
||||
|
@ -1548,7 +1549,7 @@ void player_closeWindow(struct player* player, uint16_t windowID) {
|
|||
|
||||
}
|
||||
|
||||
void setPlayerGamemode(struct player* player, int gamemode) {
|
||||
void player_set_gamemode(struct player* player, int gamemode) {
|
||||
if (gamemode != -1) {
|
||||
player->gamemode = gamemode;
|
||||
struct packet* pkt = xmalloc(sizeof(struct packet));
|
||||
|
@ -1565,7 +1566,7 @@ void setPlayerGamemode(struct player* player, int gamemode) {
|
|||
add_queue(player->outgoingPacket, pkt);
|
||||
}
|
||||
|
||||
void freePlayer(struct player* player) {
|
||||
void player_free(struct player* player) {
|
||||
struct packet* pkt = NULL;
|
||||
while ((pkt = pop_nowait_queue(player->incomingPacket)) != NULL) {
|
||||
freePacket(STATE_PLAY, 0, pkt);
|
||||
|
@ -1594,7 +1595,7 @@ void freePlayer(struct player* player) {
|
|||
xfree(player);
|
||||
}
|
||||
|
||||
block canPlayerPlaceBlock(struct player* player, block blk, int32_t x, int32_t y, int32_t z, uint8_t face) {
|
||||
block player_can_place_block(struct player* player, block blk, int32_t x, int32_t y, int32_t z, uint8_t face) {
|
||||
struct block_info* bi = getBlockInfo(blk);
|
||||
block tbb = blk;
|
||||
if (bi != NULL && bi->onBlockPlacedPlayer != NULL) tbb = (*bi->onBlockPlacedPlayer)(player, player->world, tbb, x, y, z, face);
|
||||
|
|
|
@ -1723,7 +1723,7 @@ void tick_world(struct world* world) {
|
|||
beginProfilerSection("tick_player");
|
||||
BEGIN_HASHMAP_ITERATION(world->players)
|
||||
struct player* player = (struct player*) value;
|
||||
tick_player(world, player);
|
||||
player_tick(world, player);
|
||||
tick_entity(world, player->entity); // might need to be moved into separate loop later
|
||||
END_HASHMAP_ITERATION(world->players)
|
||||
endProfilerSection("tick_player");
|
||||
|
@ -1838,7 +1838,7 @@ void freeWorld(struct world* world) { // assumes all chunks are unloaded
|
|||
del_hashmap(world->entities);
|
||||
del_hashmap(world->chunks);
|
||||
BEGIN_HASHMAP_ITERATION(world->players)
|
||||
freePlayer(value);
|
||||
player_free(value);
|
||||
END_HASHMAP_ITERATION(world->players)
|
||||
del_hashmap(world->players);
|
||||
BEGIN_HASHMAP_ITERATION(world->scheduledTicks)
|
||||
|
|
Loading…
Reference in New Issue