Now the *launcher* can actually launch mInECraFT.
This commit is contained in:
@@ -5,7 +5,7 @@ from core_lib.game.library import get_natives_platform_info
|
||||
|
||||
logger = logging.getLogger("Launcher.CoreLib")
|
||||
|
||||
def is_argument_allowed(argument: dict | str, allow_features: dict=dict) -> bool:
|
||||
def is_argument_allowed(argument: dict | str, allow_features: dict | None=None) -> bool:
|
||||
"""
|
||||
Check if argument is allowed or not.
|
||||
:param argument:
|
||||
@@ -16,6 +16,9 @@ def is_argument_allowed(argument: dict | str, allow_features: dict=dict) -> bool
|
||||
if isinstance(argument, str):
|
||||
return True
|
||||
|
||||
if allow_features is None:
|
||||
allow_features = {}
|
||||
|
||||
rules = argument.get('rules', {})
|
||||
|
||||
_, platform_rule_name, _ = get_natives_platform_info()
|
||||
@@ -125,7 +128,48 @@ def convert_argument_to_multiple_string(argument: str | dict) -> list[str]:
|
||||
|
||||
raise TypeError("Argument must be of type str or dict")
|
||||
|
||||
def parse_and_generate_arguments(arguments: list | str, mappings: ArgumentMappings, features: dict=dict) -> list[str]:
|
||||
def find_game_and_jvm_args(arguments: dict | str) -> tuple[list, list]:
|
||||
game_args = []
|
||||
jvm_args = []
|
||||
|
||||
if isinstance(arguments, dict):
|
||||
game = arguments.get("game", [])
|
||||
jvm = arguments.get("jvm", [])
|
||||
|
||||
if isinstance(game, list):
|
||||
game_args.extend(game)
|
||||
elif isinstance(game, str):
|
||||
game_args.append(game)
|
||||
|
||||
if isinstance(jvm, list):
|
||||
jvm_args.extend(jvm)
|
||||
elif isinstance(jvm, str):
|
||||
jvm_args.append(jvm)
|
||||
|
||||
if isinstance(arguments, str):
|
||||
# Convert legacy argument into a list type
|
||||
game_args = shlex.split(arguments)
|
||||
|
||||
return game_args, jvm_args
|
||||
|
||||
REMAPPING_ARGUMENTS = {
|
||||
# For some (I don't know) reason, in 26.2, Mojang include some
|
||||
"-Djava.library.path=${natives_directory}/java": "-Djava.library.path=${natives_directory}"
|
||||
}
|
||||
|
||||
def hard_remapping_special_arguments(argument: str) -> str:
|
||||
for arg in REMAPPING_ARGUMENTS:
|
||||
new_value = REMAPPING_ARGUMENTS[arg]
|
||||
|
||||
if arg == argument:
|
||||
return new_value
|
||||
|
||||
return argument
|
||||
|
||||
def parse_and_generate_arguments(arguments: list | str, mappings: ArgumentMappings, features: dict | None=None) -> list[str]:
|
||||
if features is None:
|
||||
features = {}
|
||||
|
||||
parsed_arguments = []
|
||||
|
||||
if isinstance(arguments, str):
|
||||
@@ -139,8 +183,11 @@ def parse_and_generate_arguments(arguments: list | str, mappings: ArgumentMappin
|
||||
if not is_argument_allowed(argument, allow_features=features):
|
||||
continue
|
||||
|
||||
# Replace some special arguments
|
||||
new_argument = hard_remapping_special_arguments(argument)
|
||||
|
||||
# Each argument (section) may contain multiple items, convert it to list before replace placeholder
|
||||
converted = convert_argument_to_multiple_string(argument)
|
||||
converted = convert_argument_to_multiple_string(new_argument)
|
||||
|
||||
for item in converted:
|
||||
parsed = replace_placeholders(item, placeholders)
|
||||
@@ -149,3 +196,30 @@ def parse_and_generate_arguments(arguments: list | str, mappings: ArgumentMappin
|
||||
return parsed_arguments
|
||||
|
||||
|
||||
def generate_launch_command(arg_maps: ArgumentMappings, main_class: str, java_path: str, full_args: dict | str
|
||||
) -> list[str]:
|
||||
cmd = [java_path]
|
||||
game_args, jvm_args = find_game_and_jvm_args(full_args)
|
||||
parsed_jvm_args = parse_and_generate_arguments(
|
||||
jvm_args,
|
||||
arg_maps
|
||||
)
|
||||
parsed_game_args = parse_and_generate_arguments(
|
||||
game_args,
|
||||
arg_maps
|
||||
)
|
||||
|
||||
# Legacy Minecraft don't have jvm arguments exist in the version library. We need to generate by ourselves
|
||||
if len(parsed_jvm_args) == 0:
|
||||
cmd.extend([
|
||||
f"-Djava.library.path={arg_maps.natives_directory}",
|
||||
"-cp",
|
||||
arg_maps.classpath,
|
||||
])
|
||||
else:
|
||||
cmd.extend(parsed_jvm_args)
|
||||
|
||||
cmd.append(main_class)
|
||||
cmd.extend(parsed_game_args)
|
||||
|
||||
return cmd
|
||||
Reference in New Issue
Block a user