diff --git a/code/game/src/assets.c b/code/game/src/assets.c index 16d915e..0d9ee57 100644 --- a/code/game/src/assets.c +++ b/code/game/src/assets.c @@ -59,10 +59,12 @@ void assets_destroy(void) { } uint16_t assets_find(asset_id id) { - for (uint32_t i=0; ix - (x*bs)/2.0f), p->y - (y*bs)/2.0f); world_chunk_place_block(l.chunk_id, l.id, 0); + + if (l.is_outer && l.block_id > 0) { + asset_id item_asset = blocks_get_asset(l.block_id); + uint64_t e = item_spawn(item_asset, 1); + + Position *dest = ecs_get_mut(world_ecs(), e, Position, NULL); + dest->x = (p->x - (x*bs)/2.0f); + dest->y = (p->y - (y*bs)/2.0f); + } } } diff --git a/code/game/src/items.c b/code/game/src/items.c index 157a9cd..04fdf32 100644 --- a/code/game/src/items.c +++ b/code/game/src/items.c @@ -11,19 +11,6 @@ #include "items_list.c" #define ITEMS_COUNT (sizeof(items)/sizeof(item_desc)) -uint64_t item_spawn(asset_id kind, uint32_t qty) { - ecs_entity_t e = entity_spawn(EKIND_ITEM); - - ItemDrop *d = ecs_get_mut(world_ecs(), e, ItemDrop, NULL); - *d = (ItemDrop){ - .kind = kind, - .quantity = qty, - .merger_time = 0, - }; - - return (uint64_t)e; -} - static inline uint16_t item_resolve_proxy(uint16_t id) { ZPL_ASSERT(id >= 0 && id < ITEMS_COUNT); item_usage usage = items[id].usage; @@ -33,11 +20,30 @@ static inline uint16_t item_resolve_proxy(uint16_t id) { return id; } +static inline asset_id item_fix_kind(asset_id id) { + return items[item_find(id)].kind; +} + +uint64_t item_spawn(asset_id kind, uint32_t qty) { + ecs_entity_t e = entity_spawn(EKIND_ITEM); + + ItemDrop *d = ecs_get_mut(world_ecs(), e, ItemDrop, NULL); + *d = (ItemDrop){ + .kind = item_fix_kind(kind), + .quantity = qty, + .merger_time = 0, + }; + + return (uint64_t)e; +} + uint16_t item_find(asset_id kind) { for (uint16_t i=0; i