Skip to content

Launcher Core Module

npm versionDownloadsInstall sizenpmBuild Status

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.

ts
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.

ts
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:

ts
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.

ts
const proc: Promise<ChildProcess> = Launcher.launch({ gamePath, javaPath, version, extraExecOption: { detached: true } });

🧾 Classes

🤝 Interfaces

🗃️ Namespaces

🏭 Functions

createMinecraftProcessWatcher

ts
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:491

diagnose

ts
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:156

diagnoseAssetIndex

ts
diagnoseAssetIndex(resolvedVersion: ResolvedVersion, minecraft: MinecraftFolder): Promise<AssetIndexIssue | undefined>

Parameters

  • resolvedVersion: ResolvedVersion
  • minecraft: MinecraftFolder

Return Type

  • Promise<AssetIndexIssue | undefined>

Defined in: packages/core/diagnose.ts:280

diagnoseAssets

ts
diagnoseAssets(assetObjects: Record<string, Object>, minecraft: MinecraftFolder, options: DiagnoseOptions): Promise<AssetIssue[]>

Diagnose assets currently installed.

Parameters

  • assetObjects: Record<string, Object> The assets object metadata to check
  • minecraft: MinecraftFolder The minecraft location
  • options: DiagnoseOptions

Return Type

  • Promise<AssetIssue[]>

Defined in: packages/core/diagnose.ts:214

diagnoseFile

ts
diagnoseFile(__namedParameters: Object, options: DiagnoseOptions): Promise<undefined | Object>

Diagnose a single file by a certain checksum algorithm. By default, this use sha1

Parameters

  • __namedParameters: Object
  • options: DiagnoseOptions

Return Type

  • Promise<undefined | Object>

Defined in: packages/core/diagnose.ts:119

diagnoseJar

ts
diagnoseJar(resolvedVersion: ResolvedVersion, minecraft: MinecraftFolder, options: DiagnoseOptions): Promise<MinecraftJarIssue | undefined>

Parameters

  • resolvedVersion: ResolvedVersion
  • minecraft: MinecraftFolder
  • options: DiagnoseOptions

Return Type

  • Promise<MinecraftJarIssue | undefined>

Defined in: packages/core/diagnose.ts:290

diagnoseLibraries

ts
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:251

generateArguments

ts
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 checkNatives.

Parameters

  • options: LaunchOption The launch options.

Return Type

  • Promise<string[]>

Defined in: packages/core/launch.ts:605

generateArgumentsServer

ts
generateArgumentsServer(options: MinecraftServerOptions | ServerOptions): Promise<string[]>

Generate the argument for server

Parameters

  • options: MinecraftServerOptions | ServerOptions

Return Type

  • Promise<string[]>

Defined in: packages/core/launch.ts:569

getPlatform

ts
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

ts
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

ts
launch({ ...otherOptions, prechecks: yourPrechecks });

Parameters

  • options: LaunchOption The detail options for this launching.

Return Type

  • Promise<ChildProcess>

Defined in: packages/core/launch.ts:543

launchServer

ts
launchServer(options: MinecraftServerOptions | ServerOptions): Promise<ChildProcess>

Parameters

  • options: MinecraftServerOptions | ServerOptions

Return Type

  • Promise<ChildProcess>

Defined in: packages/core/launch.ts:427

🏷️ Variables

DEFAULT_EXTRA_JVM_ARGS

ts
DEFAULT_EXTRA_JVM_ARGS: readonly string[] = ...

Defined in: packages/core/launch.ts:23

⏩ Type Aliases

MinecraftIssues

ts
MinecraftIssues: LibraryIssue | MinecraftJarIssue | VersionJsonIssue | AssetIssue | AssetIndexIssue

Defined in: packages/core/diagnose.ts:36

MinecraftLocation

ts
MinecraftLocation: MinecraftFolder | string

Defined in: packages/core/folder.ts:98

VersionParseError

ts
VersionParseError: (BadVersionJsonError | CorruptedVersionJsonError | MissingVersionJsonError | CircularDependenciesError) & Error | Error

Defined in: packages/core/version.ts:140

Released under the MIT License.