command

command contains the function for creating the minecraft command

get_minecraft_command(version: str, minecraft_directory: str | PathLike, options: MinecraftOptions) list[str]

Returns the command to run Minecraft as a list. The returned command can be executed using Python’s subprocess module.

You must provide a dictionary containing launch options. Some options are required and others are optional. The following options are available:

options = {
    # This is needed
    "username": "", # The Username,
    "uuid": "", # uuid of the user,
    "token": "", # the accessToken,
    # This is optional
    "executablePath": "java", # The path to the java executable
    "defaultExecutablePath": "java", # The path to the java executable if the client.json has none
    "jvmArguments": [], # The jvmArguments
    "launcherName": "minecraft-launcher-lib", # The name of your launcher
    "launcherVersion": "1.0", # The version of your launcher
    "gameDirectory": "/home/user/.minecraft", # The gameDirectory (default is the path given in arguments)
    "demo": False, # Run Minecraft in demo mode
    "customResolution": False, # Enable custom resolution
    "resolutionWidth": "854", # The resolution width
    "resolutionHeight": "480", # The resolution height
    "server": "example.com", # The IP of a server where Minecraft connect to after start
    "port": "123", # The port of a server where Minecraft connect to after start
    "nativesDirectory": "minecraft_directory/versions/version/natives", # The natives directory
    "enableLoggingConfig": False, # Enable use of the log4j configuration file
    "disableMultiplayer": False, # Disables the multiplayer
    "disableChat": False, # Disables the chat
    "quickPlayPath": None, # The Quick Play Path
    "quickPlaySingleplayer": None, # The Quick Play Singleplayer
    "quickPlayMultiplayer": None, # The Quick Play Multiplayer
    "quickPlayRealms": None, # The Quick Play Realms
}

Use the microsoft_account module to obtain account-related information. For details about available options, see the More Launch Options tutorial.

To test this function without logging in, use generate_test_options() to create sample launch options. Only use those test options for development and testing until you implement proper account handling

Example:

options = minecraft_launcher_lib.utils.generate_test_options()
minecraft_directory = minecraft_launcher_lib.utils.get_minecraft_directory()
command = minecraft_launcher_lib.command.get_minecraft_command("1.21", minecraft_directory, options)
subprocess.run(command, pwd=minecraft_directory)
Parameters:
  • version (str) – The Minecraft version

  • minecraft_directory (str | PathLike) – The path to your Minecraft directory

  • options (MinecraftOptions) – Some Options

Raises:

VersionNotFound – The Minecraft version was not found

Returns:

The command

Return type:

list[str]

View the source code of this module