Pass mainclass and gameargs to the main game via system properties

Signed-off-by: Xander <xander@isxander.dev>
This commit is contained in:
Xander 2025-04-26 21:41:14 +01:00 committed by GitHub
parent 60e279bf39
commit a702d06cd8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -97,6 +97,18 @@ public final class StandardLauncher extends AbstractLauncher {
gameArgs.add(worldName);
}
StringBuilder joinedGameArgs = new StringBuilder();
for (String gameArg : gameArgs) {
if (joinedGameArgs.length() > 0) {
joinedGameArgs.append(" ");
}
joinedGameArgs.append(gameArg);
}
// pass the real main class and game arguments in so mods can access them
System.setProperty("org.prismlauncher.launch.mainclass", mainClassName);
System.setProperty("org.prismlauncher.launch.gameargs", joinedGameArgs.toString());
// find and invoke the main method
MethodHandle method = ReflectionUtils.findMainMethod(mainClassName);
method.invokeExact(gameArgs.toArray(new String[0]));