mirror of https://github.com/basinserver/basin/
Re-did some changes.
This commit is contained in:
parent
600eb1a882
commit
3614ca2430
|
@ -46,7 +46,6 @@ void run_accept(struct server* server) {
|
|||
if ((spfd.revents ^ POLLIN) != 0) {
|
||||
printf("Error after polling server: %i (poll revents)!\n", spfd.revents);
|
||||
pfree(pool);
|
||||
break;
|
||||
}
|
||||
spfd.revents = 0;
|
||||
int fd = accept(server->fd, (struct sockaddr*) &conn->addr, &conn->addrlen);
|
||||
|
|
|
@ -448,10 +448,12 @@ void onBlockInteract_workbench(struct world* world, block blk, int32_t x, int32_
|
|||
block onBlockPlaced_chest(struct world* world, block blk, int32_t x, int32_t y, int32_t z, block replaced) {
|
||||
int16_t meta = blk & 0x0f;
|
||||
if (meta < 2 || meta > 5) meta = 2;
|
||||
struct mempool* pool = mempool_new();
|
||||
struct tile_entity* te = tile_new("minecraft:chest", x, y, z);
|
||||
te->data.chest.lock = NULL;
|
||||
te->data.chest.inv = xmalloc(sizeof(struct inventory));
|
||||
inventory_new(te->data.chest.inv, INVTYPE_CHEST, 2, 27);
|
||||
struct mempool* pool = mempool_new();
|
||||
inventory_new(pool, te->data.chest.inv, INVTYPE_CHEST, 2, 27);
|
||||
te->data.chest.inv->tile = te;
|
||||
te->data.chest.inv->title = xstrdup("{\"text\": \"Chest\"}", 0);
|
||||
world_set_tile(world, x, y, z, te);
|
||||
|
|
|
@ -234,7 +234,9 @@ void callCommand(struct player* player, struct mempool* pool, char* command) {
|
|||
}
|
||||
for (size_t i3 = 0; i3 < registered_commands->size; i3++) {
|
||||
struct command* com = (struct command*) registered_commands->data[i3];
|
||||
if (com == NULL) continue;
|
||||
if (com == NULL) {
|
||||
|
||||
}
|
||||
if (streq_nocase(com->command, rc)) {
|
||||
(*com->callback)(player, args, arg_count);
|
||||
return;
|
||||
|
|
|
@ -82,8 +82,7 @@ void crafting_init() {
|
|||
ITER_LLIST_END();
|
||||
}
|
||||
list_append(crafting_recipies, recipe);
|
||||
continue;
|
||||
crafting_format_error:;
|
||||
crafting_format_error: ;
|
||||
printf("[WARNING] Error Loading Crafting Recipe \"%s\"! Skipped.\n", child_json->name);
|
||||
ITER_LLIST_END();
|
||||
}
|
||||
|
@ -94,7 +93,9 @@ void crafting_once(struct player* player, struct inventory* inv) {
|
|||
int cap = inv->type == INVTYPE_PLAYERINVENTORY ? 4 : 9;
|
||||
for (int i = 1; i <= cap; i++) {
|
||||
struct slot* slot = inventory_get(player, inv, i);
|
||||
if (slot == NULL) continue;
|
||||
if (slot == NULL) {
|
||||
|
||||
}
|
||||
if (--slot->count <= 0) {
|
||||
if (slot->nbt != NULL) {
|
||||
pfree(slot->nbt->pool);
|
||||
|
@ -111,12 +112,16 @@ int crafting_all(struct player* player, struct inventory* inv) {
|
|||
uint8_t count = 64;
|
||||
for (int i = 1; i <= cap; i++) {
|
||||
struct slot* slot = inventory_get(player, inv, i);
|
||||
if (slot == NULL) continue;
|
||||
if (slot == NULL) {
|
||||
|
||||
}
|
||||
if (slot->count < count) count = slot->count;
|
||||
}
|
||||
for (int i = 1; i <= cap; i++) {
|
||||
struct slot* slot = inventory_get(player, inv, i);
|
||||
if (slot == NULL) continue;
|
||||
if (slot == NULL) {
|
||||
|
||||
}
|
||||
slot->count -= count;
|
||||
if (slot->count <= 0) {
|
||||
if (slot->nbt != NULL) {
|
||||
|
@ -177,12 +182,16 @@ struct slot* crafting_result(struct mempool* pool, struct slot** slots, size_t s
|
|||
|
||||
for (size_t i = 0; i < crafting_recipies->size; i++) {
|
||||
struct crafting_recipe* recipe = (struct crafting_recipe*) crafting_recipies->data[i];
|
||||
if (recipe == NULL || (recipe->width > 2 && slot_count <= 4) || (slot_count == 4 && (recipe->slot[6] != NULL || recipe->slot[7] != NULL || recipe->slot[8] != NULL))) continue;
|
||||
if (recipe == NULL || (recipe->width > 2 && slot_count <= 4) || (slot_count == 4 && (recipe->slot[6] != NULL || recipe->slot[7] != NULL || recipe->slot[8] != NULL))) {
|
||||
|
||||
}
|
||||
if (recipe->shapeless) { // TODO: optimize
|
||||
int matching = 1;
|
||||
for (int slot_index = 0; slot_index <= slot_count; slot_index++) {
|
||||
struct slot* slot = slots[slot_index];
|
||||
if (slot == NULL) continue;
|
||||
if (slot == NULL) {
|
||||
|
||||
}
|
||||
int local_matched = 0;
|
||||
for (int ri = 0; ri < 9; ri++) {
|
||||
struct slot* local_slot = recipe->slot[ri];
|
||||
|
@ -199,7 +208,9 @@ struct slot* crafting_result(struct mempool* pool, struct slot** slots, size_t s
|
|||
if (matching) {
|
||||
for (int slot_index_2 = 0; slot_index_2 < 9; slot_index_2++) {
|
||||
struct slot* slot = recipe->slot[slot_index_2];
|
||||
if (slot == NULL) continue;
|
||||
if (slot == NULL) {
|
||||
|
||||
}
|
||||
int local_matched = 0;
|
||||
for (int ls = 1; ls <= 4; ls++) {
|
||||
struct slot* local_slot = slots[ls];
|
||||
|
|
45
src/entity.c
45
src/entity.c
|
@ -133,7 +133,6 @@ void init_entities() {
|
|||
info->dataname = str_dup(tmp->data.string, 0, entities_pool);
|
||||
list_set(entity_infos, id, info);
|
||||
hashmap_put(entity_infos_by_name, str_tolower(str_dup(info->dataname, 0, entities_pool)), info);
|
||||
continue;
|
||||
entity_error: ;
|
||||
printf("[WARNING] Error Loading Entity \"%s\"! Skipped.\n", child_json->name);
|
||||
ITER_LLIST_END();
|
||||
|
@ -539,10 +538,14 @@ int entity_move(struct entity* entity, double* motionX, double* motionY, double*
|
|||
for (int32_t z = (int32_t) floor(obb.minZ); z < floor(obb.maxZ + 1.); z++) {
|
||||
for (int32_t y = (int32_t) floor(obb.minY); y < floor(obb.maxY + 1.); y++) {
|
||||
block b = world_get_block_guess(entity->world, ch, x, y, z);
|
||||
if (b == 0) continue;
|
||||
if (b == 0) {
|
||||
|
||||
}
|
||||
b = entity_adjustCollision(entity->world, entity, ch, b, x, y, z);
|
||||
struct block_info* bi = getBlockInfo(b);
|
||||
if (bi == NULL) continue;
|
||||
if (bi == NULL) {
|
||||
|
||||
}
|
||||
for (size_t i = 0; i < bi->boundingBox_count; i++) {
|
||||
struct boundingbox* bbx = &bi->boundingBoxes[i];
|
||||
struct boundingbox bbd;
|
||||
|
@ -578,10 +581,14 @@ int entity_move(struct entity* entity, double* motionX, double* motionY, double*
|
|||
for (int32_t z = (int32_t) floor(obb.minZ); z < floor(obb.maxZ + 1.); z++) {
|
||||
for (int32_t y = (int32_t) floor(obb.minY); y < floor(obb.maxY + 1.); y++) {
|
||||
block b = world_get_block_guess(entity->world, ch, x, y, z);
|
||||
if (b == 0) continue;
|
||||
if (b == 0) {
|
||||
|
||||
}
|
||||
b = entity_adjustCollision(entity->world, entity, ch, b, x, y, z);
|
||||
struct block_info* bi = getBlockInfo(b);
|
||||
if (bi == NULL) continue;
|
||||
if (bi == NULL) {
|
||||
|
||||
}
|
||||
for (size_t i = 0; i < bi->boundingBox_count; i++) {
|
||||
struct boundingbox* bbx = &bi->boundingBoxes[i];
|
||||
struct boundingbox bbd;
|
||||
|
@ -617,10 +624,14 @@ int entity_move(struct entity* entity, double* motionX, double* motionY, double*
|
|||
for (int32_t z = (int32_t) floor(obb.minZ); z < floor(obb.maxZ + 1.); z++) {
|
||||
for (int32_t y = (int32_t) floor(obb.minY); y < floor(obb.maxY + 1.); y++) {
|
||||
block b = world_get_block_guess(entity->world, ch, x, y, z);
|
||||
if (b == 0) continue;
|
||||
if (b == 0) {
|
||||
|
||||
}
|
||||
b = entity_adjustCollision(entity->world, entity, ch, b, x, y, z);
|
||||
struct block_info* bi = getBlockInfo(b);
|
||||
if (bi == NULL) continue;
|
||||
if (bi == NULL) {
|
||||
|
||||
}
|
||||
for (size_t i = 0; i < bi->boundingBox_count; i++) {
|
||||
struct boundingbox* bbx = &bi->boundingBoxes[i];
|
||||
struct boundingbox bbd;
|
||||
|
@ -835,7 +846,9 @@ int damageEntity(struct entity* attacked, float damage, int armorable) {
|
|||
for (size_t i = 0; i < info->loot_count; i++) {
|
||||
struct entity_loot* el = &info->loots[i];
|
||||
int amt = el->amountMax == el->amountMin ? el->amountMax : (rand() % (el->amountMax - el->amountMin) + el->amountMin);
|
||||
if (amt <= 0) continue;
|
||||
if (amt <= 0) {
|
||||
|
||||
}
|
||||
struct slot it;
|
||||
it.item = el->id;
|
||||
it.count = (unsigned char) amt;
|
||||
|
@ -888,9 +901,13 @@ int entity_inFluid(struct entity* entity, uint16_t blk, float ydown, int meta_ch
|
|||
for (int32_t z = (int32_t) floor(pbb.minZ); z < floor(pbb.maxZ + 1.); z++) {
|
||||
for (int32_t y = (int32_t) floor(pbb.minY); y < floor(pbb.maxY + 1.); y++) {
|
||||
block b = world_get_block(entity->world, x, y, z);
|
||||
if (meta_check ? (b != blk) : ((b >> 4) != (blk >> 4))) continue;
|
||||
if (meta_check ? (b != blk) : ((b >> 4) != (blk >> 4))) {
|
||||
|
||||
}
|
||||
struct block_info* bi = getBlockInfo(b);
|
||||
if (bi == NULL) continue;
|
||||
if (bi == NULL) {
|
||||
|
||||
}
|
||||
struct boundingbox bb2;
|
||||
bb2.minX = 0. + (double) x;
|
||||
bb2.maxX = 1. + (double) x;
|
||||
|
@ -921,9 +938,13 @@ int entity_inBlock(struct entity* ent, block blk) { // blk = 0 for any block
|
|||
for (int32_t z = floor(obb.minZ); z < floor(obb.maxZ + 1.); z++) {
|
||||
for (int32_t y = floor(obb.minY); y < floor(obb.maxY + 1.); y++) {
|
||||
block b = world_get_block(ent->world, x, y, z);
|
||||
if (b == 0 || (blk != 0 && blk != b)) continue;
|
||||
if (b == 0 || (blk != 0 && blk != b)) {
|
||||
|
||||
}
|
||||
struct block_info* bi = getBlockInfo(b);
|
||||
if (bi == NULL) continue;
|
||||
if (bi == NULL) {
|
||||
|
||||
}
|
||||
for (size_t i = 0; i < bi->boundingBox_count; i++) {
|
||||
struct boundingbox* bb = &bi->boundingBoxes[i];
|
||||
struct boundingbox nbb;
|
||||
|
|
|
@ -109,7 +109,7 @@ void tick_arrow(struct world* world, struct entity* entity) {
|
|||
struct entity* ehit = NULL;
|
||||
struct entity* shooter = world_get_entity(world, entity->objectData - 1);
|
||||
double bd = 999.;
|
||||
BEGIN_HASHMAP_ITERATION(world->entities)
|
||||
BEGIN_HASHMAP_ITERATION(world->entities);
|
||||
struct entity* e2 = value;
|
||||
double rd = entity_distsq_block(e2, entity->x + entity->motX, entity->y + entity->motY, entity->z + entity->motZ);
|
||||
if (rd > 4) {
|
||||
|
@ -154,7 +154,7 @@ void tick_arrow(struct world* world, struct entity* entity) {
|
|||
if (ehit->type != ENT_ENDERMAN) {
|
||||
world_despawn_entity(world, entity);
|
||||
freeEntity(entity);
|
||||
return 1;
|
||||
return;
|
||||
}
|
||||
} else if (hf >= 0) {
|
||||
entity->x = hx;
|
||||
|
@ -187,7 +187,7 @@ void tick_arrow(struct world* world, struct entity* entity) {
|
|||
if (entity->data.arrow.ticksInGround == 1200) {
|
||||
world_despawn_entity(world, entity);
|
||||
freeEntity(entity);
|
||||
return 1;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -211,7 +211,7 @@ void tick_arrow(struct world* world, struct entity* entity) {
|
|||
entity->yaw = entity->last_yaw + (entity->yaw - entity->last_yaw) * .2;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return;
|
||||
}
|
||||
|
||||
void tick_itemstack(struct world* world, struct entity* entity) {
|
||||
|
@ -303,5 +303,5 @@ void tick_itemstack(struct world* world, struct entity* entity) {
|
|||
}
|
||||
}
|
||||
END_HASHMAP_ITERATION(entity->world->entities);
|
||||
return 0;
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -290,8 +290,7 @@ void player_openInventory(struct player* player, struct inventory* inv) {
|
|||
pkt->data.play_client.windowitems.count = inv->slot_count;
|
||||
pkt->data.play_client.windowitems.slot_data = xmalloc(sizeof(struct slot) * inv->slot_count);
|
||||
for (size_t i = 0; i < inv->slot_count; i++) {
|
||||
struct mempool* pool = mempool_new();
|
||||
slot_duplicate(pool, inv->slots[i], &pkt->data.play_client.windowitems.slot_data[i]);
|
||||
slot_duplicate(pkt->pool, inv->slots[i], &pkt->data.play_client.windowitems.slot_data[i]);
|
||||
}
|
||||
add_queue(player->outgoing_packets, pkt);
|
||||
}
|
||||
|
|
|
@ -166,7 +166,7 @@ int onItemInteract_painting(struct world* world, struct player* player, uint8_t
|
|||
else if (p == 24) ent->data.painting.title = "Skeleton";
|
||||
else if (p == 25) ent->data.painting.title = "DonkeyKong";
|
||||
world_spawn_entity(world, ent);
|
||||
if (player->gamemode != 1) inventory_set_slot(player, player->inventory, 36 + player->currentItem, NULL, 1, 1);
|
||||
if (player->gamemode != 1) inventory_set_slot(player, player->inventory, 36 + player->currentItem, NULL, 1);
|
||||
}
|
||||
return 0;
|
||||
|
||||
|
@ -185,7 +185,7 @@ int onItemInteract_minecart(struct world* world, struct player* player, uint8_t
|
|||
else if (slot->item == ITM_MINECARTCOMMANDBLOCK) et = ENT_MINECARTCOMMANDBLOCK;
|
||||
struct entity* ent = entity_new(nextEntityID++, (double) x + .5, (double) y + dy, (double) z + .5, et, 0., 0.);
|
||||
world_spawn_entity(world, ent);
|
||||
if (player->gamemode != 1) inventory_set_slot(player, player->inventory, 36 + player->currentItem, NULL, 1, 1);
|
||||
if (player->gamemode != 1) inventory_set_slot(player, player->inventory, 36 + player->currentItem, NULL, 1);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
@ -629,7 +629,7 @@ void onItemUse_bow(struct world* world, struct player* player, uint8_t slot_inde
|
|||
if (--ammo->count <= 0) {
|
||||
ammo = NULL;
|
||||
}
|
||||
inventory_set_slot(player, player->inventory, bs, ammo, 1, 1);
|
||||
inventory_set_slot(player, player->inventory, bs, ammo, 1);
|
||||
}
|
||||
world_spawn_entity(player->world, arrow);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue