minecraft-detector
v0.2.1
Published
A TypeScript library to detect running Minecraft instances on Windows, including version, mod loader, login type, and LAN ports.
Maintainers
Readme
Minecraft Detector
A TypeScript library to detect running Minecraft instances on Windows, including version, mod loader, login type, and LAN ports.
Features
- Detects all running Minecraft processes.
- Parses Minecraft version (supports
--version,--assetIndex, or logs fallback). - Detects mod loader type (Vanilla, Forge, Fabric, Quilt) and loader version.
- Parses login info and determines login type (
offline,msa,other). - Detects LAN ports in use by Minecraft instances.
Installation
# Using bun
bun add minecraft-detector
# Using npm
npm install minecraft-detector
# Using yarn
yarn add minecraft-detector
# Using pnpm
pnpm add minecraft-detectorNote: This library is designed for Windows and uses PowerShell to detect running processes.
Usage
import MinecraftDetector from 'minecraft-detector';
async function main() {
const instances = await MinecraftDetector.detectAll();
console.log(instances);
}
main();MinecraftInstance Structure
type ModLoader = "Vanilla" | "Forge" | "Fabric" | "Quilt" | "NeoForge";
type LoginType = "offline" | "msa" | "custom" | "other";
interface MinecraftInstance {
pid: number; // 进程ID
java: string; // Java路径
version?: string; // Minecraft版本
loader: ModLoader; // 模组加载器
loaderVersion?: string; // 模组加载器版本
username?: string; // 玩家名称
uuid?: string; // 玩家UUID
loginType?: LoginType; // 登录类型
versionType?: string; // 启动器名称
provider?: string; // 登录提供者,仅第三方登录
lanPorts: number[]; // 局域网游戏端口
isLan: boolean; // 是否开启局域网游戏
}ModLoaderInfo Structure
interface ModLoaderInfo {
loader: ModLoader; // 模组加载器
loaderVersion?: string; // 模组加载器版本
}LoginInfo Structure
interface LoginInfo {
username?: string; // 玩家名称
uuid?: string; // 玩家UUID
loginType?: LoginType; // 登录类型
provider?: string; // 登录提供者,仅第三方登录
versionType?: string; // 登录版本类型
}API
MinecraftDetector.detectAll(mcDir?: string): Promise<MinecraftInstance[]>
Detects all running Minecraft instances.
mcDir(optional): Path to the Minecraft directory (default:%USERPROFILE%\\.minecraft).- Returns a promise that resolves to an array of
MinecraftInstanceobjects.
MinecraftDetector.parseVersion(cmd: string, mcDir?: string): string | undefined
Parses the Minecraft version from the command line or logs.
MinecraftDetector.parseModLoader(cmd: string, mcDir?: string): ModLoaderInfo
Parses the mod loader type and version from the command line or libraries folder.
MinecraftDetector.parseLoginInfo(cmd: string): LoginInfo
Parses login information from the command line and determines login type.
Notes
- Only tested on Windows.
- Uses PowerShell to query running processes and TCP connections.
- Handles Forge, Fabric, and Quilt mod loaders.
- Determines login type based on
--accessTokenJWT structure.
License
MIT
