@@ -287,14 +287,21 @@ private boolean is_currently_open(@Nullable ItemStack item) {
287287 private void update_storage_item (@ NotNull ItemStack item , @ NotNull Inventory inventory ) {
288288 // Find the correct storage item if it was moved from inventory slot and is no longer valid
289289 if (item .getType ().isAir () && inventory .getHolder () instanceof Player player ) {
290- for (ItemStack checked_item : player .getInventory ().getContents ()) {
291- if (checked_item == null || !checked_item .hasItemMeta ()) {
292- continue ;
293- }
294- if (is_currently_open (checked_item )) {
295- item = checked_item ; // Found the storage item that is currently open
296- open_block_state_inventories .put (inventory , Pair .of (player .getUniqueId (), item )); // Update Map
297- break ;
290+ // Check cursor item first
291+ var cursor_item = player .getOpenInventory ().getCursor ();
292+ if (cursor_item .hasItemMeta () && is_currently_open (cursor_item )) {
293+ item = cursor_item ; // Found the storage item that is currently open
294+ open_block_state_inventories .put (inventory , Pair .of (player .getUniqueId (), item )); // Update Map
295+ } else { // else check inventory slots
296+ for (ItemStack checked_item : player .getInventory ().getContents ()) {
297+ if (checked_item == null || !checked_item .hasItemMeta ()) {
298+ continue ;
299+ }
300+ if (is_currently_open (checked_item )) {
301+ item = checked_item ; // Found the storage item that is currently open
302+ open_block_state_inventories .put (inventory , Pair .of (player .getUniqueId (), item )); // Update Map
303+ break ;
304+ }
298305 }
299306 }
300307 }
0 commit comments