vanilla_launcher
vanilla_launcher contains some functions for interacting with the Vanilla Minecraft Launcher
- load_vanilla_launcher_profiles(minecraft_directory: str | PathLike) list[VanillaLauncherProfile]
Loads the profiles of the Vanilla Launcher from the given Minecraft directory
Example:
minecraft_directory = minecraft_launcher_lib.utils.get_minecraft_directory() profiles = minecraft_launcher_lib.vanilla_launcher.load_vanilla_launcher_profiles(minecraft_directory) for profile in profiles: print(profile["name"])
- Parameters:
minecraft_directory (str | PathLike) – The Minecraft directory
- Returns:
A List with the Profiles
- Return type:
list[VanillaLauncherProfile]
- vanilla_launcher_profile_to_minecraft_options(vanilla_profile: VanillaLauncherProfile) MinecraftOptions
Converts a VanillaLauncherProfile into a Options dict, that can be used by
get_minecraft_command(). You still need to add the Login Data to the Options before you can use it.Example:
minecraft_directory = minecraft_launcher_lib.utils.get_minecraft_directory() profiles = minecraft_launcher_lib.vanilla_launcher.load_vanilla_launcher_profiles(minecraft_directory) test_options = minecraft_launcher_lib.utils.generate_test_options() profile_options = minecraft_launcher_lib.vanilla_launcher.vanilla_launcher_profile_to_minecraft_options(profiles[0]) options = test_options | profile_options minecraft_version = minecraft_launcher_lib.vanilla_launcher.get_vanilla_launcher_profile_version(profiles[0]) command = minecraft_launcher_lib.command.get_minecraft_command(minecraft_version, minecraft_directory, options) subprocess.run(command, cwd=minecraft_directory)
- Parameters:
vanilla_profile (VanillaLauncherProfile) – The profile as returned by
load_vanilla_launcher_profiles()- Raises:
InvalidVanillaLauncherProfile – The given Profile is invalid
- Returns:
The Options Dict
- Return type:
- get_vanilla_launcher_profile_version(vanilla_profile: VanillaLauncherProfile) str
Returns the Minecraft version of the VanillaProfile. Handles
latest-releaseandlatest-snapshot.Example:
minecraft_directory = minecraft_launcher_lib.utils.get_minecraft_directory() profiles = minecraft_launcher_lib.vanilla_launcher.load_vanilla_launcher_profiles(minecraft_directory) for profile in profiles: print(minecraft_launcher_lib.vanilla_launcher.get_vanilla_launcher_profile_version(profile))
- Parameters:
vanilla_profile (VanillaLauncherProfile) – The Profile
- Raises:
InvalidVanillaLauncherProfile – The given Profile is invalid
- Returns:
The Minecraft version
- Return type:
str
- add_vanilla_launcher_profile(minecraft_directory: str | PathLike, vanilla_profile: VanillaLauncherProfile) None
Adds a new Profile to the Vanilla Launcher
Example:
profile: minecraft_launcher_lib.types.VanillaLauncherProfile = { "name": "test", "versionType": "latest-release", } minecraft_directory = minecraft_launcher_lib.utils.get_minecraft_directory() minecraft_launcher_lib.vanilla_launcher.add_vanilla_launcher_profile(minecraft_directory, profile)
- Parameters:
minecraft_directory (str | PathLike) – The Minecraft directory
vanilla_profile (VanillaLauncherProfile) – The new Profile
- Raises:
InvalidVanillaLauncherProfile – The given Profile is invalid
- Return type:
None
- do_vanilla_launcher_profiles_exists(minecraft_directory: str | PathLike) bool
Checks if profiles from the vanilla launcher can be found
Example:
minecraft_directory = minecraft_launcher_lib.utils.get_minecraft_directory() if minecraft_launcher_lib.vanilla_launcher.do_vanilla_launcher_profiles_exists(minecraft_directory): print("Profiles exists") else: print("Profiles do not exists")
- Parameters:
minecraft_directory (str | PathLike) – The Minecraft directory
- Returns:
If profiles exists
- Return type:
bool
- create_empty_vanilla_launcher_profiles_file(minecraft_directory: str | PathLike) None
Creates a
launcher_profiles.jsonfile with the correct structure inside the Minecraft directory. This function is useful for 3rd party software (e.g. some mod installers) that requires this file to be present. A existing file will be overwritten, so sue this function with caution.Example:
minecraft_directory = minecraft_launcher_lib.utils.get_minecraft_directory() minecraft_launcher_lib.vanilla_launcher.create_empty_vanilla_launcher_profiles_file(minecraft_directory)
- Parameters:
minecraft_directory (str | PathLike) – The Minecraft directory
- Return type:
None
Added in version 8.0.
- ensure_vanilla_launcher_profiles_exists(minecraft_directory: str | PathLike) None
Calls
create_empty_vanilla_launcher_profiles_file()ifdo_vanilla_launcher_profiles_exists()returnsFalse. You should call this function before you use a 3rd party software that requireslauncher_profiles.jsonto be present.Example:
minecraft_directory = minecraft_launcher_lib.utils.get_minecraft_directory() minecraft_launcher_lib.vanilla_launcher.ensure_vanilla_launcher_profiles_exists(minecraft_directory)
- Parameters:
minecraft_directory (str | PathLike) – The Minecraft directory
- Return type:
None
Added in version 8.0.