Skip to content

Commit

Permalink
Merge pull request #5 from GTNewHorizons/lwjgl3-dont-reset-mouse
Browse files Browse the repository at this point in the history
Don't reset cursor position when using lwjgl3
  • Loading branch information
Dream-Master authored Jan 31, 2023
2 parents 96ab445 + b94ebb3 commit c72e2c4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//version: 1675110695
//version: 1675173326
/*
DO NOT CHANGE THIS FILE!
Also, you may replace this file at any time if there is an update available.
Expand Down Expand Up @@ -66,7 +66,7 @@ plugins {
id 'com.diffplug.spotless' version '6.7.2' apply false
id 'com.modrinth.minotaur' version '2.+' apply false
id 'com.matthewprenger.cursegradle' version '1.4.0' apply false
id 'com.gtnewhorizons.retrofuturagradle' version '1.1.2'
id 'com.gtnewhorizons.retrofuturagradle' version '1.1.3'
}
boolean settingsupdated = verifySettingsGradle()
settingsupdated = verifyGitAttributes() || settingsupdated
Expand Down Expand Up @@ -743,6 +743,7 @@ idea {
module {
downloadJavadoc = true
downloadSources = true
inheritOutputDirs = true
}
project {
settings {
Expand Down
16 changes: 11 additions & 5 deletions src/main/java/invtweaks/InvTweaksHandlerShortcuts.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.minecraft.item.ItemStack;

import org.apache.logging.log4j.Logger;
import org.lwjgl.Sys;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;

Expand Down Expand Up @@ -50,11 +51,14 @@ private class ShortcutConfig {
*/
private Map<InvTweaksShortcutType, List<InvTweaksShortcutMapping>> shortcuts;

private boolean newLwjglDetected;

public InvTweaksHandlerShortcuts(Minecraft mc, InvTweaksConfig config) {
super(mc);
this.config = config;
this.pressedKeys = new HashMap<Integer, Boolean>();
this.shortcuts = new HashMap<InvTweaksShortcutType, List<InvTweaksShortcutMapping>>();
this.newLwjglDetected = !Sys.getVersion().startsWith("2.");
}

public void loadShortcuts() {
Expand Down Expand Up @@ -123,12 +127,14 @@ public void handleShortcut() {

// Reset mouse status to prevent default action.
// TODO Find a better solution, like 'anticipate' default action?
Mouse.destroy();
Mouse.create();
if (!newLwjglDetected) {
Mouse.destroy();
Mouse.create();

// Fixes a tiny glitch (Steve looks for a short moment
// at [0, 0] because of the mouse reset).
Mouse.setCursorPosition(ex, ey);
// Fixes a tiny glitch (Steve looks for a short moment
// at [0, 0] because of the mouse reset).
Mouse.setCursorPosition(ex, ey);
}
}

} catch (Exception e) {
Expand Down

0 comments on commit c72e2c4

Please sign in to comment.