parse the buffers instead of leaving them. Print MCLC version. allow events to register

This commit is contained in:
Pierce 2019-08-20 14:28:56 -04:00
parent 7ef41de7cc
commit 77532e2166
3 changed files with 12 additions and 10 deletions

View file

@ -16,6 +16,7 @@ https://discord.gg/8uYVbXP
### Standard Example ### Standard Example
```javascript ```javascript
const { Client, Authenticator } = require('minecraft-launcher-core'); const { Client, Authenticator } = require('minecraft-launcher-core');
const launcher = new Client();
let opts = { let opts = {
clientPackage: null, clientPackage: null,
@ -32,12 +33,10 @@ let opts = {
} }
} }
const launcher = new Client();
launcher.launch(opts); launcher.launch(opts);
launcher.on('debug', (e) => console.log(e)); launcher.on('debug', (e) => console.log(e));
launcher.on('data', (e) => console.log(e.toString('utf-8'))); launcher.on('data', (e) => console.log(e));
launcher.on('error', (e) => console.log(e.toString('utf-8')));
``` ```
### Documentation ### Documentation
@ -159,7 +158,7 @@ You'll need to provide the folder created in the versions if you're running the
| Event Name | Type | Description | | Event Name | Type | Description |
|-------------------|---------|---------------------------------------------------------------------------------------| |-------------------|---------|---------------------------------------------------------------------------------------|
| `arguments` | Object | Emitted when launch arguments are set for the Minecraft Jar. | | `arguments` | Object | Emitted when launch arguments are set for the Minecraft Jar. |
| `data` | Buffer | Emitted when information is returned from the Minecraft Process | | `data` | String | Emitted when information is returned from the Minecraft Process |
| `close` | Integer | Code number that is returned by the Minecraft Process | | `close` | Integer | Code number that is returned by the Minecraft Process |
| `package-extract` | null | Emitted when `clientPackage` finishes being extracted | | `package-extract` | null | Emitted when `clientPackage` finishes being extracted |
| `download` | String | Emitted when a file successfully downloads | | `download` | String | Emitted when a file successfully downloads |

View file

@ -29,7 +29,10 @@ class MCLCore extends EventEmitter {
} }
}; };
this.handler = new handler(this); this.handler = new handler(this);
const override = this.options.overrides; // Lets the events register. our magic switch!
await void(0);
this.emit('debug', `[MCLC]: MCLC version ${require(path.join(__dirname,'..', 'package.json')).version}`);
if(!fs.existsSync(this.options.root)) { if(!fs.existsSync(this.options.root)) {
this.emit('debug', '[MCLC]: Attempting to create root folder'); this.emit('debug', '[MCLC]: Attempting to create root folder');
@ -49,12 +52,12 @@ class MCLCore extends EventEmitter {
await this.handler.runInstaller(this.options.installer) await this.handler.runInstaller(this.options.installer)
} }
const directory = override.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 // Version JSON for the main launcher folder
const versionFile = await this.handler.getVersion(); const versionFile = await this.handler.getVersion();
const mcPath = override.minecraftJar || (this.options.version.custom ? path.join(this.options.root, 'versions', this.options.version.custom , `${this.options.version.custom}.jar`): 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(directory, `${this.options.version.number}.jar`)); path.join(directory, `${this.options.version.number}.jar`));
const nativePath = await this.handler.getNatives(); const nativePath = await this.handler.getNatives();
@ -121,8 +124,8 @@ class MCLCore extends EventEmitter {
const minecraft = child.spawn(this.options.javaPath ? this.options.javaPath : 'java', launchArguments, const minecraft = child.spawn(this.options.javaPath ? this.options.javaPath : 'java', launchArguments,
{cwd: this.options.overrides.cwd || this.options.root}); {cwd: this.options.overrides.cwd || this.options.root});
minecraft.stdout.on('data', (data) => this.emit('data', data)); minecraft.stdout.on('data', (data) => this.emit('data', data.toString('utf-8')));
minecraft.stderr.on('data', (data) => this.emit('data', data)); minecraft.stderr.on('data', (data) => this.emit('data', data.toString('utf-8')));
minecraft.on('close', (code) => this.emit('close', code)); minecraft.on('close', (code) => this.emit('close', code));
return minecraft; return minecraft;

View file

@ -1,6 +1,6 @@
{ {
"name": "minecraft-launcher-core", "name": "minecraft-launcher-core",
"version": "3.8.0", "version": "3.8.1",
"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": {