mirror of
https://github.com/p2r3/bareiron.git
synced 2025-10-02 07:35:08 +02:00
spawn players at terrain height level
This commit is contained in:
15
main.c
15
main.c
@@ -14,6 +14,7 @@
|
|||||||
#include "src/tools.h"
|
#include "src/tools.h"
|
||||||
#include "src/varnum.h"
|
#include "src/varnum.h"
|
||||||
#include "src/packets.h"
|
#include "src/packets.h"
|
||||||
|
#include "src/worldgen.h"
|
||||||
|
|
||||||
void handlePacket (int client_fd, int length, int packet_id) {
|
void handlePacket (int client_fd, int length, int packet_id) {
|
||||||
|
|
||||||
@@ -59,7 +60,19 @@ void handlePacket (int client_fd, int length, int packet_id) {
|
|||||||
PlayerData *player;
|
PlayerData *player;
|
||||||
if (getPlayerData(client_fd, &player)) break;
|
if (getPlayerData(client_fd, &player)) break;
|
||||||
|
|
||||||
sc_synchronizePlayerPosition(client_fd, player->x, player->y, player->z, player->yaw * 180 / 127, player->pitch * 90 / 127);
|
if (player->y == -32767) { // is this a new player?
|
||||||
|
|
||||||
|
int _x = 8 / chunk_size;
|
||||||
|
int _z = 8 / chunk_size;
|
||||||
|
int rx = 8 % chunk_size;
|
||||||
|
int rz = 8 % chunk_size;
|
||||||
|
|
||||||
|
uint32_t chunk_hash = getChunkHash(_x, _z);
|
||||||
|
sc_synchronizePlayerPosition(client_fd, 8.5, getHeightAt(rx, rz, _x, _z, chunk_hash) + 1, 8.5, 0, 0);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
sc_synchronizePlayerPosition(client_fd, player->x, player->y, player->z, player->yaw * 180 / 127, player->pitch * 90 / 127);
|
||||||
|
}
|
||||||
|
|
||||||
for (uint8_t i = 0; i < 41; i ++) {
|
for (uint8_t i = 0; i < 41; i ++) {
|
||||||
sc_setContainerSlot(client_fd, 0, serverSlotToClientSlot(i), player->inventory_count[i], player->inventory_items[i]);
|
sc_setContainerSlot(client_fd, 0, serverSlotToClientSlot(i), player->inventory_count[i], player->inventory_items[i]);
|
||||||
|
@@ -7,6 +7,7 @@
|
|||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include "varnum.h"
|
#include "varnum.h"
|
||||||
#include "packets.h"
|
#include "packets.h"
|
||||||
|
#include "tools.h"
|
||||||
|
|
||||||
static uint64_t htonll (uint64_t value) {
|
static uint64_t htonll (uint64_t value) {
|
||||||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||||
@@ -144,9 +145,7 @@ int reservePlayerData (int client_fd, char *uuid) {
|
|||||||
if (empty) {
|
if (empty) {
|
||||||
player_data[i].client_fd = client_fd;
|
player_data[i].client_fd = client_fd;
|
||||||
memcpy(player_data[i].uuid, uuid, 16);
|
memcpy(player_data[i].uuid, uuid, 16);
|
||||||
player_data[i].x = 8;
|
player_data[i].y = -32767;
|
||||||
player_data[i].y = 80;
|
|
||||||
player_data[i].z = 8;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -7,6 +7,7 @@
|
|||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include "tools.h"
|
#include "tools.h"
|
||||||
#include "registries.h"
|
#include "registries.h"
|
||||||
|
#include "worldgen.h"
|
||||||
|
|
||||||
uint32_t getHash (const void *data, size_t len) {
|
uint32_t getHash (const void *data, size_t len) {
|
||||||
const uint8_t *bytes = data;
|
const uint8_t *bytes = data;
|
||||||
@@ -50,8 +51,6 @@ int getCornerHeight (uint32_t hash) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define chunk_size 8
|
|
||||||
|
|
||||||
int interpolate (int a, int b, int c, int d, int x, int z) {
|
int interpolate (int a, int b, int c, int d, int x, int z) {
|
||||||
int top = a * (chunk_size - x) + b * x;
|
int top = a * (chunk_size - x) + b * x;
|
||||||
int bottom = c * (chunk_size - x) + d * x;
|
int bottom = c * (chunk_size - x) + d * x;
|
||||||
|
@@ -3,7 +3,10 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#define chunk_size 8
|
||||||
|
|
||||||
|
uint32_t getChunkHash (short x, short z);
|
||||||
|
int getHeightAt (int rx, int rz, int _x, int _z, uint32_t chunk_hash);
|
||||||
uint8_t getBlockAt (int x, int y, int z);
|
uint8_t getBlockAt (int x, int y, int z);
|
||||||
void writeChunkSection (int client_fd, int _x, int _z, int i);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user