craft_launcher_core 0.0.1 copy "craft_launcher_core: ^0.0.1" to clipboard
craft_launcher_core: ^0.0.1 copied to clipboard

A simple launcher api for Minecraft Java Edition

Craft Launcher Core #

A Dart package for launching Minecraft Java Edition. This library simplifies the process of managing launcher profiles, downloading game assets, and starting Minecraft instances.

Features #

  • Minecraft version management
  • Game assets and libraries downloading
  • Java runtime detection and management
  • Profile configuration and customization
  • Launch with Microsoft authentication support
  • Extensible launcher adapter system

Getting started #

Add this package to your pubspec.yaml:

dependencies:
  craft_launcher_core: ^0.0.1

Then run:

flutter pub get

Usage #

Basic Launcher Setup #

import 'package:craft_launcher_core/vanilla_launcher.dart';
import 'package:craft_launcher_core/models/launcher_profiles.dart';

// Create a profile
final myProfile = Profile(
  icon: 'minecraft',
  name: 'MyProfile',
  type: 'latest-release',
  created: DateTime.now().toIso8601String(),
  lastUsed: DateTime.now().toIso8601String(),
  lastVersionId: '1.21.3',
);

// Initialize launcher
final launcher = VanillaLauncher(
  gameDir: '/path/to/minecraft',
  javaDir: '/path/to/java',
  profiles: LauncherProfiles(
    profiles: {'my_profile': myProfile},
    settings: Settings(
      enableSnapshots: false,
      keepLauncherOpen: true,
      showGameLog: true,
    ),
    version: 3,
  ),
  activeProfile: myProfile,
  onOperationProgress: (operation, completed, total, percentage) {
    print('$operation: $percentage%');
  },
);

// Launch the game
await launcher.launch(
  onStdout: (data) => print('Minecraft: $data'),
  onStderr: (data) => print('Error: $data'),
  onExit: (code) => print('Game exited with code: $code'),
);

Using with Microsoft Authentication #

import 'package:craft_launcher_core/vanilla_launcher.dart';
import 'package:craft_launcher_core/models/models.dart';
import 'package:mcid_connect/mcid_connect.dart';

// Authenticate with Microsoft (see mcid_connect package)
final authService = AuthService(
  clientId: 'your-azure-app-client-id',
  redirectUri: 'http://localhost:3000',
  scopes: ['XboxLive.signin', 'offline_access'],
  onGetDeviceCode: (deviceCodeResponse) {
    print('Please visit: ${deviceCodeResponse.verificationUri}');
    print('And enter this code: ${deviceCodeResponse.userCode}');
  },
);

await authService.startAuthenticationFlow();

// Initialize the launcher with auth
final launcher = VanillaLauncher(
  // Game directory settings
  gameDir: '/path/to/minecraft',
  javaDir: '/path/to/java',
  profiles: myProfiles,
  activeProfile: myProfile,
  
  // Authentication data from Microsoft login
  minecraftAuth: MinecraftAuth(
    clientId: 'your-azure-app-client-id',
    authXuid: authService.xstsUhs,
    userName: authService.minecraftProfile.name,
    uuid: authService.minecraftProfile.id,
    accessToken: authService.minecraftToken,
    userType: 'msa',
  ),
);

// Launch with authentication
await launcher.launch();

Creating a Custom Launcher Adapter #

You can extend the launcher functionality by implementing a custom adapter:

import 'package:craft_launcher_core/launcher_adapter.dart';

class ModdedLauncherAdapter implements LauncherAdapter {
  final LauncherAdapter _vanillaAdapter;
  
  ModdedLauncherAdapter(this._vanillaAdapter);
  
  @override
  Future<void> afterBuildClasspath(
    VersionInfo versionInfo, 
    String versionId, 
    List<String> classpath
  ) async {
    // Add mod loaders to classpath
    classpath.add('/path/to/forge.jar');
    
    // Continue with vanilla behavior
    await _vanillaAdapter.afterBuildClasspath(versionInfo, versionId, classpath);
  }
  
  // Implement other interface methods or delegate to vanilla adapter
  @override
  Future<void> beforeStartProcess(
    String javaExe,
    List<String> javaArgs,
    String workingDirectory,
    Map<String, String> environment,
    String versionId,
    MinecraftAuth? auth,
  ) async {
    // Add custom JVM arguments
    javaArgs.add('-Dfml.ignoreInvalidMinecraftCertificates=true');
    
    await _vanillaAdapter.beforeStartProcess(
      javaExe, javaArgs, workingDirectory, environment, versionId, auth
    );
  }
}

Additional information #

Requirements #

  • Dart SDK 3.7.2 or higher
  • Java Runtime Environment (JRE) or Java Development Kit (JDK) for running Minecraft
  • Internet connection for downloading game assets and libraries

Contributing #

Contributions are welcome! Feel free to submit issues or pull requests on the GitHub repository.

License #

This package is available under the MIT License.

0
likes
0
points
92
downloads

Publisher

verified publisherkarasu256.com

Weekly Downloads

A simple launcher api for Minecraft Java Edition

Homepage

License

unknown (license)

Dependencies

archive, crypto, envied, flutter, http, json_annotation, json_serializable, mcid_connect, path, path_provider, uuid

More

Packages that depend on craft_launcher_core