Skip to content

Commit af7ef3f

Browse files
authored
Merge pull request #4
Support for Mouse Buttons
2 parents c602f1d + 5036f29 commit af7ef3f

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

src/main/java/net/anvian/inventorytweaks/mixin/MixinKeyInputHandler.java

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import net.minecraft.client.gui.screen.ingame.InventoryScreen;
1010
import net.minecraft.screen.ScreenHandler;
1111
import org.spongepowered.asm.mixin.Mixin;
12+
import org.spongepowered.asm.mixin.Unique;
1213
import org.spongepowered.asm.mixin.injection.At;
1314
import org.spongepowered.asm.mixin.injection.Inject;
1415
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@@ -18,14 +19,30 @@ public class MixinKeyInputHandler {
1819
@Inject(method = "keyPressed", at = @At("HEAD"))
1920
private void onKeyPressed(int keyCode, int scanCode, int modifiers, CallbackInfoReturnable<Boolean> cir) {
2021
if (ModKeyBinding.keyBinding.matchesKey(keyCode, scanCode)) {
21-
ScreenHandler screenHandler = MinecraftClient.getInstance().player.currentScreenHandler;
22-
Screen screen = MinecraftClient.getInstance().currentScreen;
22+
inventoryTweakSortingKeyPressed();
23+
}
24+
}
25+
26+
@Inject(method = "mouseClicked", at = @At("HEAD"))
27+
private void onMouseClicked(double mouseX, double mouseY, int button, CallbackInfoReturnable<Boolean> cir) {
28+
if (ModKeyBinding.keyBinding.matchesMouse(button)) {
29+
inventoryTweakSortingKeyPressed();
30+
}
31+
}
32+
33+
@Unique
34+
private void inventoryTweakSortingKeyPressed() {
35+
if (MinecraftClient.getInstance().player == null) {
36+
return;
37+
}
38+
39+
ScreenHandler screenHandler = MinecraftClient.getInstance().player.currentScreenHandler;
40+
Screen screen = MinecraftClient.getInstance().currentScreen;
2341

24-
if (screen instanceof InventoryScreen || screen instanceof CreativeInventoryScreen) {
25-
SortInventory.sortPlayerInventory(screenHandler);
26-
} else {
27-
SortInventory.sortContainerInventory(screenHandler);
28-
}
42+
if (screen instanceof InventoryScreen || screen instanceof CreativeInventoryScreen) {
43+
SortInventory.sortPlayerInventory(screenHandler);
44+
} else {
45+
SortInventory.sortContainerInventory(screenHandler);
2946
}
3047
}
3148
}

0 commit comments

Comments
 (0)