Skip to content

Commit

Permalink
Allow drop key to work properly with side mouse buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
Mixces committed Aug 9, 2024
1 parent 84e3fe7 commit 9e268da
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,34 @@

import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.Slot;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(GuiContainer.class)
public abstract class GuiContainerMixin_MouseBindFix extends GuiScreen {
@Shadow
private Slot theSlot;

@Shadow
protected abstract void handleMouseClick(Slot par1, int par2, int par3, int par4);

@Inject(method = "mouseClicked", at = @At("HEAD"), cancellable = true)
private void patcher$checkCloseClick(int mouseX, int mouseY, int mouseButton, CallbackInfo ci) {
if (mouseButton - 100 == mc.gameSettings.keyBindInventory.getKeyCode()) {
int keyCode = mouseButton - 100;
if (keyCode == mc.gameSettings.keyBindInventory.getKeyCode()) {
mc.thePlayer.closeScreen();
ci.cancel();
}
if (theSlot != null && theSlot.getHasStack()) {
if (keyCode == mc.gameSettings.keyBindPickBlock.getKeyCode()) {
handleMouseClick(theSlot, theSlot.slotNumber, 0, 3);
} else if (keyCode == mc.gameSettings.keyBindDrop.getKeyCode()) {
handleMouseClick(theSlot, theSlot.slotNumber, isCtrlKeyDown() ? 1 : 0, 4);
}
}
}
}

0 comments on commit 9e268da

Please sign in to comment.