diff --git a/gradle.properties b/gradle.properties index efc5129..1844a99 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ yarn_mappings=1.20.6+build.3 loader_version=0.15.11 # Mod Properties -mod_version=1.6 +mod_version=1.7 maven_group=systems.brn archives_base_name=Server_storage diff --git a/src/main/java/systems/brn/server_storage/lib/StorageOperations.java b/src/main/java/systems/brn/server_storage/lib/StorageOperations.java index bb38952..a3d8f8a 100644 --- a/src/main/java/systems/brn/server_storage/lib/StorageOperations.java +++ b/src/main/java/systems/brn/server_storage/lib/StorageOperations.java @@ -240,24 +240,28 @@ public class StorageOperations { return stack; } - // Method to check if an item can be inserted into a player's inventory - public static boolean canInsertItemIntoPlayerInventory(PlayerEntity player, ItemStack itemStack) { + public static int canInsertItemIntoPlayerInventory(PlayerEntity player, ItemStack itemStack) { // Get the player's inventory PlayerInventory playerInventory = player.getInventory(); + int maxInsert = 0; + // Iterate through the slots in the player's inventory for (int i = 0; i < playerInventory.main.size(); i++) { ItemStack slotStack = playerInventory.main.get(i); // Check if the slot is empty or if there's space for the item - if ( - slotStack.isEmpty() || - (ItemStack.areItemsEqual(slotStack, itemStack) && slotStack.getCount() + itemStack.getCount() <= slotStack.getMaxCount())) { - return true; // Space available + if (slotStack.isEmpty() || ItemStack.areItemsEqual(slotStack, itemStack)) { + int remainingSpace = slotStack.isEmpty() ? itemStack.getMaxCount() : slotStack.getMaxCount() - slotStack.getCount(); + maxInsert += remainingSpace; + // If the maximum insertion count is greater than or equal to the item count, return the item count + if (maxInsert >= itemStack.getCount()) { + return Math.min(itemStack.getCount(), remainingSpace); + } } } - return false; // No space available + return maxInsert; // Return the maximum insertion count } private static boolean canCombine(ItemStack stack1, ItemStack stack2) { diff --git a/src/main/java/systems/brn/server_storage/screens/StorageScreen.java b/src/main/java/systems/brn/server_storage/screens/StorageScreen.java index 0a92ba6..526c8f0 100644 --- a/src/main/java/systems/brn/server_storage/screens/StorageScreen.java +++ b/src/main/java/systems/brn/server_storage/screens/StorageScreen.java @@ -87,9 +87,13 @@ public class StorageScreen extends PagedGui { if (noLoreStack.getCount() > noLoreStack.getMaxCount()) { noLoreStack.setCount(noLoreStack.getMaxCount()); } - if (canRemoveFromInventory(inventory, noLoreStack) && canInsertItemIntoPlayerInventory(player, noLoreStack)) { - player.getInventory().insertStack(noLoreStack.copy()); - removeItemStackFromChests(inventories, noLoreStack); + int maxToInsert = canInsertItemIntoPlayerInventory(player, noLoreStack); + int insertCount = Math.min(maxToInsert, noLoreStack.getCount()); + ItemStack insertingStack = noLoreStack.copy(); + insertingStack.setCount(insertCount); + if (canRemoveFromInventory(inventory, noLoreStack) && insertCount > 0) { + player.getInventory().insertStack(insertingStack.copy()); + removeItemStackFromChests(inventories, insertingStack); } } this.updateDisplay();