11
22#include <basin/entity_impl.h>
33#include <basin/entity.h>
4+ #include <basin/server.h>
45#include <basin/game.h>
56#include <basin/packet.h>
67#include <avuna/pmem.h>
@@ -22,7 +23,7 @@ void onSpawned_minecart(struct world* world, struct entity* entity) {
2223void onTick_tnt (struct world * world , struct entity * entity ) {
2324 if (entity -> data .tnt .fuse -- <= 0 ) {
2425 world_despawn_entity (world , entity );
25- world_explode (world , NULL , entity -> x , entity -> y + .5 , entity -> z , 4f );
26+ world_explode (world , NULL , entity -> x , entity -> y + .5 , entity -> z , . 4f );
2627 }
2728}
2829
@@ -112,8 +113,9 @@ void tick_arrow(struct world* world, struct entity* entity) {
112113 BEGIN_HASHMAP_ITERATION (world -> entities );
113114 struct entity * e2 = value ;
114115 double rd = entity_distsq_block (e2 , entity -> x + entity -> motX , entity -> y + entity -> motY , entity -> z + entity -> motZ );
115- if (rd > 4 ) continue ;
116- //printf("4d %f\n", rd);
116+ if (rd > 4 ) {
117+ //printf("4d %f\n", rd);
118+ }
117119 if (e2 != entity && e2 != shooter && hasFlag (getEntityInfo (e2 -> type ), "livingbase" )) { //todo: ticksInAir >= 5?
118120 struct boundingbox eb ;
119121 getEntityCollision (e2 , & eb );
@@ -232,43 +234,47 @@ void tick_itemstack(struct world* world, struct entity* entity) {
232234 cebb .minZ -= .625 ;
233235 cebb .maxZ += .625 ;
234236 struct boundingbox oebb ;
235- //int32_t chunk_x = ((int32_t) entity->x) >> 4;
236- //int32_t chunk_z = ((int32_t) entity->z) >> 4;
237- //for (int32_t icx = chunk_x - 1; icx <= chunk_x + 1; icx++)
238- //for (int32_t icz = chunk_z - 1; icz <= chunk_z + 1; icz++) {
239- //struct chunk* ch = world_get_chunk(entity->world, icx, icz);
240- //if (ch != NULL) {
241- BEGIN_HASHMAP_ITERATION (entity -> world -> entities );
242- struct entity * oe = (struct entity * ) value ;
243- if (oe == entity || entity_distsq (entity , oe ) > 16. * 16. ) continue ;
244- if (oe -> type == ENT_PLAYER && oe -> health > 0. ) {
245- getEntityCollision (oe , & oebb );
246- //printf("%f, %f, %f vs %f, %f, %f\n", entity->x, entity->y, entity->z, oe->x, oe->y, oe->z);
247- if (boundingbox_intersects (& oebb , & cebb )) {
248- int os = entity -> data .itemstack .slot -> count ;
249- pthread_mutex_lock (& oe -> data .player .player -> inventory -> mut );
250- int r = inventory_add_player (oe -> data .player .player , oe -> data .player .player -> inventory , entity -> data .itemstack .slot , 1 );
251- pthread_mutex_unlock (& oe -> data .player .player -> inventory -> mut );
252- if (r <= 0 ) {
253- BEGIN_BROADCAST_DIST (entity , 32. )
254- struct packet * pkt = xmalloc (sizeof (struct packet ));
255- pkt -> id = PKT_PLAY_CLIENT_COLLECTITEM ;
256- pkt -> data .play_client .collectitem .collected_entity_id = entity -> id ;
257- pkt -> data .play_client .collectitem .collector_entity_id = oe -> id ;
258- pkt -> data .play_client .collectitem .pickup_item_count = os - r ;
259- add_queue (bc_player -> outgoing_packets , pkt );
260- END_BROADCAST (entity -> world -> players )
261- world_despawn_entity (world , entity );
262- freeEntity (entity );
237+ /*
238+ int32_t chunk_x = ((int32_t) entity->x) >> 4;
239+ int32_t chunk_z = ((int32_t) entity->z) >> 4;
240+ for (int32_t icx = chunk_x - 1; icx <= chunk_x + 1; icx++)
241+ for (int32_t icz = chunk_z - 1; icz <= chunk_z + 1; icz++) {
242+ struct chunk* ch = world_get_chunk(entity->world, icx, icz);
243+ */
244+ if (ch != NULL ) {
245+ BEGIN_HASHMAP_ITERATION (entity -> world -> entities );
246+ struct entity * oe = (struct entity * ) value ;
247+ if (oe == entity || entity_distsq (entity , oe ) > 16. * 16. ) {
248+
249+ }
250+ if (oe -> type == ENT_PLAYER && oe -> health > 0. ) {
251+ getEntityCollision (oe , & oebb );
252+ //printf("%f, %f, %f vs %f, %f, %f\n", entity->x, entity->y, entity->z, oe->x, oe->y, oe->z);
253+ if (boundingbox_intersects (& oebb , & cebb )) {
254+ int os = entity -> data .itemstack .slot -> count ;
255+ pthread_mutex_lock (& oe -> data .player .player -> inventory -> mut );
256+ int r = inventory_add_player (oe -> data .player .player , oe -> data .player .player -> inventory , entity -> data .itemstack .slot , 1 );
257+ pthread_mutex_unlock (& oe -> data .player .player -> inventory -> mut );
258+ if (r <= 0 ) {
259+ BEGIN_BROADCAST_DIST (entity , 32. );
260+ struct packet * pkt = xmalloc (sizeof (struct packet ));
261+ pkt -> id = PKT_PLAY_CLIENT_COLLECTITEM ;
262+ pkt -> data .play_client .collectitem .collected_entity_id = entity -> id ;
263+ pkt -> data .play_client .collectitem .collector_entity_id = oe -> id ;
264+ pkt -> data .play_client .collectitem .pickup_item_count = os - r ;
265+ add_queue (bc_player -> outgoing_packets , pkt );
266+ END_BROADCAST (entity -> world -> players );
267+ world_despawn_entity (world , entity );
268+ freeEntity (entity );
263269 } else {
264- BEGIN_BROADCAST_DIST (entity , 128. )
265- struct packet * pkt = xmalloc (sizeof (struct packet ));
266- pkt -> id = PKT_PLAY_CLIENT_ENTITYMETADATA ;
267- pkt -> data .play_client .entitymetadata .entity_id = entity -> id ;
268- writeMetadata (entity , & pkt -> data .play_client .entitymetadata .metadata .metadata , & pkt -> data .play_client .entitymetadata .metadata .metadata_size );
269- add_queue (bc_player -> outgoing_packets , pkt );
270- END_BROADCAST (entity -> world -> players )
271- BREAK_HASHMAP_ITERATION (entity -> world -> entities );
270+ BEGIN_BROADCAST_DIST (entity , 128. );
271+ struct packet * pkt = xmalloc (sizeof (struct packet ));
272+ pkt -> id = PKT_PLAY_CLIENT_ENTITYMETADATA ;
273+ pkt -> data .play_client .entitymetadata .entity_id = entity -> id ;
274+ writeMetadata (entity , & pkt -> data .play_client .entitymetadata .metadata .metadata , & pkt -> data .play_client .entitymetadata .metadata .metadata_size );
275+ add_queue (bc_player -> outgoing_packets , pkt );
276+ END_BROADCAST (entity -> world -> players );
277+ BREAK_HASHMAP_ITERATION (entity -> world -> entities );
272278 }
273279 }
274280 } else if (oe -> type == ENT_ITEM ) {
@@ -283,14 +289,13 @@ void tick_itemstack(struct world* world, struct entity* entity) {
283289 world_despawn_entity (world , entity );
284290 oe -> data .itemstack .slot -> count += entity -> data .itemstack .slot -> count ;
285291 freeEntity (entity );
286- BEGIN_BROADCAST_DIST (oe , 128. )
292+ BEGIN_BROADCAST_DIST (oe , 128. );
287293 struct packet * pkt = xmalloc (sizeof (struct packet ));
288294 pkt -> id = PKT_PLAY_CLIENT_ENTITYMETADATA ;
289295 pkt -> data .play_client .entitymetadata .entity_id = oe -> id ;
290296 writeMetadata (oe , & pkt -> data .play_client .entitymetadata .metadata .metadata , & pkt -> data .play_client .entitymetadata .metadata .metadata_size );
291297 add_queue (bc_player -> outgoing_packets , pkt );
292298 END_BROADCAST (oe -> world -> players )
293- return 1 ;
294299 }
295300 }
296301 }
0 commit comments