quickPlay support, opts.server removed

to use the old server launch arg format, use the legacy option.
This commit is contained in:
Pierce 2023-06-16 17:35:25 -07:00
parent 08d49deb49
commit 6eefbcdf6f
4 changed files with 37 additions and 15 deletions

View file

@ -2,7 +2,7 @@
##### This project is complete for now.
[![Build Status](https://travis-ci.com/Pierce01/MinecraftLauncher-core.svg?branch=master)](https://travis-ci.com/Pierce01/MinecraftLauncher-core)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
![version](https://img.shields.io/badge/stable_version-3.16.19-blue)
![version](https://img.shields.io/badge/stable_version-3.17.0-blue)
![badge](https://img.shields.io/badge/ncurses-not_supported-purple)
MCLC (Minecraft Launcher Core) is a NodeJS solution for launching modded and vanilla Minecraft without having to download and format everything yourself.
@ -62,8 +62,8 @@ launcher.on('data', (e) => console.log(e));
| `options.clientPackage` | String | Path or URL to a zip file, which will be extracted to the root directory. (Not recommended for production use)| False |
| `options.removePackage` | Boolean | Option to remove the client package zip file after its finished extracting. | 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.cache` | String | Path where launcher files will be cached in. like `C:/Users/user/AppData/Roaming/.mc/cache`, | False |
| `options.root` | String | Path where you want the launcher to work in. `C:/Users/user/AppData/Roaming/.mc` | True |
| `options.cache` | String | Path where launcher files will be cached in. `C:/Users/user/AppData/Roaming/.mc/cache` | False |
| `options.os` | String | windows, osx or linux. MCLC will auto determine the OS if this field isn't provided. | False |
| `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 |
@ -75,8 +75,9 @@ launcher.on('data', (e) => console.log(e));
| `options.memory.min` | String | Min amount of memory being used by Minecraft. | True |
| `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 |
| `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.quickPlay.type` | String | The type of the quickPlay session. `singleplayer` | `multiplayer` | `realms` | `legacy` | False |
| `options.quickPlay.identifier` | String | The folder name, server address, or realm ID, relating to the specified type. `legacy` follows `multiplayer` format. | False |
| `options.quickPlay.path` | String | The specified path for logging (relative to the run directory) | 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 |
@ -84,7 +85,7 @@ launcher.on('data', (e) => console.log(e));
| `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.window.fullscreen` | Boolean| Fullscreen the Minecraft Client. | False |
| `options.window.fullscreen`| Boolean| Fullscreen the Minecraft Client. | False |
| `options.overrides` | Object | Json object redefining paths for better customization. Example below. | False |
#### IF YOU'RE NEW TO MCLC, LET IT HANDLE EVERYTHING! DO NOT USE OVERRIDES!
```js

View file

@ -573,6 +573,26 @@ class Handler {
return newArray
}
formatQuickPlay () {
const types = {
singleplayer: '--quickPlaySingleplayer',
multiplayer: '--quickPlayMultiplayer',
realms: '--quickPlayRealms',
legacy: null
}
const { type, identifier, path } = this.options.quickPlay
const keys = Object.keys(types)
if (!keys.includes(type)) {
this.client.emit('debug', `[MCLC]: quickPlay type is not valid. Valid types are: ${keys.join(', ')}`)
return null
}
const returnArgs = type === 'legacy'
? ['--server', identifier.split(':')[0], '--port', identifier.split(':')[1] || '25565']
: [types[type], identifier]
if (path) returnArgs.push('--quickPlayPath', path)
return returnArgs
}
async getLaunchOptions (modification) {
const type = modification || this.version
@ -648,10 +668,6 @@ class Handler {
}
}
}
args = args.filter((value) => {
return typeof value === 'string' || typeof value === 'number'
})
if (this.options.window) {
// eslint-disable-next-line no-unused-expressions
this.options.window.fullscreen
@ -662,7 +678,8 @@ class Handler {
}
}
}
if (this.options.server) args.push('--server', this.options.server.host, '--port', this.options.server.port || '25565')
if (this.options.server) this.client.emit('debug', '[MCLC]: server and port are deprecated launch flags. Use the quickPlay field.')
if (this.options.quickPlay) args = args.concat(this.formatQuickPlay())
if (this.options.proxy) {
args.push(
'--proxyHost',
@ -675,7 +692,7 @@ class Handler {
this.options.proxy.password
)
}
args = args.filter(value => typeof value === 'string' || typeof value === 'number')
this.client.emit('debug', '[MCLC]: Set launch options')
return args
}

8
index.d.ts vendored
View file

@ -11,6 +11,7 @@ declare module "minecraft-launcher-core" {
directory?: string;
natives?: string;
assetRoot?: string;
assetIndex?: string;
libraryRoot?: string;
cwd?: string;
detached?: boolean;
@ -150,6 +151,11 @@ declare module "minecraft-launcher-core" {
height?: number;
fullscreen?: boolean;
};
quickPlay?: {
type: 'singleplayer' | 'multiplayer' | 'realms' | 'legacy';
identifier: string;
path?: string;
};
overrides?: IOverrides;
authorization: Promise<IUser>;
/**
@ -158,8 +164,6 @@ declare module "minecraft-launcher-core" {
cache?: string;
}
interface IUser {
access_token: string;
client_token: string;

View file

@ -1,6 +1,6 @@
{
"name": "minecraft-launcher-core",
"version": "3.16.19",
"version": "3.17.0",
"description": "Lightweight module that downloads and runs Minecraft using javascript / NodeJS",
"main": "index.js",
"dependencies": {