Skip to content

Commit 5099fbe

Browse files
committed
Allow configuring modifier keys, close #5
1 parent 1f5bbc8 commit 5099fbe

File tree

10 files changed

+72
-10
lines changed

10 files changed

+72
-10
lines changed

changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 1.0.2
4+
5+
- Made CTRL (all matching slots) and ALT (drop) function keys configurable keybinds
6+
37
## 1.0.1
48

59
- Fixed scroll interaction breaking MouseTweaks scroll behavior in certain inventories

common/src/main/java/dev/terminalmc/moremousetweaks/MoreMouseTweaks.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@
1616

1717
package dev.terminalmc.moremousetweaks;
1818

19+
import com.mojang.blaze3d.platform.InputConstants;
1920
import dev.terminalmc.moremousetweaks.config.Config;
2021
import dev.terminalmc.moremousetweaks.network.InteractionManager;
2122
import dev.terminalmc.moremousetweaks.util.ModLogger;
2223
import net.minecraft.client.Minecraft;
2324
import net.minecraft.core.registries.BuiltInRegistries;
2425

26+
import static dev.terminalmc.moremousetweaks.config.Config.options;
27+
2528
public class MoreMouseTweaks {
2629
public static final String MOD_ID = "moremousetweaks";
2730
public static final String MOD_NAME = "MoreMouseTweaks";
@@ -70,4 +73,20 @@ public static double getMouseY() {
7073
Minecraft mc = Minecraft.getInstance();
7174
return mc.mouseHandler.ypos() * (double) mc.getWindow().getGuiScaledHeight() / (double) mc.getWindow().getScreenHeight();
7275
}
76+
77+
public static boolean isMatchingSlotsKeyDown() {
78+
return isMatchingSlotsKeyDown(Minecraft.getInstance().getWindow().getWindow());
79+
}
80+
81+
public static boolean isMatchingSlotsKeyDown(long window) {
82+
return options().matchingSlotsKey != -1 && InputConstants.isKeyDown(window, options().matchingSlotsKey);
83+
}
84+
85+
public static boolean isDropKeyDown() {
86+
return isDropKeyDown(Minecraft.getInstance().getWindow().getWindow());
87+
}
88+
89+
public static boolean isDropKeyDown(long window) {
90+
return options().dropKey != -1 && InputConstants.isKeyDown(window, options().dropKey);
91+
}
7392
}

common/src/main/java/dev/terminalmc/moremousetweaks/config/Config.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.google.gson.Gson;
2020
import com.google.gson.GsonBuilder;
21+
import com.mojang.blaze3d.platform.InputConstants;
2122
import dev.terminalmc.moremousetweaks.MoreMouseTweaks;
2223
import dev.terminalmc.moremousetweaks.platform.Services;
2324
import net.minecraft.world.item.Item;
@@ -85,6 +86,12 @@ public enum ExtraSlotScope {
8586
INVENTORY,
8687
NONE
8788
}
89+
90+
public static final int matchingSlotsKeyDefault = InputConstants.KEY_LCONTROL;
91+
public int matchingSlotsKey = matchingSlotsKeyDefault;
92+
93+
public static final int dropKeyDefault = InputConstants.KEY_LALT;
94+
public int dropKey = dropKeyDefault;
8895

8996
public static final boolean alwaysMatchByTypeDefault = false;
9097
public boolean alwaysMatchByType = alwaysMatchByTypeDefault;

common/src/main/java/dev/terminalmc/moremousetweaks/gui/screen/ClothScreenProvider.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package dev.terminalmc.moremousetweaks.gui.screen;
1818

19+
import com.mojang.blaze3d.platform.InputConstants;
1920
import dev.terminalmc.moremousetweaks.config.Config;
2021
import me.shedaniel.clothconfig2.api.*;
2122
import net.minecraft.ChatFormatting;
@@ -120,6 +121,24 @@ else if (val > Config.Options.interactionRateMax) return Optional.of(
120121
.setSaveConsumer(val -> options.extraSlotScope = val)
121122
.build());
122123

124+
general.addEntry(eb.startKeyCodeField(localized("option", "matchingSlotsKey"),
125+
InputConstants.getKey(options.matchingSlotsKey, options.matchingSlotsKey))
126+
.setTooltip(localized("option", "matchingSlotsKey.tooltip"))
127+
.setDefaultValue(InputConstants.getKey(Config.Options.matchingSlotsKeyDefault,
128+
Config.Options.matchingSlotsKeyDefault))
129+
.setKeySaveConsumer(val -> options.matchingSlotsKey = val.getValue())
130+
.setAllowMouse(false) // op, default true
131+
.build());
132+
133+
general.addEntry(eb.startKeyCodeField(localized("option", "dropKey"),
134+
InputConstants.getKey(options.dropKey, options.dropKey))
135+
.setTooltip(localized("option", "dropKey.tooltip"))
136+
.setDefaultValue(InputConstants.getKey(Config.Options.dropKeyDefault,
137+
Config.Options.dropKeyDefault))
138+
.setKeySaveConsumer(val -> options.dropKey = val.getValue())
139+
.setAllowMouse(false) // op, default true
140+
.build());
141+
123142
general.addEntry(eb.startBooleanToggle(localized("option", "alwaysMatchByType"),
124143
options.alwaysMatchByType)
125144
.setTooltip(localized("option", "alwaysMatchByType.tooltip"))

common/src/main/java/dev/terminalmc/moremousetweaks/inventory/InventoryHelper.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,12 @@ public static boolean handleSlotClick(Slot slot, int button, ClickType clickType
108108
// Only operate on unlocked slots
109109
if (ItemLocksWrapper.isLocked(slot)) return false;
110110

111-
if (Screen.hasControlDown()) {
111+
if (MoreMouseTweaks.isMatchingSlotsKeyDown()) {
112112
// Quick-move or drop all matching slots
113113
handleControlClick(slot, clickConsumer, slotSupplier);
114114
return true;
115115
}
116-
else if (Screen.hasAltDown()) {
116+
else if (MoreMouseTweaks.isDropKeyDown()) {
117117
// Drop single slot
118118
clickConsumer.call(slot, MouseButton.RIGHT.getValue(), ClickType.THROW);
119119
return true;
@@ -124,8 +124,8 @@ else if (Screen.hasAltDown()) {
124124
private static void handleControlClick(Slot slot, ClickConsumer original,
125125
Supplier<List<Slot>> slotSupplier) {
126126
// Quick-move or throw all matching items
127-
int button = Screen.hasAltDown() ? MouseButton.RIGHT.getValue() : MouseButton.LEFT.getValue();
128-
ClickType clickType = Screen.hasAltDown() ? ClickType.THROW : ClickType.QUICK_MOVE;
127+
int button = MoreMouseTweaks.isDropKeyDown() ? MouseButton.RIGHT.getValue() : MouseButton.LEFT.getValue();
128+
ClickType clickType = MoreMouseTweaks.isDropKeyDown() ? ClickType.THROW : ClickType.QUICK_MOVE;
129129
ItemStack stack = slot.getItem().copy();
130130

131131
// Operate on the original slot immediately to avoid delayed conflict

common/src/main/java/dev/terminalmc/moremousetweaks/mixin/mousetweaks/MixinMain.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
2020
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
21+
import dev.terminalmc.moremousetweaks.MoreMouseTweaks;
2122
import net.minecraft.client.gui.screens.Screen;
2223
import net.minecraft.world.inventory.Slot;
2324
import net.minecraft.world.item.ItemStack;
@@ -39,7 +40,7 @@ public class MixinMain {
3940
* Wraps the first
4041
* {@link com.mojang.blaze3d.platform.InputConstants#isKeyDown}
4142
* invocation in {@link Main#onMouseDrag} to allow MouseTweaks' LMB drag
42-
* functionality to work when CTRL or ALT is pressed, not only SHIFT.
43+
* functionality to work when MoreMouseTweaks' keybinds are pressed.
4344
*/
4445
@WrapOperation(
4546
method = "onMouseDrag",
@@ -50,7 +51,9 @@ public class MixinMain {
5051
)
5152
)
5253
private static boolean wrapIsKeyDown(long window, int key, Operation<Boolean> original) {
53-
return Screen.hasShiftDown() || Screen.hasControlDown() || Screen.hasAltDown();
54+
return Screen.hasShiftDown()
55+
|| MoreMouseTweaks.isMatchingSlotsKeyDown(window)
56+
|| MoreMouseTweaks.isDropKeyDown(window);
5457
}
5558

5659
/**
@@ -68,7 +71,9 @@ private static boolean wrapIsKeyDown(long window, int key, Operation<Boolean> or
6871
)
6972
private static boolean wrapIsEmpty(ItemStack instance, Operation<Boolean> original) {
7073
if (original.call(instance)) {
71-
if (oldSelectedSlot != null && (Screen.hasControlDown() || Screen.hasAltDown())) {
74+
if (oldSelectedSlot != null && (
75+
MoreMouseTweaks.isMatchingSlotsKeyDown()
76+
|| MoreMouseTweaks.isDropKeyDown())) {
7277
handler.clickSlot(oldSelectedSlot, MouseButton.LEFT, Screen.hasShiftDown());
7378
}
7479
return true;

common/src/main/java/dev/terminalmc/moremousetweaks/mixin/quick/craft/MixinRecipeBookComponent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public void keyPressed(int keyCode, int scanCode, int modifiers, CallbackInfoRet
135135
return;
136136
}
137137
int resSlot = menu.getResultSlotIndex();
138-
if (Screen.hasControlDown()) {
138+
if (MoreMouseTweaks.isMatchingSlotsKeyDown()) {
139139
if (
140140
oldRecipeEntry != recipeEntry
141141
|| menu.slots.get(resSlot).getItem().isEmpty()

common/src/main/resources/assets/moremousetweaks/lang/en_us.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
"option.moremousetweaks.qcOverflowMode": "Quick Crafting Overflow Mode",
1616
"option.moremousetweaks.hotbarScope": "Hotbar Scope",
1717
"option.moremousetweaks.extraSlotScope": "Extra Slot Scope",
18+
"option.moremousetweaks.matchingSlotsKey": "Matching Slots Key",
19+
"option.moremousetweaks.matchingSlotsKey.tooltip": "The key to hold to apply an action to all slots with matching items",
20+
"option.moremousetweaks.dropKey": "Drop Key",
21+
"option.moremousetweaks.dropKey.tooltip": "The key to hold to allow dropping items via LMB",
1822
"option.moremousetweaks.alwaysMatchByType": "Always Match by Type",
1923
"option.moremousetweaks.alwaysMatchByType.tooltip": "CTRL-clicking will always match all items of the same type",
2024
"option.moremousetweaks.typeMatchTags": "Type Match Tags",

common/src/main/resources/assets/moremousetweaks/lang/ru_ru.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
"option.moremousetweaks.qcOverflowMode": "Режим переполнения быстрого крафта",
1616
"option.moremousetweaks.hotbarScope": "Режим панели быстрого доступа",
1717
"option.moremousetweaks.extraSlotScope": "Режим дополнительных слотов",
18+
"option.moremousetweaks.matchingSlotsKey": "Matching Slots Key",
19+
"option.moremousetweaks.matchingSlotsKey.tooltip": "The key to hold to apply an action to all slots with matching items",
20+
"option.moremousetweaks.dropKey": "Drop Key",
21+
"option.moremousetweaks.dropKey.tooltip": "The key to hold to allow dropping items via LMB",
1822
"option.moremousetweaks.alwaysMatchByType": "Подбор по типу",
1923
"option.moremousetweaks.alwaysMatchByType.tooltip": "При нажатии CTRL всегда будут соответствовать все предметы одного типа",
2024
"option.moremousetweaks.typeMatchTags": "Теги соответствия типа",
@@ -41,5 +45,5 @@
4145
"extraSlotScope.moremousetweaks.INVENTORY": "Инвентарь",
4246
"extraSlotScope.moremousetweaks.INVENTORY.tooltip": "Дополнительные слоты будут учитываться как часть основного инвентаря",
4347
"extraSlotScope.moremousetweaks.NONE": "Нет",
44-
"extraSlotScope.moremousetweaks.NONE.tooltip": "Дополнительные слоты будут проигнорированы"
48+
"extraSlotScope.moremousetweaks.NONE.tooltip": "Дополнительные слоты будут проигнорированы",
4549
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Neo/Forge version ranges: https://maven.apache.org/enforcer/enforcer-rules/versionRanges.html
44

55
# Project
6-
mod_version=1.0.1
6+
mod_version=1.0.2
77
mod_group=dev.terminalmc
88
mod_id=moremousetweaks
99
mod_id_alt=mmt

0 commit comments

Comments
 (0)