-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
63 lines (49 loc) · 1.63 KB
/
build.py
File metadata and controls
63 lines (49 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import os
import sys
import zipfile
import shutil
from pathlib import Path
PACK_NAME = "aquatic"
OUTPUT_NAME = f"{PACK_NAME}.zip"
ROOT = Path(".")
BUILD_DIR = ROOT / "build"
ZIP_PATH = BUILD_DIR / OUTPUT_NAME
REQUIRED = ["assets", "pack.mcmeta", "pack.png"]
def get_mc_resourcepacks_path():
home = Path.home()
if sys.platform.startswith("win"):
return Path(os.getenv("APPDATA")) / ".minecraft" / "resourcepacks"
elif sys.platform == "darwin":
return home / "Library" / "Application Support" / "minecraft" / "resourcepacks"
else:
return home / ".minecraft" / "resourcepacks"
def validate():
for item in REQUIRED:
if not (ROOT / item).exists():
raise FileNotFoundError(f"Missing required: {item}")
def build_zip():
if BUILD_DIR.exists():
shutil.rmtree(BUILD_DIR)
BUILD_DIR.mkdir(parents=True)
with zipfile.ZipFile(ZIP_PATH, "w", zipfile.ZIP_DEFLATED) as z:
for path in REQUIRED:
full = ROOT / path
if full.is_file():
z.write(full, arcname=full.name)
else:
for file in full.rglob("*"):
if file.is_file():
z.write(file, arcname=file.relative_to(ROOT))
def install():
dest = get_mc_resourcepacks_path()
dest.mkdir(parents=True, exist_ok=True)
target = dest / OUTPUT_NAME
shutil.copy2(ZIP_PATH, target)
print(f"Installed to: {target}")
def main():
validate()
build_zip()
install()
print("Build + install complete")
if __name__ == "__main__":
main()