diff --git a/OrzMC/app/Client.py b/OrzMC/app/Client.py index 5fe0a17..39992f1 100644 --- a/OrzMC/app/Client.py +++ b/OrzMC/app/Client.py @@ -4,6 +4,8 @@ from ..utils.utils import * from ..utils.ColorString import ColorString from ..core.OptiFine import OptiFine +from ..core.Fabric import Fabric + import os import uuid import datetime @@ -147,12 +149,19 @@ def gameArguments(self, user, resolution): mainCls = self.config.game_version_json_obj().get('mainClass') classPathList = self.javaClassPathList() - if self.config.isPure and self.config.optifine: - optifine_config = OptiFine.json_configuration(self.config) - if optifine_config != None: - mainCls = optifine_config.get('mainClass') - optifine_jar_paths = OptiFine.library_optifine_jar_paths(self.config) - classPathList = optifine_jar_paths + classPathList + if self.config.isPure: + if self.config.optifine: + optifine_config = OptiFine.json_configuration(self.config) + if optifine_config != None: + mainCls = optifine_config.get('mainClass') + optifine_jar_paths = OptiFine.library_optifine_jar_paths(self.config) + classPathList = optifine_jar_paths + classPathList + elif self.config.fabric: + fabric_config = Fabric.json_configuration(self.config) + if fabric_config != None: + mainCls = fabric_config.get('mainClass') + fabric_jar_paths = Fabric.library_fabric_jar_paths(self.config) + classPathList = fabric_jar_paths + classPathList sep = self.config.java_class_path_list_separator() classPath = sep.join(classPathList) @@ -199,6 +208,10 @@ def gameArguments(self, user, resolution): '-Xmx%s' % mem_max, '-Djava.net.preferIPv4Stack=true' ] + + if self.config.isPure and self.config.fabric: + jvm_opts.extend(Fabric.jvmOpts(self.config)) + arguments.extend(jvm_opts) game_arguments = self.config.game_version_json_obj().get('arguments') @@ -277,10 +290,16 @@ def gameArguments(self, user, resolution): if self.config.isForge: arguments.extend(self.config.game_version_json_obj().get('arguments').get('game')) - if self.config.isPure and self.config.optifine: - optifine_config = OptiFine.json_configuration(self.config) - if optifine_config != None: - arguments.extend(optifine_config.get('arguments').get('game')) + if self.config.isPure: + if self.config.optifine: + optifine_config = OptiFine.json_configuration(self.config) + if optifine_config != None: + arguments.extend(optifine_config.get('arguments').get('game')) + elif self.config.fabric: + fabric_config = Fabric.json_configuration(self.config) + if fabric_config != None: + arguments.extend(fabric_config.get('arguments').get('game')) + arguments = ' '.join(arguments) return arguments diff --git a/OrzMC/app/Config.py b/OrzMC/app/Config.py index c04265d..ab1fa60 100644 --- a/OrzMC/app/Config.py +++ b/OrzMC/app/Config.py @@ -56,6 +56,7 @@ def __init__(self,args): self.force_upgrade = args.force_upgrade_world self.backup = args.backup_world self.optifine = args.optifine + self.fabric = args.fabric self.api = args.api self.force_download = args.force_download diff --git a/OrzMC/app/Console.py b/OrzMC/app/Console.py index aea788d..9de584a 100644 --- a/OrzMC/app/Console.py +++ b/OrzMC/app/Console.py @@ -77,9 +77,12 @@ def showUserName(self): def selectLauncherProfile(self): - if not self.config.is_client or not self.config.isPure or not self.config.optifine: + if not self.config.is_client or not self.config.isPure: return + if not (self.config.optifine or self.config.fabric): + return + launcher_profiles_json_file_path = self.config.game_version_launcher_profiles_json_path() if os.path.exists(launcher_profiles_json_file_path): content = None diff --git a/OrzMC/app/Downloader.py b/OrzMC/app/Downloader.py index c7b46cb..207c745 100644 --- a/OrzMC/app/Downloader.py +++ b/OrzMC/app/Downloader.py @@ -7,6 +7,7 @@ from ..core.Spigot import Spigot from ..core.Forge import Forge from ..core.OptiFine import OptiFine +from ..core.Fabric import Fabric from ..core.BMCLAPI import BMCLAPI from tqdm import tqdm @@ -166,6 +167,8 @@ def donwloadLibraries(self): filePath=os.path.join(fileDir,os.path.basename(url)) if not checkFileExist(filePath,sha1): self.download(url,fileDir, prefix_desc=prefix_desc) + + self.downloadFabricLibraries() def downloadPaperServerJarFile(self): '''下载Paper服务端JAR文件''' @@ -268,4 +271,15 @@ def redirectUrl(self,url): print(redirected_url) return redirected_url - return url \ No newline at end of file + return url + + def downloadFabricLibraries(self): + if self.config.isPure and self.config.fabric: + for (url, file_path) in Fabric.downloadLibrariesMap(self.config).items(): + dir_path = os.path.dirname(file_path) + if not os.path.exists(dir_path): + self.download( + url, + dir_path, + prefix_desc = 'Fabric:' + ) \ No newline at end of file diff --git a/OrzMC/app/Game.py b/OrzMC/app/Game.py index 214f00a..037f7b0 100644 --- a/OrzMC/app/Game.py +++ b/OrzMC/app/Game.py @@ -25,10 +25,13 @@ def start(self): # 控制台用户交互展示 self.console.userInteraction() - try: - #启动游戏 - self.game.start() - - except Exception as e: - print(e) - print(ColorString.warn('Start Failed!!!')) \ No newline at end of file + if self.config.debug: + self.game.start() + else: + try: + #启动游戏 + self.game.start() + + except Exception as e: + print(e) + print(ColorString.warn('Start Failed!!!')) \ No newline at end of file diff --git a/OrzMC/app/OrzMC.py b/OrzMC/app/OrzMC.py index 335e9a8..ba1065c 100644 --- a/OrzMC/app/OrzMC.py +++ b/OrzMC/app/OrzMC.py @@ -64,6 +64,8 @@ def parse_args(): parser.add_argument('-d','--daemon', dest='deamon', default=False, action='store_true', help='config daemon for minecraft server with systemctl manage') # setup minecraft server skin system parser.add_argument('-S','--skin_system', dest='skin_system', default=False, action='store_true', help='setup skin system for minecraft paper server') + # setup fabric + parser.add_argument('-M','--fabric', default=False, action='store_true', help='if you have installed fabric for client, you can add this option to launch client with fabric be activated') args = parser.parse_args() return args diff --git a/OrzMC/core/Fabric.py b/OrzMC/core/Fabric.py new file mode 100644 index 0000000..6f681d4 --- /dev/null +++ b/OrzMC/core/Fabric.py @@ -0,0 +1,50 @@ +# -*- coding: utf8 -*- +import os +import json +import re +from ..utils.utils import makedirs + +# https://fabricmc.net/use/ + +class Fabric: + + _configuration = None + + @classmethod + def json_configuration(cls, config): + if Fabric._configuration == None: + fabric_json_path = os.path.join(config.game_version_client_versions_dir(), config.lastVersionId, config.lastVersionId + '.json') + if 'fabric' in config.lastVersionId.lower() and os.path.exists(fabric_json_path): + with open(fabric_json_path, 'r') as f: + Fabric._configuration = json.load(f) + return Fabric._configuration + + @classmethod + def library_fabric_jar_paths(cls, config): + ret = [] + for (url, file_path) in Fabric.downloadLibrariesMap(config).items(): + ret.append(file_path) + return ret + + @classmethod + def jvmOpts(cls, config): + ret = [] + for o in Fabric.json_configuration(config).get('arguments').get('jvm'): + o = re.sub(r'\s','',o) + ret.append(o) + return ret + + @classmethod + def downloadLibrariesMap(cls, config): + ret = {} + for l in Fabric.json_configuration(config).get('libraries'): + name = l.get('name') + splits = name.split(':') + splits = splits[0].split('.') + splits[1:] + file_name = '-'.join(splits[-2:]) + '.jar' + dir_path = os.path.join(config.game_version_client_library_dir(),*splits) + makedirs(dir_path) + url_path ='/'.join(splits + [file_name]) + url = l.get('url') + url_path + ret[url] = os.path.join(dir_path, file_name) + return ret diff --git a/OrzMC/core/OptiFine.py b/OrzMC/core/OptiFine.py index 9a8721a..58c0dd4 100644 --- a/OrzMC/core/OptiFine.py +++ b/OrzMC/core/OptiFine.py @@ -2,6 +2,8 @@ import os import json +# https://www.optifine.net/downloads + class OptiFine: _configuration = None diff --git a/OrzMC/core/__init__.py b/OrzMC/core/__init__.py index 64f7a25..9991a23 100644 --- a/OrzMC/core/__init__.py +++ b/OrzMC/core/__init__.py @@ -8,4 +8,5 @@ 'PaperAPI', 'Spigot', 'BMCLAPI', + 'Fabric', ] \ No newline at end of file diff --git a/OrzMCL/OrzMCL.py b/OrzMCL/OrzMCL.py index 9259680..4de9413 100755 --- a/OrzMCL/OrzMCL.py +++ b/OrzMCL/OrzMCL.py @@ -94,7 +94,8 @@ def startGame(self, instance): debug = False, force_upgrade = False, backup = False, - optifine = False + optifine = False, + fabric = False, ) Game(config).startClient() self.infoLabel.text = ''