From 9cf79157d2a707fa60ac43b4c05b8ec3c66d13ba Mon Sep 17 00:00:00 2001 From: Pierce Date: Sun, 26 May 2019 16:42:23 -0400 Subject: [PATCH] Fixed improper version json, added ability to set width and height --- README.md | 5 ++++- components/handler.js | 19 +++++++++---------- package.json | 2 +- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 4241115..8a29f47 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,10 @@ launcher.on('error', (e) => console.log(e)); | `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.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 | + ##### Note 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. diff --git a/components/handler.js b/components/handler.js index ac4f4c2..fec3970 100644 --- a/components/handler.js +++ b/components/handler.js @@ -70,8 +70,8 @@ class Handler { getVersion() { return new Promise(resolve => { - if(fs.existsSync(path.join(this.options.directory, `${this.options.version}.json`))) { - this.version = require(path.join(this.options.directory, `${this.options.version}.json`)); + if(fs.existsSync(path.join(this.options.directory, 'versions', this.options.version.number, `${this.options.version.number}.json`))) { + this.version = require(path.join(this.options.directory, 'versions', this.options.version.number, `${this.options.version.number}.json`)); resolve(this.version); return; } @@ -101,7 +101,7 @@ class Handler { return new Promise(async (resolve)=> { await this.downloadAsync(this.version.downloads.client.url, this.options.directory, `${this.options.version.number}.jar`); - fs.writeFileSync(path.join(this.options.directory, `${this.options.version.number}.json`), JSON.stringify(this.options.version, null, 4)); + fs.writeFileSync(path.join(this.options.directory, `${this.options.version.number}.json`), JSON.stringify(this.version, null, 4)); this.client.emit('debug', '[MCLC]: Downloaded version jar and wrote version json'); @@ -164,13 +164,9 @@ class Handler { getNatives() { return new Promise(async(resolve) => { - let nativeDirectory; - - if(fs.existsSync(path.join(this.options.root, 'natives', this.version.id))) { - nativeDirectory = path.join(this.options.root, 'natives', this.version.id); - } else { - nativeDirectory = path.join(this.options.root, "natives", this.version.id); + const nativeDirectory = path.join(this.options.root, 'natives', this.version.id); + if(!fs.existsSync(nativeDirectory) || !fs.readdirSync(nativeDirectory).length) { shelljs.mkdir('-p', nativeDirectory); await Promise.all(this.version.libraries.map(async (lib) => { @@ -322,18 +318,20 @@ class Handler { '${user_type}': 'mojang', '${version_name}': this.options.version.number, '${assets_index_name}': this.version.assetIndex.id, - '${game_directory}': path.join(this.options.root), + '${game_directory}': this.options.root, '${assets_root}': assetPath, '${game_assets}': assetPath, '${version_type}': this.options.version.type }; for (let index = 0; index < args.length; index++) { + if(typeof args[index] === 'object') args.splice(index, 2); if (Object.keys(fields).includes(args[index])) { args[index] = fields[args[index]]; } } + if(this.options.window) args.push('--width', this.options.window.width, '--height', this.options.window.height); if(this.options.server) args.push('--server', this.options.server.host, '--port', this.options.server.port || "25565"); if(this.options.proxy) args.push( '--proxyHost', @@ -346,6 +344,7 @@ class Handler { this.options.proxy.password ); + console.log(args) this.client.emit('debug', '[MCLC]: Set launch options'); resolve(args); }); diff --git a/package.json b/package.json index 7d11c9d..5293515 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "minecraft-launcher-core", - "version": "3.2.0", + "version": "3.3.0", "description": "Module that downloads Minecraft assets and runs Minecraft. Also Supports Forge", "main": "index.js", "dependencies": {