Skip to content

Commit

Permalink
add client fabric support
Browse files Browse the repository at this point in the history
  • Loading branch information
wangzhizhou committed Aug 16, 2021
1 parent 6ea8237 commit 9a56e8f
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 20 deletions.
39 changes: 29 additions & 10 deletions OrzMC/app/Client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions OrzMC/app/Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion OrzMC/app/Console.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 15 additions & 1 deletion OrzMC/app/Downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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文件'''
Expand Down Expand Up @@ -268,4 +271,15 @@ def redirectUrl(self,url):
print(redirected_url)
return redirected_url

return url
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:'
)
17 changes: 10 additions & 7 deletions OrzMC/app/Game.py
Original file line number Diff line number Diff line change
Expand Up @@ -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!!!'))
if self.config.debug:
self.game.start()
else:
try:
#启动游戏
self.game.start()

except Exception as e:
print(e)
print(ColorString.warn('Start Failed!!!'))
2 changes: 2 additions & 0 deletions OrzMC/app/OrzMC.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
50 changes: 50 additions & 0 deletions OrzMC/core/Fabric.py
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions OrzMC/core/OptiFine.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import os
import json

# https://www.optifine.net/downloads

class OptiFine:

_configuration = None
Expand Down
1 change: 1 addition & 0 deletions OrzMC/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
'PaperAPI',
'Spigot',
'BMCLAPI',
'Fabric',
]
3 changes: 2 additions & 1 deletion OrzMCL/OrzMCL.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ''
Expand Down

0 comments on commit 9a56e8f

Please sign in to comment.