mirror of
https://github.com/artegoser/pimi-launcher-core.git
synced 2024-11-22 12:16:21 +03:00
181 lines
11 KiB
Markdown
181 lines
11 KiB
Markdown
![logo](https://pierce.is-serious.business/44U1xXh.png)
|
|
##### This project is near complete.
|
|
[![Build Status](https://travis-ci.com/Pierce01/MinecraftLauncher-core.svg?branch=master)](https://travis-ci.com/Pierce01/MinecraftLauncher-core)
|
|
|
|
MCLC is a NodeJS solution for launching modded and vanilla Minecraft without having to download and format everything yourself.
|
|
Basically a core for your Electron or script based launchers.
|
|
|
|
### 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!
|
|
https://discord.gg/8uYVbXP
|
|
|
|
### Installing
|
|
|
|
`npm i minecraft-launcher-core`
|
|
|
|
### Standard Example
|
|
```javascript
|
|
const { Client, Authenticator } = require('minecraft-launcher-core');
|
|
const launcher = new Client();
|
|
|
|
let opts = {
|
|
clientPackage: null,
|
|
// 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!
|
|
authorization: Authenticator.getAuth("username", "password"),
|
|
root: "./minecraft",
|
|
os: "windows",
|
|
version: {
|
|
number: "1.14",
|
|
type: "release"
|
|
},
|
|
memory: {
|
|
max: "6000",
|
|
min: "4000"
|
|
}
|
|
}
|
|
|
|
launcher.launch(opts);
|
|
|
|
launcher.on('debug', (e) => console.log(e));
|
|
launcher.on('data', (e) => console.log(e));
|
|
```
|
|
### Documentation
|
|
|
|
#### Client Functions
|
|
|
|
| Function | Type | Description |
|
|
|----------|---------|-----------------------------------------------------------------------------------------|
|
|
| `launch` | Promise | Launches the client with the specified `options` as a parameter. Returns child the process |
|
|
|
|
##### launch
|
|
|
|
| Parameter | Type | Description | Required |
|
|
|--------------------------|----------|-------------------------------------------------------------------------------------------|----------|
|
|
| `options.clientPackage` | String | Path or URL to the client package zip file. | False |
|
|
| `options.installer` | String | Path to installer being executed. | False |
|
|
| `options.root` | String | Path where you want the launcher to work in. like `C:/Users/user/AppData/Roaming/.mc`, | True |
|
|
| `options.os` | String | windows, osx or linux. MCLC with auto determine the OS if this field isn't provided. | False |
|
|
| `options.customArgs` | Array | Array of custom java arguments you want to add. | False |
|
|
| `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 |
|
|
| `options.version.custom` | String | The name of the folder, jar file, and version json in the version folder. | False |
|
|
| `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 |
|
|
| `options.forge` | String | Path to Universal Forge Jar. (Only for versions below 1.13+ | False |
|
|
| `options.javaPath` | String | Path to the JRE executable file, will default to `java` if not entered. | False |
|
|
| `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 |
|
|
| `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 |
|
|
| `options.overrides` | Object | Json object redefining paths for better customization. Example below. | False |
|
|
| `options.overrides.minArgs`| Integer| The amount of launch arguments specified in the version file before it adds the default again| False |
|
|
```js
|
|
let opts = {
|
|
otherOps...,
|
|
overrides: {
|
|
minecraftJar: "",
|
|
versionJson: "",
|
|
directory: "", // where the Minecraft jar and version json are located.
|
|
natives: "", // all native paths are required if you use this.
|
|
assetRoot: "",
|
|
cwd: "", // working directory of the java process
|
|
classes: [], // all class paths are required if you use this.
|
|
minArgs: 11,
|
|
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.
|
|
defaultRepoForge: "https://libraries.minecraft.net/" // for Forge only, you need to redefine the library url
|
|
// in the version json.
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Notes
|
|
##### Custom
|
|
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. Still need to provide the version jar.
|
|
##### Installer
|
|
You'll need to provide the folder created in the versions if you're running the new forge like so
|
|
```json
|
|
{
|
|
"version": {
|
|
"number": "1.14.2",
|
|
"type": "release",
|
|
"custom": "1.14.2-forge-26.0.63"
|
|
},
|
|
"installer": "forge-1.14.2-26.0.63-installer.jar"
|
|
}
|
|
```
|
|
#### Authenticator Functions
|
|
|
|
##### getAuth
|
|
|
|
| Parameter | Type | Description | Required |
|
|
|-----------|--------|--------------------------------------------------------------|----------|
|
|
| `username`| String | Email or username | True |
|
|
| `password`| String | Password for the Mojang account being used if online mode. | False |
|
|
|
|
##### validate
|
|
|
|
| Parameter | Type | Description | Required |
|
|
|--------------|--------|-------------------------------------------------------------------|----------|
|
|
| `access_token` | String | Token being checked if it can be used to login with (online mode). | True |
|
|
| `client_token` | String | Client token being checked to see if there was a change of client (online mode). | True |
|
|
|
|
##### 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 |
|
|
| `selected_profile` | Object | Json Object that was returned from Mojang's auth api. | True |
|
|
|
|
##### 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 |
|
|
|
|
#### Events
|
|
|
|
| Event Name | Type | Description |
|
|
|-------------------|---------|---------------------------------------------------------------------------------------|
|
|
| `arguments` | Object | Emitted when launch arguments are set for the Minecraft Jar. |
|
|
| `data` | String | Emitted when information is returned from the Minecraft Process |
|
|
| `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 |
|
|
| `debug` | String | Emitted when functions occur, made to help debug if errors occur |
|
|
| `progress` | Object | Emitted when files are being downloaded in order. (Assets, Forge Deps, Natives, Classes)|
|
|
|
|
|
|
#### What should it look like running from console?
|
|
Showing the emitted information from debug and data, also using `getPid` after the process has been created.
|
|
![gif](https://pierce.is-serious.business/3N3PMC4.gif)
|
|
|
|
## 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.
|