You are an Android now
I was able to finish the microphone selection feature. I also found an issue in the Java<=>Rust bridge library I’m using, called J4RS. When Rust is enumerating microphones it turns them into a Java Microphone record I made. It worked fine in dev env. I try running it from a jar - a ClassNotFoundException. What? Rust was able to access other Java code before. Knowing that I suspected J4RS was doing something weird, so I started looking at it’s source and found this:
if (!IsAndroid) {
return Class.forName(className, true, ClassLoader.getSystemClassLoader());
} else {
return Class.forName(className);
}
J4RS is forcing the use of some system class loader, unless it’s running on Android. Javadocs of Class.forName say calling it with just a name is equivalent to calling Class.forName("Foo", true, this.getClass().getClassLoader()) So I guessed the issue was that the class is not being found because Neoforge’s JarInJar feature does not work with the system class loader.
So, how do we fix it? There is no time for making feature requests, I need to change the IsAndroid variable, which is private static. So what do I do?
Well, in Java nothing is truly private if you use Reflection.
try {
Field isAndroidField = Utils.class.getDeclaredField("IsAndroid");
isAndroidField.setAccessible(true);
isAndroidField.set(null, true);
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new RuntimeException(e);
}
and so, as I guessed, the issue went away.
I also did a quite funny mistake. I implemented the mic selection as a server side command!. That means if you played on a server you would be selecting a microphone for the server (which doesn’t use it). Actually it would probably just crash. Luckily I realized the mistake, and made the command client side.
I also added a bunch of error handling, because we all love when things work right away, but sometimes that’s not the case. Now in most cases if something goes wrong with starting the mic capture the user will be notified.
Additionally I added a /sephyr status command, which reports whether the detection system is loaded, is it running, and what microphone it is using.
I also found out that the IPA writing of wind - the word ʔalɪˈvɑn was wrong, because both ʔ and a sound very similarly, so it basically had two a‘s in the writing. So the ʔ prefix was removed and now it’s just alɪˈvɑn
Comments 0
No comments yet. Be the first!
Sign in to join the conversation.