Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 20 additions & 21 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

// For those who want the bleeding edge
buildscript {
repositories {
Expand All @@ -20,14 +19,14 @@ plugins {
id "net.minecraftforge.gradle.forge" version "2.0.2"
}
*/
version = "1.1.1"
version = "1.1.2"
group= "com.kuri0.rawinput" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "rawinput"

minecraft {
version = "1.8.9-11.15.1.2318-1.8.9"
runDir = "run"

// the mappings can be changed at any time, and must be in the following format.
// snapshot_YYYYMMDD snapshot are built nightly.
// stable_# stables are built at the discretion of the MCP team.
Expand All @@ -42,7 +41,7 @@ dependencies {
// or you may define them like so..
//compile "some.group:artifact:version:classifier"
//compile "some.group:artifact:version"

// real examples
//compile 'com.mod-buildcraft:buildcraft:6.0.8:dev' // adds buildcraft to the dev env
//compile 'com.googlecode.efficient-java-matrix-library:ejml:0.24' // adds ejml to the dev env
Expand All @@ -62,21 +61,21 @@ dependencies {
}

processResources
{
// this will ensure that this task is redone when the versions change.
inputs.property "version", project.version
inputs.property "mcversion", project.minecraft.version
{
// this will ensure that this task is redone when the versions change.
inputs.property "version", project.version
inputs.property "mcversion", project.minecraft.version

// replace stuff in mcmod.info, nothing else
from(sourceSets.main.resources.srcDirs) {
include 'mcmod.info'
// replace version and mcversion
expand 'version':project.version, 'mcversion':project.minecraft.version
}
// copy everything else, thats not the mcmod.info
from(sourceSets.main.resources.srcDirs) {
exclude 'mcmod.info'
}
}
// replace stuff in mcmod.info, nothing else
from(sourceSets.main.resources.srcDirs) {
include 'mcmod.info'

// replace version and mcversion
expand 'version':project.version, 'mcversion':project.minecraft.version
}

// copy everything else, thats not the mcmod.info
from(sourceSets.main.resources.srcDirs) {
exclude 'mcmod.info'
}
}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 3 additions & 3 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Sep 14 12:28:28 PDT 2015
#Sat Sep 24 18:44:29 MSK 2022
distributionUrl=https\://services.gradle.org/distributions/gradle-4.8.1-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.7-bin.zip
zipStoreBase=GRADLE_USER_HOME
78 changes: 43 additions & 35 deletions gradlew

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 4 additions & 10 deletions gradlew.bat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

110 changes: 49 additions & 61 deletions src/main/java/com/kuri0/rawinput/RawInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import net.minecraft.client.Minecraft;
import net.minecraft.util.ChatComponentText;
import net.minecraftforge.client.ClientCommandHandler;
import net.minecraft.command.ICommand;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
Expand All @@ -12,73 +13,60 @@
import net.java.games.input.ControllerEnvironment;
import net.java.games.input.Mouse;

@Mod(modid = RawInput.MODID, version = RawInput.VERSION)
@Mod(modid = RawInput.MODID, version = RawInput.VERSION, acceptedMinecraftVersions = "[1.8.9]")
public class RawInput
{
public static final String MODID = "rawinput";
public static final String VERSION = "1.1.1";

public static Mouse mouse;
// Delta for mouse
public static int dx = 0;
public static int dy = 0;

@SuppressWarnings("unchecked")
private static ControllerEnvironment createDefaultEnvironment() throws ReflectiveOperationException {
// Find constructor (class is package private, so we can't access it directly)
Constructor<ControllerEnvironment> constructor = (Constructor<ControllerEnvironment>)
Class.forName("net.java.games.input.DefaultControllerEnvironment").getDeclaredConstructors()[0];
public static final String MODID = "rawinput";
public static final String VERSION = "1.1.2";

// Constructor is package private, so we have to deactivate access control checks
constructor.setAccessible(true);
// Create object with default constructor
return constructor.newInstance();
}
public static Mouse mouse;
public static Controller[] controllers;
public static float dx = 0;
public static float dy = 0;

@EventHandler
public void init(FMLInitializationEvent event)
{
ClientCommandHandler.instance.registerCommand(new RescanCommand());
Minecraft.getMinecraft().mouseHelper = new RawMouseHelper();

Thread inputThread = new Thread(new Runnable() {
@Override
public void run() {
while (true) {
if (mouse == null) {
try {
Controller[] controllers;
controllers = createDefaultEnvironment().getControllers();
for (int i = 0; i < controllers.length; i++) {
if (controllers[i].getType() == Controller.Type.MOUSE) {
controllers[i].poll();
if (((Mouse)controllers[i]).getX().getPollData() != 0.0 || ((Mouse)controllers[i]).getY().getPollData() != 0.0) {
mouse = (Mouse)controllers[i];
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("Found mouse"));
}
}
}
} catch (ReflectiveOperationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
@EventHandler
public void init(FMLInitializationEvent event)
{
ClientCommandHandler.instance.registerCommand(new RescanCommand());
Minecraft.getMinecraft().mouseHelper = new RawMouseHelper();
controllers = ControllerEnvironment.getDefaultEnvironment().getControllers();
Thread inputThread = new Thread(new Runnable() {
@Override
public void run() {
while (true) {
int i = 0;
while (i < controllers.length && mouse == null) {
if (controllers[i].getType() == Controller.Type.MOUSE) {
controllers[i].poll();
float px = ((Mouse) controllers[i]).getX().getPollData();
float py = ((Mouse) controllers[i]).getY().getPollData();
float eps = 0.1f;
if (Math.abs(px) > eps || Math.abs(py) > eps) {
mouse = (Mouse) controllers[i];
try {
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("Found mouse"));
} catch (Exception ignored) {}
}
}
i++;
}
if (mouse != null) {
mouse.poll();
if (Minecraft.getMinecraft().currentScreen == null) {
dx += mouse.getX().getPollData();
dy += mouse.getY().getPollData();
}
} else {
mouse.poll();

dx += (int)mouse.getX().getPollData();
dy += (int)mouse.getY().getPollData();
}
try {
Thread.sleep(1);
}

try {
Thread.sleep(1L);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
});
inputThread.setName("inputThread");
inputThread.start();
}
}
}
});
inputThread.setName("inputThread");
inputThread.start();
}
}

4 changes: 2 additions & 2 deletions src/main/java/com/kuri0/rawinput/RawMouseHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ public class RawMouseHelper extends MouseHelper {
@Override
public void mouseXYChange()
{
this.deltaX = RawInput.dx;
this.deltaX = (int)RawInput.dx;
RawInput.dx = 0;
this.deltaY = -RawInput.dy;
this.deltaY = -(int)RawInput.dy;
RawInput.dy = 0;
}
}
Loading