Launcher Core Module
Provide the core function to parse Minecraft version and launch.
Usage
Parse Version JSON
Parse minecraft version as a resolved version, which is used for launching process. You can also read version info from it if you want.
import { Version } from "@xmcl/core";
const minecraftLocation: string;
const minecraftVersionId: string;
const resolvedVersion: ResolvedVersion = await Version.parse(minecraftLocation, minecraftVersionId);
Diagnose
Get the report of the version. It can check if version missing assets/libraries.
import { MinecraftLocation, diagnose, ResolvedVersion } from "@xmcl/core";
const minecraft: MinecraftLocation;
const version: string; // version string like 1.13
const resolvedVersion: ResolvedVersion = await Version.parse(minecraft, version);
const report: MinecraftIssueReport = await diagnose(resolvedVersion.id, resolvedVersion.minecraftDirectory);
const issues: MinecraftIssues[] = report.issues;
for (let issue of issues) {
switch (issue.role) {
case "minecraftJar": // your jar has problem
case "versionJson": // your json has problem
case "library": // your lib might be missing or corrupted
case "assets": // some assets are missing or corrupted
// and so on
}
}
Launch Game
Launch minecraft from a version:
import { launch } from "@xmcl/core"
const version: string; // full version id, like 1.13, or your forge version like, 1.13-forge-<someForgeVersion>
const javaPath: string; // java executable path
const gamePath: string; // .minecraft path
const proc: Promise<ChildProcess> = launch({ gamePath, javaPath, version });
Detach from the parent process. So your launcher's exit/crash won't affact the Minecraft running.
const proc: Promise<ChildProcess> = Launcher.launch({ gamePath, javaPath, version, extraExecOption: { detached: true } });
🧾 Classes
🤝 Interfaces
🗃️ Namespaces
🏭 Functions
createMinecraftProcessWatcher
createMinecraftProcessWatcher(process: ChildProcess, emitter: EventEmitter= ...): MinecraftProcessWatcher
Create a process watcher for a minecraft process.
It will watch the stdout and the error event of the process to detect error and minecraft state.
Parameters
- process:
ChildProcess
The Minecraft process - emitter:
EventEmitter
The event emitter which will emit usefule event
Return Type
MinecraftProcessWatcher
Defined in: packages/core/launch.ts:516
diagnose
diagnose(version: string, minecraftLocation: MinecraftLocation, options: DiagnoseOptions): Promise<MinecraftIssueReport>
Diagnose the version. It will check the version json/jar, libraries and assets.
Parameters
- version:
string
The version id string - minecraftLocation:
MinecraftLocation
- options:
DiagnoseOptions
Return Type
Promise<MinecraftIssueReport>
Defined in: packages/core/diagnose.ts:166
diagnoseAssetIndex
diagnoseAssetIndex(resolvedVersion: ResolvedVersion, minecraft: MinecraftFolder, useHash: boolean= false): Promise<AssetIndexIssue | undefined>
Parameters
- resolvedVersion:
ResolvedVersion
- minecraft:
MinecraftFolder
- useHash:
boolean
Return Type
Promise<AssetIndexIssue | undefined>
Defined in: packages/core/diagnose.ts:290
diagnoseAssets
diagnoseAssets(assetObjects: Record<string, { hash: string; size: number }>, minecraft: MinecraftFolder, options: DiagnoseOptions): Promise<AssetIssue[]>
Diagnose assets currently installed.
Parameters
- assetObjects:
Record<string, { hash: string; size: number }>
The assets object metadata to check - minecraft:
MinecraftFolder
The minecraft location - options:
DiagnoseOptions
Return Type
Promise<AssetIssue[]>
Defined in: packages/core/diagnose.ts:224
diagnoseFile
diagnoseFile(__namedParameters: { algorithm?: string; expectedChecksum: string; file: string; hint: string; role: T }, options: DiagnoseOptions): Promise<undefined | { expectedChecksum: string; file: string; hint: string; receivedChecksum: string; role: T; type: "missing" | "corrupted" }>
Diagnose a single file by a certain checksum algorithm. By default, this use sha1
Parameters
- __namedParameters:
{ algorithm?: string; expectedChecksum: string; file: string; hint: string; role: T }
- options:
DiagnoseOptions
Return Type
Promise<undefined | { expectedChecksum: string; file: string; hint: string; receivedChecksum: string; role: T; type: "missing" | "corrupted" }>
Defined in: packages/core/diagnose.ts:119
diagnoseJar
diagnoseJar(resolvedVersion: ResolvedVersion, minecraft: MinecraftFolder, options: DiagnoseOptions & { side?: "server" | "client" }): Promise<MinecraftJarIssue | undefined>
Parameters
- resolvedVersion:
ResolvedVersion
- minecraft:
MinecraftFolder
- options:
DiagnoseOptions & { side?: "server" | "client" }
Return Type
Promise<MinecraftJarIssue | undefined>
Defined in: packages/core/diagnose.ts:300
diagnoseLibraries
diagnoseLibraries(resolvedVersion: ResolvedVersion, minecraft: MinecraftFolder, options: DiagnoseOptions): Promise<LibraryIssue[]>
Diagnose all libraries presented in this resolved version.
Parameters
- resolvedVersion:
ResolvedVersion
The resolved version to check - minecraft:
MinecraftFolder
The minecraft location - options:
DiagnoseOptions
Return Type
Promise<LibraryIssue[]>
Defined in: packages/core/diagnose.ts:261
generateArguments
generateArguments(options: LaunchOption): Promise<string[]>
Generate the arguments array by options. This function is useful if you want to launch the process by yourself.
This function will NOT check if the runtime libs are completed, and WONT'T check or extract native libs.
If you want to ensure native. Please see LaunchPrecheck.checkNatives.
Parameters
- options:
LaunchOption
The launch options.
Return Type
Promise<string[]>
Defined in: packages/core/launch.ts:658
generateArgumentsServer
generateArgumentsServer(options: ServerOptions, _delimiter: string= delimiter, _sep: string= sep): string[]
Generate the argument for server
Parameters
- options:
ServerOptions
- _delimiter:
string
- _sep:
string
Return Type
string[]
Defined in: packages/core/launch.ts:612
getPlatform
getPlatform(): Platform
Get Minecraft style platform info. (Majorly used to enable/disable native dependencies)
Return Type
Platform
Defined in: packages/core/platform.ts:24
launch
launch(options: LaunchOption): Promise<ChildProcess>
Launch the minecraft as a child process. This function use spawn to create child process. To use an alternative way, see function generateArguments.
By default, it will use the LauncherPrecheck.Default
to pre-check:
- It will also check if the runtime libs are completed, and will extract native libs if needed.
- It might throw exception when the version jar is missing/checksum not matched.
- It might throw if the libraries/natives are missing.
If you DON'T want such precheck, and you want to change it. You can assign the prechecks
property in launch
launch({ ...otherOptions, prechecks: yourPrechecks });
Parameters
- options:
LaunchOption
The detail options for this launching.
Return Type
Promise<ChildProcess>
Defined in: packages/core/launch.ts:573
launchServer
launchServer(options: ServerOptions): Promise<ChildProcess>
Parameters
- options:
ServerOptions
Return Type
Promise<ChildProcess>
Defined in: packages/core/launch.ts:458
🏷️ Variables
DEFAULT_EXTRA_JVM_ARGS const
DEFAULT_EXTRA_JVM_ARGS: readonly string[] = ...
Defined in: packages/core/launch.ts:23
⏩ Type Aliases
MinecraftIssues
MinecraftIssues: LibraryIssue | MinecraftJarIssue | VersionJsonIssue | AssetIssue | AssetIndexIssue
Defined in: packages/core/diagnose.ts:36
MinecraftLocation
MinecraftLocation: MinecraftFolder | string
Defined in: packages/core/folder.ts:104
VersionParseError
VersionParseError: (BadVersionJsonError | CorruptedVersionJsonError | MissingVersionJsonError | CircularDependenciesError) & Error | Error
Defined in: packages/core/version.ts:140