Skip to content

Commit 9247e7b

Browse files
committed
feat: add modpack selection functionality and improve modpack management; refactor Minecraft launch process
1 parent 57dafb8 commit 9247e7b

File tree

5 files changed

+486
-189
lines changed

5 files changed

+486
-189
lines changed

src/auth.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,5 +260,16 @@ async def __render_skin(self, skin_url):
260260
return resp
261261
return resp
262262

263+
@property
264+
def username(self):
265+
return self.user["user"]["players"][0]["name"]
266+
267+
@property
268+
def uuid(self):
269+
return self.user["user"]["players"][0]["uuid"]
270+
271+
@property
272+
def access_token(self):
273+
return self.account.get("access_token", "")
263274

264275
account = Auth()

src/config.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@
4040
f"https://raw.githubusercontent.com/{MODPACK_REPO}/refs/heads/main/README.md"
4141
)
4242

43-
MODPACK_INDEX_URL = (
44-
f"https://raw.githubusercontent.com/{MODPACK_REPO}/refs/heads/main/modrinth.index.json"
45-
)
4643
MODPACK_REPO_URL = f"https://github.com/{MODPACK_REPO}"
4744
LATEST_LAUNCHER_RELEASE_URL = (
4845
"https://api.github.com/repos/cubedvij/launcher/releases/latest"

src/minecraft_launcher_lib/install.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import shutil
44
from concurrent.futures import ThreadPoolExecutor
55
from pathlib import Path
6+
import platform
67
from typing import Optional
78

89
import httpx
@@ -23,7 +24,9 @@
2324

2425
__all__ = ["install_minecraft_version"]
2526

26-
27+
_platform = platform.system().lower()
28+
if _platform == "darwin":
29+
_platform = "osx"
2730

2831

2932
def _download_and_extract_native(
@@ -65,7 +68,8 @@ def install_libraries(
6568
"""
6669
base_path = Path(base_path)
6770
filtered_libraries = [
68-
lib_info for lib_info in libraries
71+
lib_info
72+
for lib_info in libraries
6973
if parse_rule_list(lib_info.get("rules", []), {})
7074
]
7175

@@ -75,8 +79,15 @@ def install_libraries(
7579
def download_library(lib_info: ClientJsonLibrary) -> None:
7680
# Download natives if present
7781
if "classifiers" in lib_info.get("downloads", {}):
78-
jar_filename_native = lib_info["downloads"]["artifact"]["path"]
79-
libraries_path = base_path / "libraries" / lib_info["path"]
82+
jar_filename_native = lib_info["downloads"].get("artifact")
83+
if jar_filename_native:
84+
jar_filename_native = jar_filename_native["path"]
85+
else:
86+
jar_filename_native = lib_info["downloads"]["classifiers"][
87+
f"natives-{_platform}"
88+
]["path"]
89+
libraries_path = base_path / "libraries" / Path(jar_filename_native).parent
90+
libraries_path.mkdir(parents=True, exist_ok=True)
8091
check_path_inside_minecraft_directory(str(base_path), str(libraries_path))
8192
_download_and_extract_native(
8293
lib_info, libraries_path, jar_filename_native, version_id, base_path
@@ -203,7 +214,10 @@ def do_version_install(
203214
jobs.append(
204215
{
205216
"url": client_info["url"],
206-
"path": base_path / "versions" / versiondata["id"] / f"{versiondata['id']}.jar",
217+
"path": base_path
218+
/ "versions"
219+
/ versiondata["id"]
220+
/ f"{versiondata['id']}.jar",
207221
"sha1": client_info["sha1"],
208222
"minecraft_directory": str(base_path),
209223
}
@@ -279,4 +293,4 @@ def install_minecraft_version(
279293
sha1=version.get("sha1"),
280294
)
281295
return
282-
raise VersionNotFound(version_id)
296+
raise VersionNotFound(version_id)

0 commit comments

Comments
 (0)