11package fr .idarkay .morefeatures .mixin ;
22
33import fr .idarkay .morefeatures .FeaturesClient ;
4+ import net .minecraft .client .gui .Click ;
45import net .minecraft .client .gui .DrawContext ;
56import net .minecraft .client .gui .screen .Screen ;
67import net .minecraft .client .gui .screen .ingame .HandledScreen ;
78import net .minecraft .client .gui .screen .ingame .ScreenHandlerProvider ;
9+ import net .minecraft .client .input .KeyInput ;
810import net .minecraft .item .Item ;
911import net .minecraft .item .ItemStack ;
1012import net .minecraft .item .Items ;
2830@ Mixin (HandledScreen .class )
2931public abstract class HandledScreenMixin <T extends ScreenHandler > extends Screen implements ScreenHandlerProvider <T > {
3032 @ Shadow
31- protected abstract boolean handleHotbarKeyPressed (int keyCode , int scanCode );
33+ protected abstract boolean handleHotbarKeyPressed (KeyInput keyInput );
3234
3335 @ Shadow
3436 @ Nullable
@@ -50,17 +52,17 @@ protected HandledScreenMixin(Text title) {
5052 }
5153
5254 @ Overwrite
53- public boolean keyPressed (int keyCode , int scanCode , int modifiers ) {
54- if (super .keyPressed (keyCode , scanCode , modifiers )) {
55+ public boolean keyPressed (KeyInput keyInput ) {
56+ if (super .keyPressed (keyInput )) {
5557 return true ;
56- } else if (keyCode != 256 && !this .client .options .inventoryKey .matchesKey (keyCode , scanCode )) {
57- this .handleHotbarKeyPressed (keyCode , scanCode );
58+ } else if (keyInput . getKeycode () != 256 && !this .client .options .inventoryKey .matchesKey (keyInput )) {
59+ this .handleHotbarKeyPressed (keyInput );
5860 if (this .focusedSlot != null && this .focusedSlot .hasStack ()) {
59- if (this .client .options .pickItemKey .matchesKey (keyCode , scanCode )) {
61+ if (this .client .options .pickItemKey .matchesKey (keyInput )) {
6062 this .onMouseClick (this .focusedSlot , this .focusedSlot .id , 0 , SlotActionType .CLONE );
61- } else if (this .client .options .dropKey .matchesKey (keyCode , scanCode )) {
62- boolean control = hasControlDown ();
63- if (hasShiftDown () && control ) {
63+ } else if (this .client .options .dropKey .matchesKey (keyInput )) {
64+ boolean control = keyInput . hasCtrlOrCmd ();
65+ if (keyInput . hasShift () && control ) {
6466 Item focusedType = this .focusedSlot .getStack ().getItem ();
6567 if (!focusedType .equals (Items .AIR )) {
6668 for (Slot slot : handler .slots ) {
@@ -80,50 +82,26 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
8082 }
8183 }
8284
83- @ Inject (method = "mouseDragged(DDIDD)Z" , at = @ At ("TAIL" ))
84- public void mouseDragged (double mouseX , double mouseY , int button , double deltaX , double deltaY ,
85- CallbackInfoReturnable <Boolean > cir ) {
86- if ((button == 0 || button == 1 ) && hasShiftDown ()
85+ @ Inject (method = "mouseDragged" , at = @ At ("TAIL" ))
86+ public void mouseDragged (Click click , double offsetX , double offsetY , CallbackInfoReturnable <Boolean > cir ) {
87+ if ((click .button () == 0 || click .button () == 1 ) && click .hasShift ()
8788 && this .client .player .currentScreenHandler .getCursorStack ().isEmpty ()) {
88- Slot slot = this .getSlotAt (mouseX , mouseY );
89+ Slot slot = this .getSlotAt (click . x (), click . y () );
8990 if (slot != null && !slot .getStack ().isEmpty ()) {
90- this .onMouseClick (slot , slot .id , button , SlotActionType .QUICK_MOVE );
91+ this .onMouseClick (slot , slot .id , click . button () , SlotActionType .QUICK_MOVE );
9192 }
9293 }
9394 }
9495
95- @ Inject (method = "drawSlot(Lnet/minecraft/client/gui/DrawContext;Lnet/minecraft/screen/slot/Slot;)V" ,
96- at = @ At ("RETURN" ))
97- private void drawSlot (DrawContext context , Slot slot , CallbackInfo ci ) {
98- // final boolean maj = (InputUtil.isKeyPressed(MinecraftClient.getInstance().getWindow().getHandle(), GLFW.GLFW_KEY_LEFT_SHIFT) || InputUtil.isKeyPressed(MinecraftClient.getInstance().getWindow().getHandle(), GLFW.GLFW_KEY_RIGHT_SHIFT));
96+ @ Inject (method = "drawSlot" , at = @ At ("RETURN" ))
97+ private void drawSlot (DrawContext context , Slot slot , int mouseX , int mouseY , CallbackInfo ci ) {
9998 final ItemStack cursor = this .handler .getCursorStack ();
10099 final ItemStack slotIT = slot .getStack ();
101100 if ((FeaturesClient .options ().lightSameItem && !slotIT .isEmpty ()
102101 && !cursor .isEmpty ()
103102 && slot .getStack ().getItem ().equals (cursor .getItem ()))
104- // || (maj && !slotIT.isEmpty() && this.focusedSlot != null
105- // && !this.focusedSlot.getStack().isEmpty()
106- // && this.focusedSlot.getStack().getItem().equals(slotIT.getItem()))
107103 ) {
108104 context .fill (slot .x , slot .y , slot .x + 16 , slot .y + 16 , FeaturesClient .options ().getLightSameItemColor ());
109105 }
110106 }
111-
112- // @Inject(method = "drawItem(Lnet/minecraft/item/ItemStack;IILjava/lang/String;)V", at = @At("HEAD"))
113- // private void drawItem(ItemStack stack, int x, int y, String amountText, CallbackInfo ci) {
114- //
115- // final boolean maj = (InputUtil.isKeyPressed(MinecraftClient.getInstance().getWindow().getHandle(), GLFW.GLFW_KEY_LEFT_SHIFT) || InputUtil.isKeyPressed(MinecraftClient.getInstance().getWindow().getHandle(), GLFW.GLFW_KEY_RIGHT_SHIFT));
116- // final ItemStack cursor = this.handler.getCursorStack();
117- // if ((FeaturesClient.options().lightSameItem && !stack.isEmpty()
118- // && !cursor.isEmpty()
119- // && stack.getItem().equals(cursor.getItem()))
120- // || (maj && !stack.isEmpty() && this.focusedSlot != null
121- // && !this.focusedSlot.getStack().isEmpty()
122- // && this.focusedSlot.getStack().getItem().equals(stack.getItem()))
123- // )
124- // {
125- // fill(RenderSystem.getModelViewStack(), x, y, x + 16, y + 16, FeaturesClient.options().getLightSameItemColor());
126- // }
127- // }
128-
129- }
107+ }
0 commit comments