A library to make Minecraft launcher development with JVM languages easier by providing a library to do the hard work: actually authenticating and launching Minecraft.
Launching and downloading is done asynchronously, taking just 2s fully cached.
The library can launch Minecraft without an internet connection just from the data in .minecraft
.
Although this library is written in Groovy, Java support IS a priority for me, some Java-based launchers are already using it.
If you require help and support see me in the #RX14 channel on EsperNet. Do not hesitate to report bugs and feature requests in the Github Issues. Even if you decide not to use this library, please drop a note as to how I can improve.
The library is available on the jCenter Maven repository.
Using Gradle:
repositories {
jcenter()
}
dependencies {
compile "uk.co.rx14.jmclaunchlib:jMCLaunchLib:$version"
}
First step in launching Minecraft is to get a LaunchTask
.
This Task
object will spawn several other Task objects which run in parallel (10 thread threadpool) to launch Minecraft.
LaunchTask task = new LaunchTaskBuilder()
.setCachesDir("test/caches") //Directory to cache stuff in, copies caches from .minecraft (and verifies)
.setMinecraftVersion("1.7.10") //Set vanilla version
//OR
.setForgeVersion("1.7.10", "1.7.10-10.13.3.1408-1.7.10") //Minecraftforge version
.setInstanceDir("test/instance") //Minecraft directory
.setUsername("RX14") //Username for offline
.setOffline() //Offline mode
//OR
.setUsername("example@email") //Mojang username
.setPasswordSupplier(new YourPasswordSupplier()) //Callback to request password. Details below.
.build(); //Build LaunchTask
This should be mostly self-explanitory apart from the requirement for a PasswordSupplier
.
PasswordSupplier
is an interface with one method, String getPassword(String username)
.
This is required because jMCLaunchLib stores authentication tokens but does not store passwords,
using this interface as a callback to request the password for a specific username enables the launcher to only ask the user for a password when absolutely needed.
This will typically be called when the token has expired or when logging in for the first time.
Now you have your LaunchTask
, what can you do with it?
Now is the time to send the launch task back to your GUI thread, so that your progress dialog can call task.getCompletedPercentage()
.
After that, call task.getSpec()
which calculates the LaunchSpec
object which contains the java arguments required to launch Minecraft.
//Open a dialog box to report the percentage with
task.getCompletedPercentage()
LaunchSpec spec = task.getSpec()
You should be able to reuse the LaunchTaskBuilder
, it is immutable and each stage copies the object.
You should keep a partially constructed LaunchTaskBuilder
and reuse it many times.
You cannot reuse Task objects.
LaunchSpec is a class which contains the information you need to launch Minecraft: classpath, program arguments for minecraft, JVM arguments and the main class.
You can use getLaunchArgs().add(...)
and getJvmArgs().add(...)
to customise the launch parameters.
Use LaunchSpec.getJavaCommandline()
to get the arguments to pass to the Java executable as a String,
or use LaunchSpec.run(java.nio.file.Path javaExecutable)
to let jMCLaunchLib run Minecraft using the path to the java executable.
The run()
method returns a standard Java Process object so you can control Minecraft and route it's standard output streams.
Please note that the instance directory must exist before calling run, or it will fail with a slightly cryptic error 267.
(If you pester me enough I might write something cool to redirect stdout/err from a Process to useful places.)
Below is an example of using the LaunchSpec
class to run minecraft, using the current java executable.
If you are creating a launcher, I strongly suggest you make the java executable path configurable,
with a sensible default.
spec.run(Paths.get(System.getProperty("java.home"), "bin", OS.getCURRENT() == OS.WINDOWS ? "java.exe" : "java"));
- You can make your own custom
Version
interface, for example for liteloader + forge, and use it in theLaunchtaskBuilder
. - Make an issue if you want to do something this library does not allow.