diff --git a/source/game/gui/screen_inventory.c b/source/game/gui/screen_inventory.c index 4a919fb..a693849 100644 --- a/source/game/gui/screen_inventory.c +++ b/source/game/gui/screen_inventory.c @@ -104,7 +104,7 @@ static void screen_inventory_update(struct screen* s, float dt) { struct inventory* inv = windowc_get_latest(gstate.windows[WINDOWC_INVENTORY]); - if(input_pressed(IB_INVENTORY) && !inventory_get_picked_item(inv, NULL)) { + if(input_pressed(IB_INVENTORY)) { svin_rpc_send(&(struct server_rpc) { .type = SRPC_WINDOW_CLOSE, .payload.window_close.window = WINDOWC_INVENTORY, @@ -289,8 +289,7 @@ static void screen_inventory_render2D(struct screen* s, int width, int height) { += gutil_control_icon(icon_offset, IB_GUI_CLICK_ALT, "Split stack"); } - if(!inventory_get_picked_item(inv, NULL)) - icon_offset += gutil_control_icon(icon_offset, IB_INVENTORY, "Leave"); + icon_offset += gutil_control_icon(icon_offset, IB_INVENTORY, "Leave"); struct item_data item; if(inventory_get_picked_item(inv, &item)) { diff --git a/source/item/inventory.c b/source/item/inventory.c index 5af8fb7..f7921fb 100644 --- a/source/item/inventory.c +++ b/source/item/inventory.c @@ -184,6 +184,18 @@ bool inventory_get_slot(struct inventory* inv, size_t slot, return inv->items[slot].id > 0; } +void inventory_clear_picked_item(struct inventory* inv) { + assert(inv); + inv->picked_item.id = 0; + inv->picked_item.durability = 0; + inv->picked_item.count = 0; +} + +void inventory_set_picked_item(struct inventory* inv, struct item_data item) { + assert(inv); + inv->picked_item = item; +} + bool inventory_get_picked_item(struct inventory* inv, struct item_data* item) { assert(inv); diff --git a/source/item/inventory.h b/source/item/inventory.h index 05d84dc..c4f1987 100644 --- a/source/item/inventory.h +++ b/source/item/inventory.h @@ -38,6 +38,8 @@ #define INVENTORY_SLOT_MAIN 9 #define INVENTORY_SLOT_HOTBAR 36 +#define SPECIAL_SLOT_PICKED_ITEM 255 + struct inventory { struct item_data picked_item; struct item_data* items; @@ -70,6 +72,8 @@ void inventory_set_slot(struct inventory* inv, size_t slot, void inventory_clear_slot(struct inventory* inv, size_t slot); bool inventory_get_slot(struct inventory* inv, size_t slot, struct item_data* item); +void inventory_clear_picked_item(struct inventory* inv); +void inventory_set_picked_item(struct inventory* inv, struct item_data item); bool inventory_get_picked_item(struct inventory* inv, struct item_data* item); bool inventory_action(struct inventory* inv, size_t slot, bool right); diff --git a/source/item/window_container.c b/source/item/window_container.c index 8ad05ac..f43ee37 100644 --- a/source/item/window_container.c +++ b/source/item/window_container.c @@ -137,7 +137,12 @@ void windowc_slot_change(struct window_container* wc, size_t slot, ilist_inventory_it(it, wc->invs); struct inventory* prev = ilist_inventory_ref(it); - inventory_set_slot(prev, slot, item); + + if(slot == SPECIAL_SLOT_PICKED_ITEM) { + inventory_set_picked_item(prev, item); + } else { + inventory_set_slot(prev, slot, item); + } ilist_inventory_next(it); diff --git a/source/network/server_local.c b/source/network/server_local.c index dbe3f6f..540d439 100644 --- a/source/network/server_local.c +++ b/source/network/server_local.c @@ -134,6 +134,22 @@ static void server_local_process(struct server_rpc* call, void* user) { = s->player.inventory.items[k], }); } + + struct item_data picked_item; + if(inventory_get_picked_item(&s->player.inventory, + &picked_item)) { + inventory_clear_picked_item(&s->player.inventory); + spawn_item((vec3) {s->player.x, s->player.y, s->player.z}, + &picked_item, true, s); + + clin_rpc_send(&(struct client_rpc) { + .type = CRPC_INVENTORY_SLOT, + .payload.inventory_slot.window = WINDOWC_INVENTORY, + .payload.inventory_slot.slot = NETWORK_SLOT_PICKED_ITEM, + .payload.inventory_slot.item + = s->player.inventory.picked_item, + }); + } } break; case SRPC_BLOCK_DIG: