Raw Mouse Input Fix?

This commit is contained in:
kirillsaint 2023-08-31 13:58:03 +06:00
parent f3a00cb1cc
commit 7251b4f0c1
5 changed files with 34 additions and 60 deletions

View File

@ -190,11 +190,6 @@ public class Client {
if(acc != null) {
Client.getInstance().setAccount(acc.getAccount());
}
if(OSUtil.isWindows()) {
logger.info("STARTING > raw-mouse-input");
Minecraft.getMinecraft().mouseHelper = new RawMouseHelper();
RawInputHandler.init();
}
logger.info("STARTING > settings-manager");
settingsManager = new SettingsManager();
logger.info("STARTING > mod-instances");
@ -235,6 +230,12 @@ public class Client {
}
logger.info("STARTING > config-manager");
configManager = new ConfigManager();
if(OSUtil.isWindows()) {
logger.info("STARTING > raw-mouse-input");
Minecraft.getMinecraft().mouseHelper = new RawMouseHelper();
RawInputHandler.init();
RawInputHandler.toggleRawInput(Client.getInstance().getSettingsManager().getSettingByClass(GeneralMod.class, "Raw Mouse Input").getValBoolean());
}
logger.info("STARTING > texture-manager");
this.textureManager = new SCTextureManager(Minecraft.getMinecraft().getResourceManager());
logger.info("STARTING > font-renderer");

View File

@ -75,7 +75,7 @@ public class Mod implements IMod {
mc.renderGlobal.loadRenderers();
}
if(setting.getName() == "Raw Mouse Input") {
RawInputHandler.toggleRawInput(setting.getValBoolean() ? "disable" : "enable");
RawInputHandler.toggleRawInput(setting.getValBoolean());
}
if(setting.getName() == "Menu Background Blur") {
if(setting.getValBoolean()) {

View File

@ -48,7 +48,7 @@ public class GeneralMod extends Mod {
public void onChangeSettingValue(Setting setting) {
switch(setting.getName()) {
case "Raw Mouse Input":
RawInputHandler.toggleRawInput(setting.getValBoolean() ? "enable" : "disable");
RawInputHandler.toggleRawInput(setting.getValBoolean());
break;
case "Menu Background Blur":
if(setting.getValBoolean()) {

View File

@ -4,9 +4,7 @@ import net.java.games.input.Controller;
import net.java.games.input.ControllerEnvironment;
import net.java.games.input.Mouse;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.util.MouseHelper;
import net.silentclient.client.Client;
public class RawInputHandler {
public static Controller[] controllers;
@ -16,7 +14,6 @@ public class RawInputHandler {
public static void init() {
controllers = ControllerEnvironment.getDefaultEnvironment().getControllers();
startThread();
}
public static void getMouse() {
@ -30,41 +27,22 @@ public class RawInputHandler {
}
}
public static void toggleRawInput(String mode) {
EntityPlayerSP player = Minecraft.getMinecraft().thePlayer;
float saveYaw = player.rotationYaw;
float savePitch = player.rotationPitch;
if (Minecraft.getMinecraft().mouseHelper instanceof RawMouseHelper && mode == "disable") {
Client.logger.info("[SC]: Disabling Raw Mouse Input");
Minecraft.getMinecraft().mouseHelper = new MouseHelper();
Minecraft.getMinecraft().mouseHelper.grabMouseCursor();
} else {
Client.logger.info("[SC]: Enabling Raw Mouse Input");
public static void toggleRawInput(boolean enable) {
if(enable) {
Minecraft.getMinecraft().mouseHelper = new RawMouseHelper();
Minecraft.getMinecraft().mouseHelper.grabMouseCursor();
}
player.rotationYaw = saveYaw;
player.rotationPitch = savePitch;
}
controllers = ControllerEnvironment.getDefaultEnvironment().getControllers();
public static void rescan() {
RawInputHandler.getMouse();
}
public static void startThread() {
Thread inputThread = new Thread(() -> {
while (true) {
if (mouse != null && Minecraft.getMinecraft().currentScreen == null) {
RawInputHandler.getMouse();
if (mouse != null) {
mouse.poll();
dx += (int) mouse.getX().getPollData();
dy += (int) mouse.getY().getPollData();
} else if (mouse != null) {
mouse.poll();
} else {
getMouse();
RawInputHandler.rescan();
}
try {
Thread.sleep(1);
} catch (InterruptedException e) {
@ -74,5 +52,12 @@ public class RawInputHandler {
});
inputThread.setName("inputThread");
inputThread.start();
} else {
Minecraft.getMinecraft().mouseHelper = new MouseHelper();
}
}
public static void rescan() {
RawInputHandler.getMouse();
}
}

View File

@ -1,7 +1,5 @@
package net.silentclient.client.utils;
import org.lwjgl.input.Mouse;
import net.minecraft.util.MouseHelper;
public class RawMouseHelper extends MouseHelper {
@ -13,14 +11,4 @@ public class RawMouseHelper extends MouseHelper {
this.deltaY = -RawInputHandler.dy;
RawInputHandler.dy = 0;
}
@Override
public void grabMouseCursor()
{
if (Boolean.parseBoolean(System.getProperty("fml.noGrab","false"))) return;
Mouse.setGrabbed(true);
this.deltaX = 0;
RawInputHandler.dx = 0;
this.deltaY = 0;
RawInputHandler.dy = 0;
}
}