mclauncher-api
mclauncher-api copied to clipboard
Unable to launch Minecraft on versions past 1.18.2
When launching any Minecraft version after 1.18.2 through the API, the game doesn't launch and returns this error in the output stream:
[22:39:08] [Datafixer Bootstrap/INFO]: 198 Datafixer optimizations took 308 milliseconds
[22:39:10] [Render thread/INFO]: [STDERR]: java.lang.NoClassDefFoundError: Could not initialize class com.mojang.blaze3d.systems.RenderSystem
[22:39:10] [Render thread/INFO]: [STDERR]: at ab.a(SourceFile:66)
[22:39:10] [Render thread/INFO]: [STDERR]: at evi.a(SourceFile:2605)
[22:39:10] [Render thread/INFO]: [STDERR]: at evi.a(SourceFile:2580)
[22:39:10] [Render thread/INFO]: [STDERR]: at net.minecraft.client.main.Main.main(SourceFile:233)
[22:39:10] [Render thread/INFO]: [STDERR]: Caused by: java.lang.ExceptionInInitializerError: Exception java.lang.UnsatisfiedLinkError: Failed to locate library: liblwjgl.so [in thread "Render thread"]
[22:39:10] [Render thread/INFO]: [STDERR]: at org.lwjgl.system.Library.loadSystem(Library.java:174)
[22:39:10] [Render thread/INFO]: [STDERR]: at org.lwjgl.system.Library.loadSystem(Library.java:64)
[22:39:10] [Render thread/INFO]: [STDERR]: at org.lwjgl.system.Library.<clinit>(Library.java:52)
[22:39:10] [Render thread/INFO]: [STDERR]: at org.lwjgl.system.MemoryUtil.<clinit>(MemoryUtil.java:100)
[22:39:10] [Render thread/INFO]: [STDERR]: at eoz.<clinit>(SourceFile:8)
[22:39:10] [Render thread/INFO]: [STDERR]: at epw.<init>(SourceFile:49)
[22:39:10] [Render thread/INFO]: [STDERR]: at eqd.<init>(SourceFile:33)
[22:39:10] [Render thread/INFO]: [STDERR]: at com.mojang.blaze3d.systems.RenderSystem.<clinit>(SourceFile:51)
[22:39:10] [Render thread/INFO]: [STDERR]: at net.minecraft.client.main.Main.main(SourceFile:220)
Here's a bit of the code I'm using
File workingDirectory = new File(Platform.getCurrentPlatform().getWorkingDirectory().getPath());
MinecraftLauncherBackend mcLauncherBackend = new MinecraftLauncherBackend(workingDirectory);
System.out.println(mcLauncherBackend.getVersionList());
String version = "1.20.4";
mcLauncherBackend.updateMinecraft(version, null);
ProcessBuilder mcProcessBuilder = mcLauncherBackend.launchMinecraft(loginSession, version);
File output;
output = new File("./temp.txt");
System.out.println(output.getAbsolutePath());
mcProcessBuilder.redirectOutput(output);
mcProcessBuilder.start();
System.out.println(workingDirectory);
System.out.println(Platform.getCurrentPlatform().getWorkingDirectory());
It launches fine when using 1.18.2 and versions below. I honestly don't know if I'm doing something wrong, or if there's something up with the api.
Turns out the natives folder is handled differently pre and post 1.19. Before, each version folder just had a natives folder with all the files in it, but after 1.19, it instead creates a new natives folder for each game launch, and removes it every time the game is quit. I tried manually making a new natives folder, but the game always clears it at the start of each launch, and copying the liblwjgl.so file I downloaded into it while its starting up didn't help.
The natives folder that minecraft generates on startup (when I'm using the normal minecraft launcher) is named '
I made some code to work around the issue, its really scuffed but it works. https://github.com/Cinder4198/MCLauncherAPINativesPatch
First, you want to use NativesVersionChecker to return a boolean for if the version needs the patch or not.
boolean isPost1_19 = new NativesVersionChecker().checker(<version>);
Then, if it returns true, use NativesDownloader to download the natives. You should run this after using MinecraftLauncherBackend.update. The first argument will be where your versions are stored, the second will be which version's natives to download, and the third will be which version folder to download them into. Usually the second and third argument will be the same, but this may not be the case if you're using a modded version or something.
if(isPost1_19)new NativesDownloader(<versionFolderLocation>, <versionNativesToDownload>, <versionFolderName>);
After that, use the NativesCommandPatcher to get a version of the launch command that will use the newly generated Natives folder instead of the default.
if(isPost1_19) patchedCommand = new NativesCommandPatcher().patcher(mcProcessBuilder.command(), profile.getVersion());
After that, just use the patched launch command in place of the normal one, then the game should launch. Hope this helps.