mirror of
https://github.com/refactorinqq/SLC-1.8.9.git
synced 2024-11-10 09:11:32 +01:00
Update RawInputHandler.java
This commit is contained in:
parent
3337cd65ec
commit
6acba6c85b
@ -4,7 +4,9 @@ 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;
|
||||
@ -14,6 +16,7 @@ public class RawInputHandler {
|
||||
|
||||
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();
|
||||
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 {
|
||||
RawInputHandler.rescan();
|
||||
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) {
|
||||
} catch(InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
inputThread.setName("inputThread");
|
||||
inputThread.start();
|
||||
} else {
|
||||
Minecraft.getMinecraft().mouseHelper = new MouseHelper();
|
||||
}
|
||||
}
|
||||
|
||||
public static void rescan() {
|
||||
RawInputHandler.getMouse();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user