diff --git a/build/scripts/publish_resourcepack_release.py b/build/scripts/publish_resourcepack_release.py index 3855c57..f96c08d 100644 --- a/build/scripts/publish_resourcepack_release.py +++ b/build/scripts/publish_resourcepack_release.py @@ -19,16 +19,29 @@ def log(message: str) -> None: print(message, file=sys.stderr, flush=True) +def add_payload_file(archive: zipfile.ZipFile, source_file: Path, relative_path: Path) -> None: + if source_file.exists() and source_file.is_file(): + archive.write(source_file, relative_path.as_posix()) + + def zip_resourcepack(resourcepack_root: Path, archive_path: Path) -> None: archive_path.parent.mkdir(parents=True, exist_ok=True) with zipfile.ZipFile(archive_path, mode="w", compression=zipfile.ZIP_DEFLATED) as archive: - for source_file in sorted(resourcepack_root.rglob("*")): - if source_file.is_dir(): + add_payload_file(archive, resourcepack_root / "pack.mcmeta", Path("pack.mcmeta")) + add_payload_file(archive, resourcepack_root / "pack.png", Path("pack.png")) + + for directory_name in ("assets", "data"): + directory = resourcepack_root / directory_name + if not directory.is_dir(): continue - relative_path = source_file.relative_to(resourcepack_root).as_posix() - archive.write(source_file, relative_path) + for source_file in sorted(directory.rglob("*")): + if source_file.is_dir(): + continue + + relative_path = source_file.relative_to(resourcepack_root) + archive.write(source_file, relative_path.as_posix()) def request_json(request: urllib.request.Request) -> dict[str, object]: