9
9
import net .minecraft .client .gui .screen .ingame .InventoryScreen ;
10
10
import net .minecraft .screen .ScreenHandler ;
11
11
import org .spongepowered .asm .mixin .Mixin ;
12
+ import org .spongepowered .asm .mixin .Unique ;
12
13
import org .spongepowered .asm .mixin .injection .At ;
13
14
import org .spongepowered .asm .mixin .injection .Inject ;
14
15
import org .spongepowered .asm .mixin .injection .callback .CallbackInfoReturnable ;
@@ -18,14 +19,30 @@ public class MixinKeyInputHandler {
18
19
@ Inject (method = "keyPressed" , at = @ At ("HEAD" ))
19
20
private void onKeyPressed (int keyCode , int scanCode , int modifiers , CallbackInfoReturnable <Boolean > cir ) {
20
21
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 ;
23
41
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 );
29
46
}
30
47
}
31
48
}
0 commit comments