diff --git a/src/main/java/net/silentclient/client/utils/RawInputHandler.java b/src/main/java/net/silentclient/client/utils/RawInputHandler.java index e1bc887..db4e3f8 100644 --- a/src/main/java/net/silentclient/client/utils/RawInputHandler.java +++ b/src/main/java/net/silentclient/client/utils/RawInputHandler.java @@ -4,16 +4,19 @@ 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; + public static Controller[] controllers; public static Mouse mouse; public static int dx = 0; public static int dy = 0; public static void init() { controllers = ControllerEnvironment.getDefaultEnvironment().getControllers(); + startThread(); } public static void getMouse() { @@ -28,36 +31,50 @@ public class RawInputHandler { } public static void toggleRawInput(boolean enable) { - if(enable) { - Minecraft.getMinecraft().mouseHelper = new RawMouseHelper(); - controllers = ControllerEnvironment.getDefaultEnvironment().getControllers(); + EntityPlayerSP player = Minecraft.getMinecraft().thePlayer; + float saveYaw = player.rotationYaw; + float savePitch = player.rotationPitch; - Thread inputThread = new Thread(() -> { - while (true) { - RawInputHandler.getMouse(); - if (mouse != null) { - mouse.poll(); - - dx += (int) mouse.getX().getPollData(); - dy += (int) mouse.getY().getPollData(); - } else { - RawInputHandler.rescan(); - } - try { - Thread.sleep(1); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - }); - inputThread.setName("inputThread"); - inputThread.start(); - } else { + if (Minecraft.getMinecraft().mouseHelper instanceof RawMouseHelper && !enable) { + Client.logger.info("[SC]: Disabling Raw Mouse Input"); Minecraft.getMinecraft().mouseHelper = new MouseHelper(); + Minecraft.getMinecraft().mouseHelper.grabMouseCursor(); + Minecraft.getMinecraft().mouseHelper.ungrabMouseCursor(); + } else { + Client.logger.info("[SC]: Enabling Raw Mouse Input"); + Minecraft.getMinecraft().mouseHelper = new RawMouseHelper(); + Minecraft.getMinecraft().mouseHelper.grabMouseCursor(); + Minecraft.getMinecraft().mouseHelper.ungrabMouseCursor(); } + player.rotationYaw = saveYaw; + player.rotationPitch = savePitch; } public static void rescan() { RawInputHandler.getMouse(); } -} + + public static void startThread() { + Thread inputThread = new Thread(() -> { + while(true){ + if (mouse != null && Minecraft.getMinecraft().currentScreen == null) { + mouse.poll(); + dx += (int)mouse.getX().getPollData(); + dy += (int)mouse.getY().getPollData(); + } else if (mouse != null) { + mouse.poll(); + } else { + getMouse(); + } + + try { + Thread.sleep(1); + } catch(InterruptedException e) { + e.printStackTrace(); + } + } + }); + inputThread.setName("inputThread"); + inputThread.start(); + } +} \ No newline at end of file