diff --git a/gradle.properties b/gradle.properties index 32bf1a7..4ac4cd1 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.8 +mod_version=1.9 maven_group=systems.brn archives_base_name=Server_storage diff --git a/src/main/java/systems/brn/server_storage/lib/PagedGui.java b/src/main/java/systems/brn/server_storage/lib/PagedGui.java index 8e78ab3..b808d8f 100644 --- a/src/main/java/systems/brn/server_storage/lib/PagedGui.java +++ b/src/main/java/systems/brn/server_storage/lib/PagedGui.java @@ -30,7 +30,7 @@ public abstract class PagedGui extends SimpleGui { public static final String GUI_REFRESH = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDc1ZDNkYjAzZGMyMWU1NjNiMDM0MTk3ZGE0MzViNzllY2ZlZjRiOGUyZWNkYjczMGUzNzBjMzE2NjI5ZDM2ZiJ9fX0="; public static final String GUI_A = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNGU0MTc0ODEyMTYyNmYyMmFlMTZhNGM2NjRjNzMwMWE5ZjhlYTU5MWJmNGQyOTg4ODk1NzY4MmE5ZmRhZiJ9fX0="; public static final String GUI_1 = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvY2E1MTZmYmFlMTYwNThmMjUxYWVmOWE2OGQzMDc4NTQ5ZjQ4ZjZkNWI2ODNmMTljZjVhMTc0NTIxN2Q3MmNjIn19fQ=="; - + public static final String GUI_STORE_ALL = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMWFkNmM4MWY4OTlhNzg1ZWNmMjZiZTFkYzQ4ZWFlMmJjZmU3NzdhODYyMzkwZjU3ODVlOTViZDgzYmQxNGQifX19"; public static final int PAGE_SIZE = 9 * 5; protected final Runnable closeCallback; @@ -128,6 +128,7 @@ public abstract class PagedGui extends SimpleGui { this.updateDisplay(); }) ); + case 5 -> this.storeAll(); case 6 -> DisplayElement.nextPage(this); case 8 -> DisplayElement.of( new GuiElementBuilder(Items.STRUCTURE_VOID) @@ -146,6 +147,8 @@ public abstract class PagedGui extends SimpleGui { protected abstract DisplayElement sorting(); + protected abstract DisplayElement storeAll(); + public record DisplayElement(@Nullable GuiElementInterface element, @Nullable Slot slot) { private static final DisplayElement EMPTY = DisplayElement.of(new GuiElement(ItemStack.EMPTY, GuiElementInterface.EMPTY_CALLBACK)); 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 f0af978..4aff346 100644 --- a/src/main/java/systems/brn/server_storage/lib/StorageOperations.java +++ b/src/main/java/systems/brn/server_storage/lib/StorageOperations.java @@ -278,7 +278,7 @@ public class StorageOperations { 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 Math.min(itemStack.getCount(), maxInsert); } } } @@ -286,7 +286,7 @@ public class StorageOperations { return maxInsert; // Return the maximum insertion count } - private static boolean canCombine(ItemStack stack1, ItemStack stack2) { + public static boolean canCombine(ItemStack stack1, ItemStack stack2) { return !stack1.isEmpty() && stack1.getItem() == stack2.getItem() && ItemStack.areItemsAndComponentsEqual(stack1, 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 a049fa2..0253726 100644 --- a/src/main/java/systems/brn/server_storage/screens/StorageScreen.java +++ b/src/main/java/systems/brn/server_storage/screens/StorageScreen.java @@ -85,19 +85,34 @@ public class StorageScreen extends PagedGui { if (clickedElement != null) { ItemStack clickedItem = clickedElement.getItemStack(); ItemStack noLoreStack = removeCountFromLore(clickedItem); - if (noLoreStack.getCount() > noLoreStack.getMaxCount() && !type.shift) { - noLoreStack.setCount(noLoreStack.getMaxCount()); + if (type.isRight) { + if (!type.shift) { + noLoreStack.setCount(Math.min(noLoreStack.getMaxCount(), noLoreStack.getCount() / 2)); //half stack + } else { + for (int i = 0; i < player.getInventory().main.size(); i++) { + ItemStack stack = player.getInventory().main.get(i); + if (ItemStack.areItemsAndComponentsEqual(stack, noLoreStack)) { + insertItem(stack, 0, this.getVirtualSize(), false); + } + } + } + + } else if (type.isLeft) { + if (noLoreStack.getCount() > noLoreStack.getMaxCount() && !type.shift) { + noLoreStack.setCount(noLoreStack.getMaxCount()); // if not shift, get one stack + } } - 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); + if (!(type.isRight && type.shift)) { + int insertCount = canInsertItemIntoPlayerInventory(player, noLoreStack); + ItemStack insertingStack = noLoreStack.copy(); + insertingStack.setCount(insertCount); + if (canRemoveFromInventory(inventory, noLoreStack) && insertCount > 0) { + player.getInventory().insertStack(insertingStack.copy()); + removeItemStackFromChests(inventories, insertingStack); + this.updateDisplay(); + } } } - this.updateDisplay(); return false; } @@ -140,6 +155,23 @@ public class StorageScreen extends PagedGui { ); } + @Override + protected DisplayElement storeAll() { + return DisplayElement.of( + new GuiElementBuilder(Items.PLAYER_HEAD) + .setName(Text.translatable("gui.all").formatted(Formatting.WHITE)) + .hideDefaultTooltip().noDefaults() + .setSkullOwner(GUI_STORE_ALL) + .setCallback((x, y, z) -> { + playClickSound(this.player); + for (int i = 0; i < player.getInventory().main.size(); i++) { + ItemStack stack = player.getInventory().main.get(i); + insertItem(stack, 0, this.getVirtualSize(), false); + } + }) + ); + } + public void doSearch(String query) { this.query = query; this.page = 0;