From 55a29ff1bfdccc96edf43a7ca50001f176b8ffdb Mon Sep 17 00:00:00 2001 From: NotRyken <127091011+NotRyken@users.noreply.github.com> Date: Mon, 25 Nov 2024 11:56:16 +0800 Subject: [PATCH] Add option to switch between LMB and RMB for bundles --- .../terminalmc/clientsort/config/Config.java | 3 +++ .../gui/screen/ClothScreenProvider.java | 10 ++++++++++ .../inventory/sort/InventorySorter.java | 19 +++++++++++-------- .../assets/clientsort/lang/en_us.json | 3 +++ .../assets/clientsort/lang/ru_ru.json | 3 +++ .../assets/clientsort/lang/zh_cn.json | 3 +++ .../assets/clientsort/lang/zh_tw.json | 3 +++ 7 files changed, 36 insertions(+), 8 deletions(-) diff --git a/common/src/main/java/dev/terminalmc/clientsort/config/Config.java b/common/src/main/java/dev/terminalmc/clientsort/config/Config.java index f7988ad..6b21912 100644 --- a/common/src/main/java/dev/terminalmc/clientsort/config/Config.java +++ b/common/src/main/java/dev/terminalmc/clientsort/config/Config.java @@ -64,6 +64,9 @@ public String lowerName() { } } + public static final boolean defaultRmbBundle = false; + public boolean rmbBundle = defaultRmbBundle; + // Sorting public static final String defaultSortMode = SortMode.CREATIVE.name; public String sortModeStr = defaultSortMode; diff --git a/common/src/main/java/dev/terminalmc/clientsort/gui/screen/ClothScreenProvider.java b/common/src/main/java/dev/terminalmc/clientsort/gui/screen/ClothScreenProvider.java index 5ebd51d..6f3afeb 100644 --- a/common/src/main/java/dev/terminalmc/clientsort/gui/screen/ClothScreenProvider.java +++ b/common/src/main/java/dev/terminalmc/clientsort/gui/screen/ClothScreenProvider.java @@ -89,6 +89,16 @@ else if (val > 100) return Optional.of( .setSaveConsumer(val -> options.hotbarMode = val) .build()); + general.addEntry(eb.startBooleanToggle(localized("option", "rmbBundle"), + options.rmbBundle) + .setTooltip(localized("option", "rmbBundle.tooltip")) + .setDefaultValue(Config.Options.defaultRmbBundle) + .setSaveConsumer(val -> { + options.rmbBundle = val; + if (val) CreativeSearchOrder.tryRefreshItemSearchPositionLookup(); + }) + .build()); + ConfigCategory sort = builder.getOrCreateCategory(localized("option", "sorting")); sort.addEntry(eb.startSelector(localized("option", "sortMode"), diff --git a/common/src/main/java/dev/terminalmc/clientsort/inventory/sort/InventorySorter.java b/common/src/main/java/dev/terminalmc/clientsort/inventory/sort/InventorySorter.java index 5412a94..6709847 100644 --- a/common/src/main/java/dev/terminalmc/clientsort/inventory/sort/InventorySorter.java +++ b/common/src/main/java/dev/terminalmc/clientsort/inventory/sort/InventorySorter.java @@ -17,6 +17,7 @@ package dev.terminalmc.clientsort.inventory.sort; +import dev.terminalmc.clientsort.config.Config; import dev.terminalmc.clientsort.inventory.ContainerScreenHelper; import dev.terminalmc.clientsort.network.InteractionManager; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; @@ -201,18 +202,20 @@ protected void sortOnClient(int[] sortedIds) { } // swap the current stack with the target stack - if ((backingStacks[id] instanceof BundleItem && !(carriedItem instanceof AirItem)) - || (carriedItem instanceof BundleItem && !(backingStacks[id] instanceof AirItem))) { - temp = backingStacks[id]; - backingStacks[id] = carriedItem; - carriedItem = temp; + if ( + Config.get().options.rmbBundle + && ( + (backingStacks[id] instanceof BundleItem && !(carriedItem instanceof AirItem)) + || (carriedItem instanceof BundleItem && !(backingStacks[id] instanceof AirItem)) + ) + ) { InteractionManager.push(screenHelper.createClickEvent(inventorySlots[id], 1, ClickType.PICKUP)); } else { - temp = backingStacks[id]; - backingStacks[id] = carriedItem; - carriedItem = temp; InteractionManager.push(screenHelper.createClickEvent(inventorySlots[id], 0, ClickType.PICKUP)); } + temp = backingStacks[id]; + backingStacks[id] = carriedItem; + carriedItem = temp; currentStack = stacks[id]; doneSlashEmpty.set(id); // mark the current target as done // If the target that we just swapped with was empty before, then this breaks the chain. diff --git a/common/src/main/resources/assets/clientsort/lang/en_us.json b/common/src/main/resources/assets/clientsort/lang/en_us.json index 22d2db6..ccaaa7b 100644 --- a/common/src/main/resources/assets/clientsort/lang/en_us.json +++ b/common/src/main/resources/assets/clientsort/lang/en_us.json @@ -12,6 +12,9 @@ "option.clientsort.interactionRateClient": "Singleplayer Interaction Rate", "option.clientsort.interactionRate.tooltip": "Reduce to sort faster, increase if you are experiencing packet rate issues", "option.clientsort.hotbarMode": "Hotbar Mode", + "option.clientsort.rmbBundle": "Bundles use Right Click", + "option.clientsort.rmbBundle.tooltip": "In 1.21.2+, bundles use right-click to load and unload, which breaks sorting. If playing on a 1.21.2+ server, enable this option.", + "option.clientsort.sorting": "Sorting", "option.clientsort.sortMode": "Sort Mode", "option.clientsort.shiftSortMode": "Shift Sort Mode", diff --git a/common/src/main/resources/assets/clientsort/lang/ru_ru.json b/common/src/main/resources/assets/clientsort/lang/ru_ru.json index 6cc3c88..4f425fc 100644 --- a/common/src/main/resources/assets/clientsort/lang/ru_ru.json +++ b/common/src/main/resources/assets/clientsort/lang/ru_ru.json @@ -12,6 +12,9 @@ "option.clientsort.interactionRateClient": "Скорость локального взаимодействия", "option.clientsort.interactionRate.tooltip": "Уменьшите, чтобы ускорить сортировку, увеличьте, если у вас возникли проблемы со скоростью передачи пакетов", "option.clientsort.hotbarMode": "Режим горячей панели", + "option.clientsort.rmbBundle": "Bundles use Right Click", + "option.clientsort.rmbBundle.tooltip": "In 1.21.2+, bundles use right-click to load and unload, which breaks sorting. If playing on a 1.21.2+ server, enable this option.", + "option.clientsort.sorting": "Сортировка", "option.clientsort.sortMode": "Режим сортировки", "option.clientsort.shiftSortMode": "Режим сортировки по Shift", diff --git a/common/src/main/resources/assets/clientsort/lang/zh_cn.json b/common/src/main/resources/assets/clientsort/lang/zh_cn.json index 2b1c21d..fdea9ea 100644 --- a/common/src/main/resources/assets/clientsort/lang/zh_cn.json +++ b/common/src/main/resources/assets/clientsort/lang/zh_cn.json @@ -12,6 +12,9 @@ "option.clientsort.interactionRateClient": "单机模式交互速率", "option.clientsort.interactionRate.tooltip": "降低值可更快整理, 若遇到发包速率问题, 请将该值增加", "option.clientsort.hotbarMode": "快捷栏模式", + "option.clientsort.rmbBundle": "Bundles use Right Click", + "option.clientsort.rmbBundle.tooltip": "In 1.21.2+, bundles use right-click to load and unload, which breaks sorting. If playing on a 1.21.2+ server, enable this option.", + "option.clientsort.sorting": "整理", "option.clientsort.sortMode": "整理模式", "option.clientsort.shiftSortMode": "Shift 键整理模式", diff --git a/common/src/main/resources/assets/clientsort/lang/zh_tw.json b/common/src/main/resources/assets/clientsort/lang/zh_tw.json index 66eea12..ab5dbe1 100644 --- a/common/src/main/resources/assets/clientsort/lang/zh_tw.json +++ b/common/src/main/resources/assets/clientsort/lang/zh_tw.json @@ -12,6 +12,9 @@ "option.clientsort.interactionRateClient": "單人遊戲排序速率", "option.clientsort.interactionRate.tooltip": "降低以更快排序,如果遇到封包速率問題則提高", "option.clientsort.hotbarMode": "快捷欄模式", + "option.clientsort.rmbBundle": "Bundles use Right Click", + "option.clientsort.rmbBundle.tooltip": "In 1.21.2+, bundles use right-click to load and unload, which breaks sorting. If playing on a 1.21.2+ server, enable this option.", + "option.clientsort.sorting": "排序", "option.clientsort.sortMode": "排序模式", "option.clientsort.shiftSortMode": "Shift 排序模式",