start entity refactoring

This commit is contained in:
Protryon 2019-05-04 17:56:30 -07:00
parent ec36719041
commit 61a58305f5
12 changed files with 101 additions and 143 deletions

View File

@ -445,6 +445,8 @@ struct entity {
struct hashmap* attackers;
};
struct entity* entity_new(struct world* world, int32_t id, double x, double y, double z, uint32_t type, float yaw, float pitch);
int damageEntityWithItem(struct entity* attacked, struct entity* attacker, uint8_t slot_index, struct slot* item);
int damageEntity(struct entity* attacked, float damage, int armorable);
@ -469,8 +471,6 @@ double entity_distsq_block(struct entity* ent1, double x, double y, double z);
double entity_dist_block(struct entity* ent1, double x, double y, double z);
struct entity* newEntity(int32_t id, double x, double y, double z, uint32_t type, float yaw, float pitch);
void getEntityCollision(struct entity* ent, struct boundingbox* bb);
int moveEntity(struct entity* entity, double* mx, double* my, double* mz, float shrink);

View File

@ -15,7 +15,7 @@
void player_openInventory(struct player* player, struct inventory* inv);
float randFloat();
float game_rand_float();
void playSound(struct world* world, int32_t soundID, int32_t soundCategory, float x, float y, float z, float volume, float pitch);
@ -23,7 +23,7 @@ void dropPlayerItem(struct player* player, struct slot* drop);
void dropEntityItem_explode(struct entity* entity, struct slot* drop);
void dropBlockDrop(struct world* world, struct slot* slot, int32_t x, int32_t y, int32_t z);
void game_drop_block(struct world* world, struct slot* slot, int32_t x, int32_t y, int32_t z);
void dropBlockDrops(struct world* world, block blk, struct player* breaker, int32_t x, int32_t y, int32_t z);
@ -31,7 +31,7 @@ void game_load_player(struct player* to, struct player* from);
void game_load_entity(struct player* to, struct entity* from);
void onInventoryUpdate(struct player* player, struct inventory* inv, int slot);
void game_update_inventory(struct player* player, struct inventory* inventory, int slot);
void world_tick(struct world* world);

View File

@ -240,7 +240,7 @@ int32_t ai_attackmelee(struct world* world, struct entity* entity, struct aitask
double dist = entity_distsq(entity->attacking, entity);
amd->delayCounter--;
//TODO: cansee
if ((amd->longMemory || 1) && amd->delayCounter <= 0 && ((amd->targetX == 0. && amd->targetY == 0. && amd->targetZ == 0.) || entity_distsq_block(entity->attacking, amd->targetX, amd->targetY, amd->targetZ) >= 1. || randFloat() < .05)) {
if ((amd->longMemory || 1) && amd->delayCounter <= 0 && ((amd->targetX == 0. && amd->targetY == 0. && amd->targetZ == 0.) || entity_distsq_block(entity->attacking, amd->targetX, amd->targetY, amd->targetZ) >= 1. || game_rand_float() < .05)) {
amd->targetX = entity->attacking->x;
amd->targetY = entity->attacking->y;
amd->targetZ = entity->attacking->z;
@ -425,7 +425,7 @@ int32_t ai_skeletonriders(struct world* world, struct entity* entity, struct ait
}
int32_t ai_swimming(struct world* world, struct entity* entity, struct aitask* ai) {
//if (randFloat() < .8) {
//if (game_rand_float() < .8) {
jump(entity);
//}
return 0;

View File

@ -224,10 +224,10 @@ void onBlockUpdate_tnt(struct world* world, block blk, int32_t x, int32_t y, int
uint8_t maxPower = getPropogatedPower_block(world, world_get_chunk(world, x >> 4, z >> 4), x, y, z, -1);
if (maxPower > 0) {
world_set_block(world, 0, x, y, z);
struct entity* e = newEntity(nextEntityID++, (double) x + .5, (double) y, (double) z + .5, ENT_PRIMEDTNT, 0., 0.);
struct entity* e = entity_new(nextEntityID++, (double) x + .5, (double) y, (double) z + .5, ENT_PRIMEDTNT, 0., 0.);
e->data.tnt.fuse = 80;
e->objectData = blk >> 4;
float ra = randFloat() * M_PI * 2.;
float ra = game_rand_float() * M_PI * 2.;
e->motX = -sinf(ra) * .02;
e->motY = .2;
e->motZ = -cosf(ra) * .02;
@ -485,7 +485,7 @@ int onBlockDestroyed_chest(struct world* world, block blk, int32_t x, int32_t y,
if (te == NULL) return 0;
for (size_t i = 0; i < te->data.chest.inv->slot_count; i++) {
struct slot* sl = inventory_get(NULL, te->data.chest.inv, i);
dropBlockDrop(world, sl, x, y, z);
game_drop_block(world, sl, x, y, z);
}
world_set_tile(world, x, y, z, NULL);
return 0;
@ -518,7 +518,7 @@ int onBlockDestroyed_furnace(struct world* world, block blk, int32_t x, int32_t
if (te == NULL) return 0;
for (size_t i = 0; i < te->data.furnace.inv->slot_count; i++) {
struct slot* sl = inventory_get(NULL, te->data.furnace.inv, i);
dropBlockDrop(world, sl, x, y, z);
game_drop_block(world, sl, x, y, z);
}
world_set_tile(world, x, y, z, NULL);
return 0;
@ -644,14 +644,14 @@ void dropItems_gravel(struct world* world, block blk, int32_t x, int32_t y, int3
drop.damage = 0;
drop.count = 1;
drop.nbt = NULL;
dropBlockDrop(world, &drop, x, y, z);
game_drop_block(world, &drop, x, y, z);
} else {
struct slot drop;
drop.item = BLK_GRAVEL >> 4;
drop.damage = BLK_GRAVEL & 0x0f;
drop.count = 1;
drop.nbt = NULL;
dropBlockDrop(world, &drop, x, y, z);
game_drop_block(world, &drop, x, y, z);
}
}
@ -687,7 +687,7 @@ void dropItems_leaves(struct world* world, block blk, int32_t x, int32_t y, int3
} else return;
drop.count = 1;
drop.nbt = NULL;
dropBlockDrop(world, &drop, x, y, z);
game_drop_block(world, &drop, x, y, z);
}
if (blk == BLK_LEAVES_OAK || blk == BLK_LEAVES_BIG_OAK) {
chance = 200;
@ -701,7 +701,7 @@ void dropItems_leaves(struct world* world, block blk, int32_t x, int32_t y, int3
drop.damage = 0;
drop.count = 1;
drop.nbt = NULL;
dropBlockDrop(world, &drop, x, y, z);
game_drop_block(world, &drop, x, y, z);
}
}
}
@ -713,7 +713,7 @@ void dropItems_tallgrass(struct world* world, block blk, int32_t x, int32_t y, i
drop.damage = 0;
drop.count = 1 + (rand() % (fortune * 2 + 1));
drop.nbt = NULL;
dropBlockDrop(world, &drop, x, y, z);
game_drop_block(world, &drop, x, y, z);
}
}
@ -731,7 +731,7 @@ void onBlockUpdate_falling(struct world* world, block blk, int32_t x, int32_t y,
int scheduledTick_falling(struct world* world, block blk, int32_t x, int32_t y, int32_t z) {
if (y > 0 && falling_canFallThrough(world_get_block(world, x, y - 1, z))) {
world_set_block(world, 0, x, y, z);
struct entity* e = newEntity(nextEntityID++, (double) x + .5, (double) y, (double) z + .5, ENT_FALLINGBLOCK, 0., 0.);
struct entity* e = entity_new(nextEntityID++, (double) x + .5, (double) y, (double) z + .5, ENT_FALLINGBLOCK, 0., 0.);
e->data.fallingblock.b = blk;
e->objectData = blk >> 4;
world_spawn_entity(world, e);
@ -951,7 +951,7 @@ void dropItems_hugemushroom(struct world* world, block blk, int32_t x, int32_t y
drop.damage = 0;
drop.count = ct;
drop.nbt = NULL;
dropBlockDrop(world, &drop, x, y, z);
game_drop_block(world, &drop, x, y, z);
}
}
@ -967,7 +967,7 @@ void dropItems_crops(struct world* world, block blk, int32_t x, int32_t y, int32
drop.count = 1;
drop.damage = 0;
drop.nbt = NULL;
dropBlockDrop(world, &drop, x, y, z);
game_drop_block(world, &drop, x, y, z);
}
seed = ITM_SEEDS;
} else if ((blk >> 4) == (BLK_PUMPKINSTEM >> 4)) {
@ -977,7 +977,7 @@ void dropItems_crops(struct world* world, block blk, int32_t x, int32_t y, int32
drop.nbt = NULL;
for (int i = 0; i < 3; i++) {
if (rand() % 15 <= age) {
dropBlockDrop(world, &drop, x, y, z);
game_drop_block(world, &drop, x, y, z);
}
}
seed = ITM_SEEDS_PUMPKIN;
@ -989,7 +989,7 @@ void dropItems_crops(struct world* world, block blk, int32_t x, int32_t y, int32
drop.nbt = NULL;
for (int i = 0; i < 3; i++) {
if (rand() % 15 <= age) {
dropBlockDrop(world, &drop, x, y, z);
game_drop_block(world, &drop, x, y, z);
}
}
seed = ITM_SEEDS_PUMPKIN;
@ -1001,7 +1001,7 @@ void dropItems_crops(struct world* world, block blk, int32_t x, int32_t y, int32
drop.count = 1;
drop.damage = 0;
drop.nbt = NULL;
dropBlockDrop(world, &drop, x, y, z);
game_drop_block(world, &drop, x, y, z);
}
seed = ITM_CARROTS;
} else if ((blk >> 4) == (BLK_POTATOES >> 4)) {
@ -1012,13 +1012,13 @@ void dropItems_crops(struct world* world, block blk, int32_t x, int32_t y, int32
drop.count = 1;
drop.damage = 0;
drop.nbt = NULL;
dropBlockDrop(world, &drop, x, y, z);
game_drop_block(world, &drop, x, y, z);
if (rand() % 50 == 0) {
drop.item = ITM_POTATOPOISONOUS;
drop.count = 1;
drop.damage = 0;
drop.nbt = NULL;
dropBlockDrop(world, &drop, x, y, z);
game_drop_block(world, &drop, x, y, z);
}
}
} else if ((blk >> 4) == (BLK_NETHERSTALK >> 4)) {
@ -1032,7 +1032,7 @@ void dropItems_crops(struct world* world, block blk, int32_t x, int32_t y, int32
if (fortune > 0) rct += rand() % (fortune + 1);
}
for (int i = 0; i < rct; i++)
dropBlockDrop(world, &drop, x, y, z);
game_drop_block(world, &drop, x, y, z);
return;
} else if ((blk >> 4) == (BLK_BEETROOTS >> 4)) {
maxAge = 3;
@ -1041,7 +1041,7 @@ void dropItems_crops(struct world* world, block blk, int32_t x, int32_t y, int32
drop.count = 1;
drop.damage = 0;
drop.nbt = NULL;
dropBlockDrop(world, &drop, x, y, z);
game_drop_block(world, &drop, x, y, z);
}
seed = ITM_BEETROOT_SEEDS;
} else if ((blk >> 4) == (BLK_COCOA >> 4)) {
@ -1052,7 +1052,7 @@ void dropItems_crops(struct world* world, block blk, int32_t x, int32_t y, int32
drop.damage = 3;
drop.nbt = NULL;
for (int i = 0; i < rc; i++)
dropBlockDrop(world, &drop, x, y, z);
game_drop_block(world, &drop, x, y, z);
return;
}
if (seed > 0) {
@ -1063,10 +1063,10 @@ void dropItems_crops(struct world* world, block blk, int32_t x, int32_t y, int32
if (age >= maxAge) {
int rct = 3 + fortune;
for (int i = 0; i < rct; i++) {
if (rand() % (2 * maxAge) <= age) dropBlockDrop(world, &drop, x, y, z);
if (rand() % (2 * maxAge) <= age) game_drop_block(world, &drop, x, y, z);
}
}
dropBlockDrop(world, &drop, x, y, z);
game_drop_block(world, &drop, x, y, z);
}
}

View File

@ -110,7 +110,7 @@ void crafting_once(struct player* player, struct inventory* inv) {
}
inv->slots[i] = slot;
}
onInventoryUpdate(player, inv, 1);
game_update_inventory(player, inv, 1);
}
int crafting_all(struct player* player, struct inventory* inv) {

View File

@ -77,7 +77,7 @@ int onTick_fallingblock(struct world* world, struct entity* ent) {
sl.damage = ent->data.fallingblock.b & 0x0f;
sl.count = 1;
sl.nbt = NULL;
dropBlockDrop(world, &sl, (int32_t) floor(ent->x), (int32_t) floor(ent->y - .01), (int32_t) floor(ent->z));
game_drop_block(world, &sl, (int32_t) floor(ent->x), (int32_t) floor(ent->y - .01), (int32_t) floor(ent->z));
//ent->onGround = 0;
//return 0;
} else {
@ -130,7 +130,7 @@ void onInteract_mooshroom(struct world* world, struct entity* entity, struct pla
}
} else if (item->item == ITM_SHEARS && interacter->gamemode != 1) { // TODO: not child
//TODO: explosion
struct entity* ent = newEntity(nextEntityID++, entity->x, entity->y, entity->z, ENT_COW, entity->yaw, entity->pitch);
struct entity* ent = entity_new(nextEntityID++, entity->x, entity->y, entity->z, ENT_COW, entity->yaw, entity->pitch);
ent->health = entity->health;
memcpy(&ent->data, &entity->data, sizeof(union entity_data));
world_spawn_entity(world, ent);
@ -500,54 +500,25 @@ void jump(struct entity* entity) {
}
}
struct entity* newEntity(int32_t id, double x, double y, double z, uint32_t type, float yaw, float pitch) {
struct entity* e = malloc(sizeof(struct entity));
struct entity_info* ei = getEntityInfo(type);
e->id = id;
e->age = 0;
e->x = x;
e->y = y;
e->z = z;
e->last_x = x;
e->last_y = y;
e->last_z = z;
e->type = type;
e->yaw = yaw;
e->pitch = pitch;
e->last_yaw = yaw;
e->last_pitch = pitch;
e->headpitch = 0.;
e->on_ground = 0;
e->motX = 0.;
e->motY = 0.;
e->motZ = 0.;
e->objectData = 0;
e->markedKill = 0;
e->effects = NULL;
e->effect_count = 0;
e->collidedVertically = 0;
e->collidedHorizontally = 0;
e->sneaking = 0;
e->sprinting = 0;
e->usingItemMain = 0;
e->usingItemOff = 0;
e->portalCooldown = 0;
e->ticksExisted = 0;
e->subtype = 0;
e->fallDistance = 0.;
e->maxHealth = ei == NULL ? 20. : ei->maxHealth;
e->health = e->maxHealth;
e->world = NULL;
e->inWater = 0;
e->inLava = 0;
e->invincibilityTicks = 0;
e->loadingPlayers = hashmap_thread_new(16, e->pool);
e->attacking = NULL;
e->attackers = new_hashmap(1, 0);
e->immovable = 0;
memset(&e->data, 0, sizeof(union entity_data));
e->ai = NULL;
return e;
struct entity* entity_new(struct world* world, int32_t id, double x, double y, double z, uint32_t type, float yaw, float pitch) {
struct mempool* pool = mempool_new();
pchild(world->pool, pool);
struct entity* entity = pcalloc(pool, sizeof(struct entity));
entity->pool = pool;
entity->world = world;
struct entity_info* info = getEntityInfo(type);
entity->id = id;
entity->type = type;
entity->last_x = entity->x = x;
entity->last_y = entity->y = y;
entity->last_z = entity->z = z;
entity->last_yaw = entity->yaw = yaw;
entity->last_pitch = entity->pitch = pitch;
entity->maxHealth = info == NULL ? 20f : info->maxHealth;
entity->health = entity->maxHealth;
entity->loadingPlayers = hashmap_thread_new(16, entity->pool);
// entity->attackers = new_hashmap(1, 0);
return entity;
}
double entity_dist(struct entity* ent1, struct entity* ent2) {
@ -1103,7 +1074,7 @@ void applyVelocity(struct entity* entity, double x, double y, double z) {
void applyKnockback(struct entity* entity, float yaw, float strength) {
float kb_resistance = 0.;
if (randFloat() > kb_resistance) {
if (game_rand_float() > kb_resistance) {
float xr = sinf(yaw / 360. * 2 * M_PI);
float zr = -cosf(yaw / 360. * 2 * M_PI);
float m = sqrtf(xr * xr + zr * zr);
@ -1353,7 +1324,7 @@ void pushOutOfBlocks(struct entity* ent) {
fby = 1.;
fbz = 0.;
}
float mag = randFloat() * .2 + .1;
float mag = game_rand_float() * .2 + .1;
if (fbx == 0. && fbz == 0.) {
ent->motX *= .75;
ent->motY = mag * fby;

View File

@ -128,72 +128,59 @@ void game_load_entity(struct player* to, struct entity* from) {
hashmap_putint(from->loadingPlayers, (uint64_t) to->entity->id, to);
}
void onInventoryUpdate(struct player* player, struct inventory* inv, int slot) {
if (inv->type == INVTYPE_PLAYERINVENTORY) {
void game_update_inventory(struct player* player, struct inventory* inventory, int slot) {
if (inventory->type == INVTYPE_PLAYERINVENTORY) {
if (slot == player->currentItem + 36) {
if (player->itemUseDuration > 0 && player->itemUseHand == 0) {
struct slot* ihs = inventory_get(player, player->inventory, player->itemUseHand ? 45 : (36 + player->currentItem));
struct item_info* ihi = ihs == NULL ? NULL : getItemInfo(ihs->item);
if (ihs == NULL || ihi == NULL) player->itemUseDuration = 0;
struct slot* in_hand_slot = inventory_get(player, player->inventory, player->itemUseHand ? 45 : (36 + player->currentItem));
struct item_info* info = in_hand_slot == NULL ? NULL : getItemInfo(in_hand_slot->item);
if (in_hand_slot == NULL || info == NULL) player->itemUseDuration = 0;
else {
if (ihi->onItemUseTick != NULL) (*ihi->onItemUseTick)(player->world, player, player->itemUseHand ? 45 : (36 + player->currentItem), ihs, -1);
if (info->onItemUseTick != NULL) (*info->onItemUseTick)(player->world, player, player->itemUseHand ? 45 : (36 + player->currentItem), in_hand_slot, -1);
player->itemUseDuration = 0;
}
}
BEGIN_BROADCAST_EXCEPT_DIST(player, player->entity, 128.)
struct packet* pkt = xmalloc(sizeof(struct packet));
pkt->id = PKT_PLAY_CLIENT_ENTITYEQUIPMENT;
pkt->data.play_client.entityequipment.entity_id = player->entity->id;
pkt->data.play_client.entityequipment.slot = 0;
slot_duplicate(inventory_get(player, inv, player->currentItem + 36), &pkt->data.play_client.entityequipment.item);
add_queue(bc_player->outgoing_packets, pkt);
END_BROADCAST(player->world->players)
BEGIN_BROADCAST_EXCEPT_DIST(player, player->entity, 128.){
game_entity_equipment(bc_player, player->entity, 0, inventory_get(player, inventory, player->currentItem + 36));
END_BROADCAST(player->world->players);
}
} else if (slot >= 5 && slot <= 8) {
BEGIN_BROADCAST_EXCEPT_DIST(player, player->entity, 128.)
struct packet* pkt = xmalloc(sizeof(struct packet));
pkt->id = PKT_PLAY_CLIENT_ENTITYEQUIPMENT;
pkt->data.play_client.entityequipment.entity_id = player->entity->id;
if (slot == 5) pkt->data.play_client.entityequipment.slot = 5;
else if (slot == 6) pkt->data.play_client.entityequipment.slot = 4;
else if (slot == 7) pkt->data.play_client.entityequipment.slot = 3;
else if (slot == 8) pkt->data.play_client.entityequipment.slot = 2;
slot_duplicate(inventory_get(player, inv, slot), &pkt->data.play_client.entityequipment.item);
add_queue(bc_player->outgoing_packets, pkt);
END_BROADCAST(player->world->players)
BEGIN_BROADCAST_EXCEPT_DIST(player, player->entity, 128.) {
int packet_slot = (8 - slot) + 2;
game_entity_equipment(bc_player, player->entity, packet_slot, inventory_get(player, inventory, slot));
END_BROADCAST(player->world->players);
}
} else if (slot == 45) {
BEGIN_BROADCAST_EXCEPT_DIST(player, player->entity, 128.)
struct packet* pkt = xmalloc(sizeof(struct packet));
pkt->id = PKT_PLAY_CLIENT_ENTITYEQUIPMENT;
pkt->data.play_client.entityequipment.entity_id = player->entity->id;
pkt->data.play_client.entityequipment.slot = 1;
slot_duplicate(inventory_get(player, inv, 45), &pkt->data.play_client.entityequipment.item);
add_queue(bc_player->outgoing_packets, pkt);
END_BROADCAST(player->world->players)
BEGIN_BROADCAST_EXCEPT_DIST(player, player->entity, 128.) {
game_entity_equipment(bc_player, player->entity, 1, inventory_get(player, inventory, 45));
END_BROADCAST(player->world->players);
}
} else if (slot >= 1 && slot <= 4) {
inventory_set_slot(player, inv, 0, crafting_result(&inv->slots[1], 4), 1, 1);
// TODO: adjust pools here properly
inventory_set_slot(player, inventory, 0, crafting_result(inventory->pool, &inventory->slots[1], 4), 1);
}
} else if (inv->type == INVTYPE_WORKBENCH) {
} else if (inventory->type == INVTYPE_WORKBENCH) {
if (slot >= 1 && slot <= 9) {
inventory_set_slot(player, inv, 0, crafting_result(&inv->slots[1], 9), 1, 1);
inventory_set_slot(player, inventory, 0, crafting_result(inventory->pool, &inventory->slots[1], 9), 1);
}
} else if (inv->type == INVTYPE_FURNACE) {
} else if (inventory->type == INVTYPE_FURNACE) {
if (slot >= 0 && slot <= 2 && player != NULL) {
update_furnace(player->world, inv->tile);
update_furnace(player->world, inventory->tile);
}
}
}
float randFloat() {
float game_rand_float() {
return ((float) rand() / (float) RAND_MAX);
}
void dropBlockDrop(struct world* world, struct slot* slot, int32_t x, int32_t y, int32_t z) {
struct entity* item = newEntity(nextEntityID++, (double) x + .5, (double) y + .5, (double) z + .5, ENT_ITEM, randFloat() * 360., 0.);
void game_drop_block(struct world* world, struct slot* slot, int32_t x, int32_t y, int32_t z) {
struct entity* item = entity_new(world->server->next_entity_id++, (double) x + .5, (double) y + .5, (double) z + .5, ENT_ITEM, game_rand_float() * 360., 0.);
item->data.itemstack.slot = xmalloc(sizeof(struct slot));
item->objectData = 1;
item->motX = randFloat() * .2 - .1;
item->motX = game_rand_float() * .2 - .1;
item->motY = .2;
item->motZ = randFloat() * .2 - .1;
item->motZ = game_rand_float() * .2 - .1;
item->data.itemstack.delayBeforeCanPickup = 0;
slot_duplicate(slot, item->data.itemstack.slot);
world_spawn_entity(world, item);
@ -203,16 +190,16 @@ void dropBlockDrop(struct world* world, struct slot* slot, int32_t x, int32_t y,
}
void dropPlayerItem(struct player* player, struct slot* drop) {
struct entity* item = newEntity(nextEntityID++, player->entity->x, player->entity->y + 1.32, player->entity->z, ENT_ITEM, 0., 0.);
struct entity* item = entity_new(nextEntityID++, player->entity->x, player->entity->y + 1.32, player->entity->z, ENT_ITEM, 0., 0.);
item->data.itemstack.slot = xmalloc(sizeof(struct slot));
item->objectData = 1;
item->motX = -sin(player->entity->yaw * M_PI / 180.) * cos(player->entity->pitch * M_PI / 180.) * .3;
item->motZ = cos(player->entity->yaw * M_PI / 180.) * cos(player->entity->pitch * M_PI / 180.) * .3;
item->motY = -sin(player->entity->pitch * M_PI / 180.) * .3 + .1;
float nos = randFloat() * M_PI * 2.;
float mag = .02 * randFloat();
float nos = game_rand_float() * M_PI * 2.;
float mag = .02 * game_rand_float();
item->motX += cos(nos) * mag;
item->motY += (randFloat() - randFloat()) * .1;
item->motY += (game_rand_float() - game_rand_float()) * .1;
item->motZ += sin(nos) * mag;
item->data.itemstack.delayBeforeCanPickup = 20;
slot_duplicate(drop, item->data.itemstack.slot);
@ -238,11 +225,11 @@ void playSound(struct world* world, int32_t soundID, int32_t soundCategory, floa
}
void dropEntityItem_explode(struct entity* entity, struct slot* drop) {
struct entity* item = newEntity(nextEntityID++, entity->x, entity->y + 1.32, entity->z, ENT_ITEM, 0., 0.);
struct entity* item = entity_new(nextEntityID++, entity->x, entity->y + 1.32, entity->z, ENT_ITEM, 0., 0.);
item->data.itemstack.slot = xmalloc(sizeof(struct slot));
item->objectData = 1;
float f1 = randFloat() * .5;
float f2 = randFloat() * M_PI * 2.;
float f1 = game_rand_float() * .5;
float f2 = game_rand_float() * M_PI * 2.;
item->motX = -sin(f2) * f1;
item->motZ = cos(f2) * f1;
item->motY = .2;
@ -272,7 +259,7 @@ void dropBlockDrops(struct world* world, block blk, struct player* breaker, int3
dd.damage = bi->drop_damage;
dd.count = bi->drop_min + ((bi->drop_max == bi->drop_min) ? 0 : (rand() % (bi->drop_max - bi->drop_min)));
dd.nbt = NULL;
dropBlockDrop(world, &dd, x, y, z);
game_drop_block(world, &dd, x, y, z);
} else (*bi->dropItems)(world, blk, x, y, z, 0);
}

View File

@ -72,7 +72,7 @@ void inventory_set_slot(struct player* player, struct inventory* inv, int index,
inv->slots[index] = pmalloc(inv->pool, sizeof(struct slot));
slot_duplicate(inv->pool, slot, inv->slots[index]);
}
onInventoryUpdate(player, inv, index);
game_update_inventory(player, inv, index);
if (broadcast) {
BEGIN_BROADCAST(inv->watching_players)
struct packet* pkt = packet_new(mempool_new(), PKT_PLAY_CLIENT_SETSLOT);

View File

@ -69,7 +69,7 @@ int onItemInteract_painting(struct world* world, struct player* player, uint8_t
int32_t oz = z;
offsetCoordByFace(&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.);
struct entity* ent = entity_new(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;
if (face == WEST) ent->data.painting.direction = 1;
@ -190,7 +190,7 @@ int onItemInteract_minecart(struct world* world, struct player* player, uint8_t
else if (slot->item == ITM_MINECARTTNT) et = ENT_MINECARTTNT;
else if (slot->item == ITM_MINECARTHOPPER) et = ENT_MINECARTHOPPER;
else if (slot->item == ITM_MINECARTCOMMANDBLOCK) et = ENT_MINECARTCOMMANDBLOCK;
struct entity* ent = newEntity(nextEntityID++, (double) x + .5, (double) y + dy, (double) z + .5, et, 0., 0.);
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);
return 0;
@ -357,7 +357,7 @@ int onItemInteract_spawnegg(struct world* world, struct player* player, uint8_t
struct nbt_tag* tmp = nbt_get(et, "id");
if (tmp == NULL || tmp->id != NBT_TAG_STRING) return 0;
uint32_t etx = getIDFromEntityDataName(tmp->data.nbt_string);
struct entity* ent = newEntity(nextEntityID++, (float) x + .5, (float) y, (float) z + .5, etx, 0., 0.);
struct entity* ent = entity_new(nextEntityID++, (float) x + .5, (float) y, (float) z + .5, etx, 0., 0.);
world_spawn_entity(world, ent);
if (player->gamemode != 1 && --slot->count <= 0) {
slot = NULL;
@ -599,7 +599,7 @@ void onItemUse_bow(struct world* world, struct player* player, uint8_t slot_inde
if (velocity > 1.) velocity = 1.;
if (velocity >= .1) {
int sp = ammo != NULL && ammo->item == ITM_SPECTRAL_ARROW;
struct entity* arrow = newEntity(nextEntityID++, player->entity->x, player->entity->y + 1.52, player->entity->z, sp ? ENT_SPECTRALARROW : ENT_ARROW, player->entity->yaw, player->entity->pitch);
struct entity* arrow = entity_new(nextEntityID++, player->entity->x, player->entity->y + 1.52, player->entity->z, sp ? ENT_SPECTRALARROW : ENT_ARROW, player->entity->yaw, player->entity->pitch);
//player->entity->pitch = 0.;
//player->entity->yaw = 0.;
float x = -sinf(player->entity->yaw / 360. * 2 * M_PI) * cosf(player->entity->pitch / 360. * 2 * M_PI);

View File

@ -56,7 +56,7 @@ int work_joinServer(struct connection* conn, char* username, char* uuid_string)
return 1;
}
conn->protocol_state = STATE_PLAY;
struct entity* ep = newEntity(conn->server->next_entity_id++, (double) conn->server->overworld->spawnpos.x + .5, (double) conn->server->overworld->spawnpos.y, (double) conn->server->overworld->spawnpos.z + .5, ENT_PLAYER, 0f, 0f);
struct entity* ep = entity_new(conn->server->next_entity_id++, (double) conn->server->overworld->spawnpos.x + .5, (double) conn->server->overworld->spawnpos.y, (double) conn->server->overworld->spawnpos.z + .5, ENT_PLAYER, 0f, 0f);
struct player* player = player_new(conn->pool, conn->server, conn, conn->server->overworld, ep, str_dup(resp->data.login_client.loginsuccess.username, 1, conn->pool), uuid, 1); // TODO default gamemode
conn->player = player;
hashmap_putint(conn->server->players_by_entity_id, (uint64_t) player->entity->id, player);

View File

@ -239,7 +239,7 @@ void player_packet_handle_clickwindow(struct player* player, struct mempool* poo
int amt = crafting_all(player, inventory);
for (int i = 0; i < amt; i++)
inventory_add(player, inventory, item, 44, 8, 0);
onInventoryUpdate(player, inventory, 1); // 2-4 would just repeat the calculation
game_update_inventory(player, inventory, 1); // 2-4 would just repeat the calculation
} else if (slot != 45 && it == ITM_SHIELD && inventory->slots[45] == NULL) {
inventory_swap(player, inventory, 45, slot, 0);
} else if (slot != 5 && inventory->slots[5] == NULL && (it == BLK_PUMPKIN || it == ITM_HELMETCLOTH || it == ITM_HELMETCHAIN || it == ITM_HELMETIRON || it == ITM_HELMETDIAMOND || it == ITM_HELMETGOLD)) {
@ -269,7 +269,7 @@ void player_packet_handle_clickwindow(struct player* player, struct mempool* poo
int amt = crafting_all(player, inventory);
for (int i = 0; i < amt; i++)
inventory_add(player, inventory, inventory->slots[0], 45, 9, 0);
onInventoryUpdate(player, inventory, 1); // 2-4 would just repeat the calculation
game_update_inventory(player, inventory, 1); // 2-4 would just repeat the calculation
} else if (slot <= 9) {
int r = inventory_add(player, inventory, item, 10, 46, 0);
if (r <= 0) inventory_set_slot(player, inventory, slot, NULL, 0);
@ -898,7 +898,7 @@ void player_packet_handle_helditemchange(struct player* player, struct mempool*
}
pthread_mutex_lock(&player->inventory->mutex);
player->currentItem = (uint16_t) packet->slot;
onInventoryUpdate(player, player->inventory, player->currentItem + 36);
game_update_inventory(player, player->inventory, player->currentItem + 36);
pthread_mutex_unlock(&player->inventory->mutex);
}

View File

@ -357,7 +357,7 @@ void world_explode(struct world* world, struct chunk* ch, double x, double y, do
dx /= d;
dy /= d;
dz /= d;
float modified_strength = strength * (.7f + randFloat() * .6f);
float modified_strength = strength * (.7f + game_rand_float() * .6f);
double x2 = x;
double y2 = y;
double z2 = z;