Skip to content

Commit 44c7469

Browse files
committed
made it possible to grab mouses after their connection type is updated
1 parent e390977 commit 44c7469

File tree

6 files changed

+22
-12
lines changed

6 files changed

+22
-12
lines changed

build.gradle.kts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ dependencies {
6767
mappings("de.oceanlabs.mcp:mcp_stable:22-1.8.9")
6868
forge("net.minecraftforge:forge:1.8.9-11.15.1.2318-1.8.9")
6969

70-
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4")
71-
70+
shadowImpl("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4")
7271
shadowImpl(kotlin("stdlib-jdk8"))
7372
}
7473

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ org.gradle.jvmargs=-Xmx2g
33
baseGroup = com.github.subat0m1c.rawinput
44
mcVersion = 1.8.9
55
modid = rawinput
6-
version = 1.0.1
6+
version = 1.0.2

src/main/kotlin/com/github/subat0m1c/rawinput/RawInput.kt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,29 @@ import net.minecraft.util.ChatComponentText
99
object RawInput {
1010
var mouse: Mouse? = null
1111

12+
/**
13+
* Controllers are only grabbed once on launch, so we need to force a reset in the event of mouse connections changing during runtime.
14+
* using reflection for this is really slow i think but i dont wanna make a mixin for this garbage
15+
*/
16+
fun resetControllers() = runCatching {
17+
ControllerEnvironment::class.java.getDeclaredField("defaultEnvironment").apply {
18+
isAccessible = true
19+
set(null, Class.forName("net.java.games.input.DefaultControllerEnvironment").getDeclaredConstructor().apply {
20+
isAccessible = true
21+
}.newInstance())
22+
}
23+
}
24+
1225
fun findMouse() {
13-
for (controller in ControllerEnvironment.getDefaultEnvironment().controllers) {
26+
ControllerEnvironment.getDefaultEnvironment().controllers.forEach { controller ->
1427
if (controller.type == Controller.Type.MOUSE) {
1528
controller.poll()
1629
val mouseController = controller as Mouse
1730
if (mouseController.x.pollData != 0f || mouseController.y.pollData != 0f) {
1831
mouse = mouseController
1932
mc.thePlayer?.addChatMessage(ChatComponentText("Mouse found: ${mouseController.name}"))
2033
?: println("Mouse found: ${mouseController.name}")
21-
break
34+
return
2235
}
2336
}
2437
}

src/main/kotlin/com/github/subat0m1c/rawinput/commands/ConfigCommand.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class ConfigCommand : CommandBase() {
1313

1414
override fun processCommand(sender: ICommandSender?, args: Array<out String>?) {
1515
if (args == null || args.isEmpty()) {
16-
sender?.addChatMessage(ChatComponentText("Usage: /rawconfig <maxchange|view> <int?>")) // waittime|
16+
sender?.addChatMessage(ChatComponentText("Usage: /rawconfig <maxchange|view> <int?>"))
1717
return
1818
}
1919

src/main/kotlin/com/github/subat0m1c/rawinput/commands/RescanCommand.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ class RescanCommand : CommandBase() {
2323
}
2424
}
2525
sender?.addChatMessage(ChatComponentText("Rescanning input devices...") as IChatComponent)
26+
RawInput.resetControllers().onFailure {
27+
sender?.addChatMessage(ChatComponentText("Failed to reset default controllers. If you changed the mouse connection, you may need to restart the game"))
28+
it.printStackTrace()
29+
}
2630
RawInput.mouse = null
2731
}
2832

src/main/kotlin/com/github/subat0m1c/rawinput/config/Config.kt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,6 @@ class Config <T : Any> (val name: String, private val Json: JsonManager<T>) {
3535
{ Json: JsonElement -> Json.asInt },
3636
{ value: Int -> JsonPrimitive(value) }
3737
)
38-
39-
fun floatSetting(default: Float) = JsonManager(
40-
default,
41-
{ Json: JsonElement -> Json.asFloat },
42-
{ value: Float -> JsonPrimitive(value) }
43-
)
4438
}
4539
}
4640

0 commit comments

Comments
 (0)