[NOISSUE] Nitpicks

This commit is contained in:
Pierce 2020-07-07 23:36:31 -04:00
parent d1417e07c8
commit 9ee4f3dda2
4 changed files with 25 additions and 31 deletions

View file

@ -2,7 +2,7 @@
##### This project is complete for now. ##### 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) [![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) [![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.14.3-blue) ![version](https://img.shields.io/badge/stable_version-3.14.4-blue)
![badge](https://img.shields.io/badge/ncurses-not_supported-purple) ![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. MCLC (Minecraft Launcher Core) is a NodeJS solution for launching modded and vanilla Minecraft without having to download and format everything yourself.
@ -97,7 +97,7 @@ let opts = {
natives: "", // native directory path. natives: "", // native directory path.
assetRoot: "", assetRoot: "",
cwd: "", // working directory of the java process. cwd: "", // working directory of the java process.
detached: false, // whether or not the client is detached from the parent / launcher. detached: true, // whether or not the client is detached from the parent / launcher.
classes: [], // all class paths are required if you use this. classes: [], // all class paths are required if you use this.
minArgs: 11, minArgs: 11,
maxSockets: 2, // max sockets for downloadAsync. maxSockets: 2, // max sockets for downloadAsync.

View file

@ -11,7 +11,6 @@ class Handler {
constructor (client) { constructor (client) {
this.client = client this.client = client
this.options = client.options this.options = client.options
this.version = undefined
this.baseRequest = request.defaults({ this.baseRequest = request.defaults({
pool: { maxSockets: this.options.overrides.maxSockets || 2 }, pool: { maxSockets: this.options.overrides.maxSockets || 2 },
timeout: this.options.timeout || 10000 timeout: this.options.timeout || 10000
@ -165,7 +164,7 @@ class Handler {
if (!fs.existsSync(path.join(subAsset, hash)) || !await this.checkSum(hash, path.join(subAsset, hash))) { if (!fs.existsSync(path.join(subAsset, hash)) || !await this.checkSum(hash, path.join(subAsset, hash))) {
await this.downloadAsync(`${this.options.overrides.url.resource}/${subhash}/${hash}`, subAsset, hash, await this.downloadAsync(`${this.options.overrides.url.resource}/${subhash}/${hash}`, subAsset, hash,
true, 'assets') true, 'assets')
counter = counter + 1 counter++
this.client.emit('progress', { this.client.emit('progress', {
type: 'assets', type: 'assets',
task: counter, task: counter,
@ -176,7 +175,7 @@ class Handler {
counter = 0 counter = 0
// Copy assets to legacy if it's an older Minecraft version. // Copy assets to legacy if it's an older Minecraft version.
if (this.version.assets === 'legacy' || this.version.assets === 'pre-1.6') { if (this.isLegacy()) {
const assetDirectory = this.options.overrides.assetRoot || path.join(this.options.root, 'assets') const assetDirectory = this.options.overrides.assetRoot || path.join(this.options.root, 'assets')
this.client.emit('debug', `[MCLC]: Copying assets over to ${path.join(assetDirectory, 'legacy')}`) this.client.emit('debug', `[MCLC]: Copying assets over to ${path.join(assetDirectory, 'legacy')}`)
@ -201,7 +200,7 @@ class Handler {
if (!fs.existsSync(path.join(assetDirectory, 'legacy', asset))) { if (!fs.existsSync(path.join(assetDirectory, 'legacy', asset))) {
fs.copyFileSync(path.join(subAsset, hash), path.join(assetDirectory, 'legacy', asset)) fs.copyFileSync(path.join(subAsset, hash), path.join(assetDirectory, 'legacy', asset))
} }
counter = counter + 1 counter++
this.client.emit('progress', { this.client.emit('progress', {
type: 'assets-copy', type: 'assets-copy',
task: counter, task: counter,
@ -261,7 +260,6 @@ class Handler {
}) })
await Promise.all(stat.map(async (native) => { await Promise.all(stat.map(async (native) => {
// Edge case on some systems where native is undefined and throws an error, this should fix it.
if (!native) return if (!native) return
const name = native.path.split('/').pop() const name = native.path.split('/').pop()
await this.downloadAsync(native.url, nativeDirectory, name, true, 'natives') await this.downloadAsync(native.url, nativeDirectory, name, true, 'natives')
@ -277,7 +275,7 @@ class Handler {
console.warn(e) console.warn(e)
} }
shelljs.rm(path.join(nativeDirectory, name)) shelljs.rm(path.join(nativeDirectory, name))
counter = counter + 1 counter++
this.client.emit('progress', { this.client.emit('progress', {
type: 'natives', type: 'natives',
task: counter, task: counter,
@ -343,7 +341,7 @@ class Handler {
if (fs.existsSync(path.join(jarPath, name))) { if (fs.existsSync(path.join(jarPath, name))) {
paths.push(`${jarPath}${path.sep}${name}`) paths.push(`${jarPath}${path.sep}${name}`)
counter = counter + 1 counter++
this.client.emit('progress', { type: 'forge', task: counter, total: forge.libraries.length }) this.client.emit('progress', { type: 'forge', task: counter, total: forge.libraries.length })
return return
} }
@ -353,7 +351,7 @@ class Handler {
if (!download) await this.downloadAsync(`${this.options.overrides.url.fallbackMaven}${lib[0].replace(/\./g, '/')}/${lib[1]}/${lib[2]}/${name}`, jarPath, name, true, 'forge') if (!download) await this.downloadAsync(`${this.options.overrides.url.fallbackMaven}${lib[0].replace(/\./g, '/')}/${lib[1]}/${lib[2]}/${name}`, jarPath, name, true, 'forge')
paths.push(`${jarPath}${path.sep}${name}`) paths.push(`${jarPath}${path.sep}${name}`)
counter = counter + 1 counter++
this.client.emit('progress', { this.client.emit('progress', {
type: 'forge', type: 'forge',
task: counter, task: counter,
@ -421,7 +419,7 @@ class Handler {
} }
} }
counter = counter + 1 counter++
this.client.emit('progress', { this.client.emit('progress', {
type: eventName, type: eventName,
task: counter, task: counter,
@ -461,16 +459,13 @@ class Handler {
return tempArray.join('/') return tempArray.join('/')
} }
static cleanUp (array) { cleanUp (array) {
return new Promise(resolve => { const newArray = []
const newArray = [] for (const classPath in array) {
if (newArray.includes(array[classPath])) continue
for (const classPath in array) { newArray.push(array[classPath])
if (newArray.includes(array[classPath])) continue }
newArray.push(array[classPath]) return newArray
}
resolve(newArray)
})
} }
async getLaunchOptions (modification) { async getLaunchOptions (modification) {
@ -480,12 +475,11 @@ class Handler {
? type.minecraftArguments.split(' ') ? type.minecraftArguments.split(' ')
: type.arguments.game : type.arguments.game
const assetRoot = this.options.overrides.assetRoot || path.join(this.options.root, 'assets') const assetRoot = this.options.overrides.assetRoot || path.join(this.options.root, 'assets')
const assetPath = this.version.assets === 'legacy' || const assetPath = this.isLegacy()
this.version.assets === 'pre-1.6'
? path.join(assetRoot, 'legacy') ? path.join(assetRoot, 'legacy')
: path.join(assetRoot) : path.join(assetRoot)
const minArgs = this.options.overrides.minArgs || (this.version.assets === 'legacy' || this.version.assets === 'pre-1.6') ? 5 : 11 const minArgs = this.options.overrides.minArgs || this.isLegacy() ? 5 : 11
if (args.length < minArgs) args = args.concat(this.version.minecraftArguments ? this.version.minecraftArguments.split(' ') : this.version.arguments.game) if (args.length < minArgs) args = args.concat(this.version.minecraftArguments ? this.version.minecraftArguments.split(' ') : this.version.arguments.game)
this.options.authorization = await Promise.resolve(this.options.authorization) this.options.authorization = await Promise.resolve(this.options.authorization)
@ -544,6 +538,10 @@ class Handler {
return opts[this.getOS()] return opts[this.getOS()]
} }
isLegacy () {
return this.version.assets === 'legacy' || this.version.assets === 'pre-1.6'
}
getOS () { getOS () {
if (this.options.os) { if (this.options.os) {
return this.options.os return this.options.os

View file

@ -60,7 +60,6 @@ class MCLCore extends EventEmitter {
const directory = this.options.overrides.directory || path.join(this.options.root, 'versions', this.options.version.number) const directory = this.options.overrides.directory || path.join(this.options.root, 'versions', this.options.version.number)
this.options.directory = directory this.options.directory = directory
// Version JSON for the main launcher folder
const versionFile = await this.handler.getVersion() const versionFile = await this.handler.getVersion()
const mcPath = this.options.overrides.minecraftJar || (this.options.version.custom const mcPath = this.options.overrides.minecraftJar || (this.options.version.custom
? path.join(this.options.root, 'versions', this.options.version.custom, `${this.options.version.custom}.jar`) ? path.join(this.options.root, 'versions', this.options.version.custom, `${this.options.version.custom}.jar`)
@ -76,7 +75,6 @@ class MCLCore extends EventEmitter {
let custom = null let custom = null
if (this.options.forge) { if (this.options.forge) {
this.options.forge = path.resolve(this.options.forge) this.options.forge = path.resolve(this.options.forge)
this.emit('debug', '[MCLC]: Detected Forge in options, getting dependencies') this.emit('debug', '[MCLC]: Detected Forge in options, getting dependencies')
forge = await this.handler.getForgeDependenciesLegacy() forge = await this.handler.getForgeDependenciesLegacy()
if (forge === false) custom = await this.handler.getForgedWrapped() if (forge === false) custom = await this.handler.getForgedWrapped()
@ -88,7 +86,6 @@ class MCLCore extends EventEmitter {
const args = [] const args = []
// Jvm
let jvm = [ let jvm = [
'-XX:-UseAdaptiveSizePolicy', '-XX:-UseAdaptiveSizePolicy',
'-XX:-OmitStackTraceInFastThrow', '-XX:-OmitStackTraceInFastThrow',
@ -104,7 +101,7 @@ class MCLCore extends EventEmitter {
if (this.options.customArgs) jvm = jvm.concat(this.options.customArgs) if (this.options.customArgs) jvm = jvm.concat(this.options.customArgs)
const classes = this.options.overrides.classes || await Handler.cleanUp(await this.handler.getClasses(custom)) const classes = this.options.overrides.classes || this.handler.cleanUp(await this.handler.getClasses(custom))
const classPaths = ['-cp'] const classPaths = ['-cp']
const separator = this.handler.getOS() === 'windows' ? ';' : ':' const separator = this.handler.getOS() === 'windows' ? ';' : ':'
this.emit('debug', `[MCLC]: Using ${separator} to separate class paths`) this.emit('debug', `[MCLC]: Using ${separator} to separate class paths`)
@ -122,11 +119,10 @@ class MCLCore extends EventEmitter {
classPaths.push(file.mainClass) classPaths.push(file.mainClass)
} }
// Download version's assets
this.emit('debug', '[MCLC]: Attempting to download assets') this.emit('debug', '[MCLC]: Attempting to download assets')
await this.handler.getAssets() await this.handler.getAssets()
// Launch options. Thank you Lyrus for the reformat <3 // Forge -> Custom -> Vanilla
const modification = forge ? forge.forge : null || custom ? custom : null const modification = forge ? forge.forge : null || custom ? custom : null
const launchOptions = await this.handler.getLaunchOptions(modification) const launchOptions = await this.handler.getLaunchOptions(modification)

View file

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