2020-03-18 03:15:32 +03:00
![logo ](https://owo.whats-th.is/8mT5kxc.png )
2019-10-10 20:23:03 +03:00
##### This project is complete for now.
2019-05-23 03:24:53 +03:00
[![Build Status ](https://travis-ci.com/Pierce01/MinecraftLauncher-core.svg?branch=master )](https://travis-ci.com/Pierce01/MinecraftLauncher-core)
2019-08-29 21:17:01 +03:00
[![License: MIT ](https://img.shields.io/badge/License-MIT-yellow.svg )](https://opensource.org/licenses/MIT)
2020-07-23 19:03:31 +03:00
![version ](https://img.shields.io/badge/stable_version-3.14.6-blue )
2019-08-29 21:17:01 +03:00
![badge ](https://img.shields.io/badge/ncurses-not_supported-purple )
2018-10-30 01:13:58 +03:00
2019-12-13 05:14:25 +03:00
MCLC (Minecraft Launcher Core) is a NodeJS solution for launching modded and vanilla Minecraft without having to download and format everything yourself.
2019-02-11 05:21:14 +03:00
Basically a core for your Electron or script based launchers.
2018-10-30 01:13:58 +03:00
2019-04-19 00:56:36 +03:00
### Getting support
Since people seem to use this, I've created a Discord server for anyone who needs to get in contact with me or get help!
2019-08-29 21:17:01 +03:00
< p >
< a href = "https://discord.gg/8uYVbXP" >
< img src = "https://img.shields.io/discord/568550848871923723?logo=discord"
alt="chat on Discord">< / a >
< p >
2019-04-19 00:56:36 +03:00
2018-12-31 02:35:47 +03:00
### Installing
2018-12-10 02:17:20 +03:00
`npm i minecraft-launcher-core`
2019-03-11 03:18:49 +03:00
### Standard Example
```javascript
2019-05-23 01:28:48 +03:00
const { Client, Authenticator } = require('minecraft-launcher-core');
2019-08-20 21:28:56 +03:00
const launcher = new Client();
2019-05-23 01:28:48 +03:00
let opts = {
clientPackage: null,
2019-12-13 05:14:25 +03:00
// For production launchers, I recommend not passing
// the getAuth function through the authorization field and instead
// handling authentication outside before you initialize
// MCLC so you can handle auth based errors and validation!
2019-06-06 21:49:18 +03:00
authorization: Authenticator.getAuth("username", "password"),
2019-05-23 01:28:48 +03:00
root: "./minecraft",
version: {
number: "1.14",
type: "release"
2019-05-23 01:32:45 +03:00
},
2019-05-23 01:28:48 +03:00
memory: {
max: "6000",
min: "4000"
}
}
2019-06-06 21:49:18 +03:00
launcher.launch(opts);
2019-05-23 01:28:48 +03:00
launcher.on('debug', (e) => console.log(e));
2019-08-20 21:28:56 +03:00
launcher.on('data', (e) => console.log(e));
2019-03-11 03:18:49 +03:00
```
2019-06-06 21:49:18 +03:00
### Documentation
2018-10-30 01:13:58 +03:00
2019-06-06 21:49:18 +03:00
#### Client Functions
| Function | Type | Description |
|----------|---------|-----------------------------------------------------------------------------------------|
2019-06-08 21:21:15 +03:00
| `launch` | Promise | Launches the client with the specified `options` as a parameter. Returns child the process |
2019-06-06 21:49:18 +03:00
##### launch
2019-05-23 01:28:48 +03:00
| Parameter | Type | Description | Required |
|--------------------------|----------|-------------------------------------------------------------------------------------------|----------|
2020-04-04 20:25:14 +03:00
| `options.clientPackage` | String | Path or URL to the client package zip file. Do not rehost Minecraft, it's against ToS. | False |
2019-10-10 20:21:23 +03:00
| `options.removePackage` | Boolean | Option to remove the client package zip file after its finished extracting. | False |
2019-07-19 13:38:29 +03:00
| `options.installer` | String | Path to installer being executed. | False |
2019-05-23 01:28:48 +03:00
| `options.root` | String | Path where you want the launcher to work in. like `C:/Users/user/AppData/Roaming/.mc` , | True |
2020-08-19 21:27:36 +03:00
| `options.gameDirectofy` | String | Path where you want the game to work in. If you don't specify it, it will be in the same place as root.| False |
2019-10-10 20:21:23 +03:00
| `options.os` | String | windows, osx or linux. MCLC will auto determine the OS if this field isn't provided. | False |
2020-04-07 16:36:06 +03:00
| `options.customLaunchArgs` | Array | Array of custom Minecraft arguments you want to add. | False |
| `options.customArgs` | Array | Array of custom Java arguments you want to add. | False |
2019-05-23 01:28:48 +03:00
| `options.version.number` | String | Minecraft version that is going to be launched. | True |
| `options.version.type` | String | Any string. The actual Minecraft launcher uses `release` and `snapshot` . | True |
2019-06-23 05:55:43 +03:00
| `options.version.custom` | String | The name of the folder, jar file, and version json in the version folder. | False |
2019-07-19 13:38:29 +03:00
| `options.memory.max` | String | Max amount of memory being used by Minecraft. | True |
| `options.memory.min` | String | Min amount of memory being used by Minecraft. | True |
2020-05-29 05:39:13 +03:00
| `options.forge` | String | Path to Forge Jar. (Versions below 1.13 should be the "universal" jar while versions above 1.13+ should be the "installer" jar)| False |
2019-06-06 21:49:18 +03:00
| `options.javaPath` | String | Path to the JRE executable file, will default to `java` if not entered. | False |
2019-05-23 01:28:48 +03:00
| `options.server.host` | String | Host url to the server, don't include the port. | False |
| `options.server.port` | String | Port of the host url, will default to `25565` if not entered. | False |
| `options.proxy.host` | String | Host url to the proxy, don't include the port. | False |
| `options.proxy.port` | String | Port of the host proxy, will default to `8080` if not entered. | False |
| `options.proxy.username` | String | Username for the proxy. | False |
| `options.proxy.password` | String | Password for the proxy. | False |
2019-05-26 23:42:23 +03:00
| `options.timeout` | Integer | Timeout on download requests. | False |
| `options.window.width` | String | Width of the Minecraft Client | False |
| `options.window.height` | String | Height of the Minecraft Client. | False |
2019-11-04 21:37:59 +03:00
| `options.window.fullscreen` | Boolean| Fullscreen the Minecraft Client. | False |
2019-07-23 02:29:36 +03:00
| `options.overrides` | Object | Json object redefining paths for better customization. Example below. | False |
2019-08-05 17:30:06 +03:00
| `options.overrides.minArgs` | Integer| The amount of launch arguments specified in the version file before it adds the default again| False |
2020-04-04 20:25:14 +03:00
#### IF YOU'RE NEW TO MCLC, LET IT HANDLE EVERYTHING! DO NOT USE OVERRIDES!
2019-07-23 02:29:36 +03:00
```js
let opts = {
otherOps...,
overrides: {
minecraftJar: "",
versionJson: "",
2019-08-05 19:54:57 +03:00
directory: "", // where the Minecraft jar and version json are located.
2019-12-13 05:14:25 +03:00
natives: "", // native directory path.
2019-08-05 17:30:06 +03:00
assetRoot: "",
2020-07-23 00:19:48 +03:00
libraryRoot: "",
2020-06-20 05:21:00 +03:00
cwd: "", // working directory of the java process.
2020-07-08 06:36:31 +03:00
detached: true, // whether or not the client is detached from the parent / launcher.
2019-08-05 17:30:06 +03:00
classes: [], // all class paths are required if you use this.
minArgs: 11,
2019-08-13 04:06:54 +03:00
maxSockets: 2, // max sockets for downloadAsync.
// The following is for launcher developers located in countries that have the Minecraft and Forge resource servers
// blocked for what ever reason. They obviously need to mirror the formatting of the original JSONs / file structures.
url: {
meta: "https://launchermeta.mojang.com", // List of versions.
resource: "https://resources.download.minecraft.net", // Minecraft resources.
mavenForge: "http://files.minecraftforge.net/maven/", // Forge resources.
2019-10-29 01:03:32 +03:00
defaultRepoForge: "https://libraries.minecraft.net/", // for Forge only, you need to redefine the library url
2019-08-13 04:06:54 +03:00
// in the version json.
2019-10-29 01:03:32 +03:00
fallbackMaven: "https://search.maven.org/remotecontent?filepath="
2019-08-13 04:06:54 +03:00
}
2019-07-23 02:29:36 +03:00
}
}
```
2019-05-26 23:42:23 +03:00
2019-07-19 13:38:29 +03:00
#### Notes
##### Custom
2020-01-05 02:21:12 +03:00
If you are loading up a client outside of vanilla Minecraft or Forge (Optifine and for an example), you'll need to download the needed files yourself if you don't provide downloads url downloads like Forge and Fabric. If no version jar is specified, MCLC will default back to the normal MC jar so mods like Fabric work.
2019-07-19 13:38:29 +03:00
##### Installer
2020-05-29 05:39:13 +03:00
This runs an executable with specified launch arguments. Was used to support Forge 1.13 before ForgeWrapper.
2019-05-23 01:28:48 +03:00
#### Authenticator Functions
2018-12-31 02:35:47 +03:00
##### getAuth
| Parameter | Type | Description | Required |
|-----------|--------|--------------------------------------------------------------|----------|
2019-05-24 02:40:34 +03:00
| `username` | String | Email or username | True |
| `password` | String | Password for the Mojang account being used if online mode. | False |
2018-12-31 02:35:47 +03:00
##### validate
| Parameter | Type | Description | Required |
|--------------|--------|-------------------------------------------------------------------|----------|
| `access_token` | String | Token being checked if it can be used to login with (online mode). | True |
2019-08-12 19:34:28 +03:00
| `client_token` | String | Client token being checked to see if there was a change of client (online mode). | True |
2018-12-31 02:35:47 +03:00
##### refreshAuth
| Parameter | Type | Description | Required |
|--------------------|--------|-------------------------------------------------------------------------------------|----------|
| `access_token` | String | Token being checked if it can be used to login with (online mode). | True |
| `client_token` | String | Token being checked if it's the same client that the access_token was created from. | True |
2019-07-19 13:38:29 +03:00
| `selected_profile` | Object | Json Object that was returned from Mojang's auth api. | True |
2018-12-31 02:35:47 +03:00
2019-05-23 01:28:48 +03:00
##### invalidate
| Parameter | Type | Description | Required |
|--------------|--------|-------------------------------------------------------------------|----------|
| `access_token` | String | Token being checked if it can be used to login with (online mode). | True |
| `client_token` | String | Token being checked if it's the same client that the access_token was created from. | True |
##### signOut
| Parameter | Type | Description | Required |
|--------------|--------|--------------------------------------|----------|
| `username` | String | Username used to login with | True |
| `password` | String | Password used to login with | True |
2020-04-04 20:25:14 +03:00
##### changeApiUrl
| Parameter | Type | Description | Required |
|-----------|--------|--------------------------------------------------------------|----------|
| `url` | String | New URL that MCLC will make calls to authenticate the login. | True |
2019-02-08 22:02:42 +03:00
#### Events
2019-02-11 05:21:14 +03:00
| Event Name | Type | Description |
|-------------------|---------|---------------------------------------------------------------------------------------|
2019-04-26 20:03:39 +03:00
| `arguments` | Object | Emitted when launch arguments are set for the Minecraft Jar. |
2019-08-20 21:28:56 +03:00
| `data` | String | Emitted when information is returned from the Minecraft Process |
2019-02-11 05:21:14 +03:00
| `close` | Integer | Code number that is returned by the Minecraft Process |
| `package-extract` | null | Emitted when `clientPackage` finishes being extracted |
| `download` | String | Emitted when a file successfully downloads |
| `download-status` | Object | Emitted when data is received while downloading |
2019-04-29 00:52:37 +03:00
| `debug` | String | Emitted when functions occur, made to help debug if errors occur |
2019-08-28 17:21:48 +03:00
| `progress` | Object | Emitted when files are being downloaded in order. (Assets, Forge, Natives, Classes) |
2019-02-08 22:02:42 +03:00
2018-12-01 22:30:58 +03:00
2018-10-30 01:40:52 +03:00
#### What should it look like running from console?
2019-11-04 21:37:59 +03:00
The `pid` is printed in console after the process is launched.
2020-03-24 21:52:30 +03:00
![gif ](https://owo.whats-th.is/3N3PMC4.gif )
2019-08-12 19:34:28 +03:00
## Contributors
These are the people that helped out that aren't listed [here ](https://github.com/Pierce01/MinecraftLauncher-core/graphs/contributors )!
* [Pyker ](https://github.com/Pyker ) - Forge dependency parsing.
* [Khionu ](https://github.com/khionu ) - Research on how Minecraft's`natives` are handled.
* [Coding-Kiwi ](https://github.com/Coding-Kiwi ) - Pointed out I didn't pass `clientToken` in initial authentication function.
* maxbsoft - Pointed out that a certain JVM option causes OSX Minecraft to bug out.
2020-04-29 17:51:17 +03:00
* [Noé ](https://github.com/NoXeDev ) - Pointed out launch args weren't being passed for Forge 1.13+.