mindstorm38 / portablemc

A fast, reliable and cross-platform command-line Minecraft launcher and API for developers. Including fast and easy installation of common mod loaders such as Fabric, Forge, NeoForge and Quilt.
https://pypi.org/project/portablemc/
GNU General Public License v3.0
320 stars 19 forks source link

Trouble launching Windows Minecraft from WSL #188

Closed dalps closed 5 months ago

dalps commented 8 months ago

Hello there! This might be a silly task, but I'm trying to get PMC on WSL (running Ubuntu 22.04) to launch Minecraft (any version) from the %appdata%/.minecraft directory of my Windows 11 host, instead from the default directory for Linux ~/.minecraft.

My first attempt was to change the main directory of PMC:

portablemc -v --main-dir /mnt/c/Users/dalps/AppData/Roaming/.minecraft/ start

but I got the following error:

FileNotFoundError: [Errno 2] No such file or directory: '/mnt/c/Users/dalps/AppData/Roaming/.minecraft/jvm/java-runtime-gamma/bin/java'

I figured that PMC looks for the java binary as is named in the Linux installation of Minecraft, however on Windows this binary is named java.exe. Providing the correct binary to the --jvm option:

portablemc -v --main-dir /mnt/c/Users/dalps/AppData/Roaming/.minecraft/ start --jvm /mnt/c/Users/dalps/AppData/
Roaming/.minecraft/jvm/java-runtime-gamma/bin/java.exe

yields the following error:

<3>init: (1546) ERROR: UtilAcceptVsock:244: accept4 failed 110

I know this is a interoperability issue between Windows and WSL, but it should be possible to call a Windows application from within WSL. So, is PMC is at fault here, or is the problem on WSL (or my) side?

Again sorry if this sounds convoluted, I just want to avoid using PMC on PowerShell :P.

mindstorm38 commented 8 months ago

Wow, give me some time to digest this haha

mindstorm38 commented 5 months ago

I'm racking my mind on this one... First thing that I find weird in your example is that you give the path to java.exe, instead of javaw.exe (with w, for windowed). It's slightly different, so I don't expect this to work anyway, but this is more correct.

I don't think however that PortableMC is at fault here, or more precisely, it could not do better. I think that the launcher choose and download the linux-specific libraries (for LWJGL for example) and add them to class-path, but you're still using the windows JVM, so I would not be surprised if this is the problem. I'm trying to replicate your issue but I get another ones...

I also think that the classpath is built with wsl (unix) paths, but the host JVM cannot find them. In the end there is no classpath at all.

mindstorm38 commented 5 months ago

The best, and in my opinion only solution here is to only set the work-dir to the Windows .minecraft, but keep the main directory in your WSL. For now, I wont fix this as it's not an issue related to PortableMC. It would be possible for PortableMC to detect WSL and act like windows, but there is still the issue of paths, I don't know how I could invert the /mnt/c path to C:/, I don't think it's that trivial.

dalps commented 5 months ago

Thanks for reviewing this issue! I'm glad to know it was related to a misuse on my part. Using PMC from WSL launches the Ubuntu instance of Minecraft, which is really buggy for mouse input. As of now I'm happy with launching the Windows instance from PowerShell.

Thanks for the great tool and sorry for the headache!