From 76e397244501f78b9475b99089d93d988e75b778 Mon Sep 17 00:00:00 2001 From: NotRyken <127091011+NotRyken@users.noreply.github.com> Date: Tue, 26 Nov 2024 09:41:14 +0800 Subject: [PATCH] Add optional separate grouping of extra slots --- CHANGELOG.md | 1 + .../terminalmc/clientsort/config/Config.java | 17 +++++++++++++++++ .../gui/screen/ClothScreenProvider.java | 11 +++++++++++ .../inventory/ContainerScreenHelper.java | 10 ++++++++-- .../resources/assets/clientsort/lang/en_us.json | 8 ++++++++ 5 files changed, 45 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e52f15..91bd160 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,3 +5,4 @@ - Updated bundle handling - Added Ukrainian translation (ttrafford7) - Added support for ItemLocks +- Added an option to change behavior of extra slots (e.g. offhand) when sorting 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 ef5876b..7690ada 100644 --- a/common/src/main/java/dev/terminalmc/clientsort/config/Config.java +++ b/common/src/main/java/dev/terminalmc/clientsort/config/Config.java @@ -50,6 +50,9 @@ public static class Options { public static final HotbarMode defaultHotbarMode = HotbarMode.HARD; public HotbarMode hotbarMode = defaultHotbarMode; + public static final ExtraSlotMode defaultExtraSlotMode = ExtraSlotMode.NONE; + public ExtraSlotMode extraSlotMode = defaultExtraSlotMode; + public enum HotbarMode { NONE, HARD, @@ -64,6 +67,20 @@ public String lowerName() { } } + public enum ExtraSlotMode { + NONE, + HOTBAR, + INVENTORY; + + public String lowerName() { + return switch(this) { + case NONE -> "none"; + case HOTBAR -> "hotbar"; + case INVENTORY -> "inventory"; + }; + } + } + public static final boolean defaultLmbBundle = false; public boolean lmbBundle = defaultLmbBundle; 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 da6f874..8e1f268 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,17 @@ else if (val > 100) return Optional.of( .setSaveConsumer(val -> options.hotbarMode = val) .build()); + general.addEntry(eb.startEnumSelector(localized("option", "extraSlotMode"), + Config.Options.ExtraSlotMode.class, options.extraSlotMode) + .setEnumNameProvider(val -> localized("extraSlotMode", + ((Config.Options.ExtraSlotMode)val).lowerName())) + .setTooltipSupplier(val -> Optional.of(new Component[]{ + localized("extraSlotMode", val.lowerName() + ".tooltip") + })) + .setDefaultValue(Config.Options.defaultExtraSlotMode) + .setSaveConsumer(val -> options.extraSlotMode = val) + .build()); + general.addEntry(eb.startBooleanToggle(localized("option", "lmbBundle"), options.lmbBundle) .setTooltip(localized("option", "lmbBundle.tooltip")) diff --git a/common/src/main/java/dev/terminalmc/clientsort/inventory/ContainerScreenHelper.java b/common/src/main/java/dev/terminalmc/clientsort/inventory/ContainerScreenHelper.java index 1bd389a..0326b31 100644 --- a/common/src/main/java/dev/terminalmc/clientsort/inventory/ContainerScreenHelper.java +++ b/common/src/main/java/dev/terminalmc/clientsort/inventory/ContainerScreenHelper.java @@ -65,14 +65,20 @@ public int getScope(Slot slot, boolean preferSmallerScopes) { } if (screen instanceof EffectRenderingInventoryScreen) { if (slot.container instanceof Inventory) { + Config.Options options = Config.get().options; if (isHotbarSlot(slot)) { - Config.Options options = Config.get().options; if (options.hotbarMode == Config.Options.HotbarMode.HARD || options.hotbarMode == Config.Options.HotbarMode.SOFT && preferSmallerScopes) { return -1; } } else if (((ISlot) slot).mouseWheelie_getIndexInInv() >= 40) { - return -1; + if (options.extraSlotMode == Config.Options.ExtraSlotMode.NONE) { + return -2; + } else if (options.extraSlotMode == Config.Options.ExtraSlotMode.HOTBAR + && (options.hotbarMode == Config.Options.HotbarMode.HARD + || options.hotbarMode == Config.Options.HotbarMode.SOFT && preferSmallerScopes)) { + return -1; + } } return 0; } else { 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 6b32bd8..278cdf7 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,7 @@ "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.extraSlotMode": "Extra Slot Mode", "option.clientsort.lmbBundle": "Bundles use Left Click", "option.clientsort.lmbBundle.tooltip": "In 1.21.2+, bundles use left-click to load, which breaks sorting. If playing on a 1.21.2+ server, enable this option.", @@ -29,6 +30,13 @@ "hotbarMode.clientsort.off": "Off", "hotbarMode.clientsort.off.tooltip": "Hotbar cannot be sorted", + "extraSlotMode.clientsort.none": "None", + "extraSlotMode.clientsort.none.tooltip": "Extra slots will not be sortable", + "extraSlotMode.clientsort.hotbar": "Hotbar", + "extraSlotMode.clientsort.hotbar.tooltip": "Extra slots will be sorted with the hotbar", + "extraSlotMode.clientsort.inventory": "Inventory", + "extraSlotMode.clientsort.inventory.tooltip": "Extra slots will be sorted with the main inventory", + "sortOrder.clientsort.none": "None", "sortOrder.clientsort.alphabet": "Alphabet", "sortOrder.clientsort.creative": "Creative",