Files
cobblemon-survival-pack/tools/build.py
T
claudeandClaude Opus 5.5 0741c84077 Phase 9: Iris and Complementary Reimagined, off by default
Adrian, 2026-11-09: set up the shader but keep it disabled by default. Iris
1.8.14-beta.1 (built for the pack's Sodium 0.8.13) and Complementary Reimagined
r5.9.3, both client only and fetched from Modrinth. Default Options' extra
folder ships config/iris.properties with shaders off and Complementary
preselected, copied only when a player has none. Toggle Shaders is on M, the
only free letter; Iris's other keys are unbound. tools/build.py fails if the
settings name a shader file the pack doesn't install.

Smoke test passes; client dependencies are satisfied. Not launched on a client.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 13:08:14 +01:00

143 lines
5.3 KiB
Python

#!/usr/bin/env python3
"""Build the companion mod and export the pack.
Outputs, all under build/:
stage/full/ every mod plus the companion jar; the Prism
instance and the server smoke test install this
<slug>-<ver>.mrpack Modrinth pack
<slug>-<ver>-curseforge.zip CurseForge pack
Each platform export only lists mods that platform hosts. A mod hosted on just
one platform is left out of the other export and reported; it is never copied
into overrides/, because the pack must not bundle third-party jars. The
companion mod is our own work, so it is the one jar allowed in overrides/.
Usage: tools/build.py [--skip-mod]
"""
import argparse
import os
import shutil
import subprocess
import sys
import tomllib
import zipfile
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
PACK = ROOT / "pack"
BUILD = ROOT / "build"
MODRINTH_HOSTS = ("https://cdn.modrinth.com/", "https://github.com/",
"https://raw.githubusercontent.com/", "https://gitlab.com/")
def run(cmd, cwd):
print(f"$ {' '.join(map(str, cmd))} (in {cwd.relative_to(ROOT) if cwd.is_relative_to(ROOT) else cwd})")
subprocess.run(cmd, cwd=cwd, check=True)
def packwiz(*args, cwd):
run([shutil.which("packwiz") or "packwiz", *args, "-y"], cwd)
def java_home():
"""Gradle 8.14 cannot run on Java 25, so prefer an explicit Java 21."""
for candidate in (os.environ.get("JAVA21_HOME"), os.environ.get("JAVA_HOME"),
Path.home() / ".var/app/org.prismlauncher.PrismLauncher/data/PrismLauncher/java/java-runtime-delta"):
if candidate and (Path(candidate) / "bin" / "java").exists():
return str(candidate)
return None
def build_mod():
env = dict(os.environ)
if home := java_home():
env["JAVA_HOME"] = home
subprocess.run(["./gradlew", "build", "--console=plain"], cwd=ROOT / "mod", env=env, check=True)
def companion_jar():
props = dict(line.split("=", 1) for line in (ROOT / "mod/gradle.properties").read_text().splitlines()
if "=" in line and not line.startswith("#"))
jar = ROOT / "mod/build/libs" / f"{props['mod_id']}-{props['mod_version']}.jar"
if not jar.exists():
sys.exit(f"companion jar not found: {jar} (run without --skip-mod)")
return jar
def platforms_of(meta):
hosts = set()
if "curseforge" in meta.get("update", {}):
hosts.add("curseforge")
if meta.get("download", {}).get("url", "").startswith(MODRINTH_HOSTS):
hosts.add("modrinth")
return hosts
def stage(name, jar, platform=None):
dest = BUILD / "stage" / name
shutil.rmtree(dest, ignore_errors=True)
shutil.copytree(PACK, dest)
left_out = []
if platform:
for path in sorted((dest / "mods").glob("*.pw.toml")):
meta = tomllib.loads(path.read_text())
if platform not in platforms_of(meta):
left_out.append(meta["name"])
path.unlink()
shutil.copy2(jar, dest / "mods" / jar.name)
packwiz("refresh", cwd=dest)
return dest, left_out
def check_overrides(archive, jar):
bundled = [n for n in zipfile.ZipFile(archive).namelist()
if n.endswith(".jar") and Path(n).name != jar.name]
if bundled:
sys.exit(f"{archive.name} would bundle third-party jars: {bundled}")
def check_default_shader():
"""The shader pack named in the default Iris settings is the file the pack installs."""
settings = (PACK / "config/defaultoptions/extra/config/iris.properties").read_text()
named = next(line.split("=", 1)[1] for line in settings.splitlines() if line.startswith("shaderPack="))
files = [tomllib.loads(p.read_text())["filename"] for p in (PACK / "shaderpacks").glob("*.pw.toml")]
if named not in files:
sys.exit(f"config/defaultoptions/extra/config/iris.properties names {named}, the pack has {files}")
def main():
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument("--skip-mod", action="store_true", help="reuse the last companion mod build")
args = parser.parse_args()
if not args.skip_mod:
build_mod()
jar = companion_jar()
check_default_shader()
run([sys.executable, str(ROOT / "tools/quests.py")], ROOT) # the quest book (Phase 8) from docs/quests.yaml
packwiz("refresh", cwd=PACK)
pack = tomllib.loads((PACK / "pack.toml").read_text())
base = f"{pack['name'].lower().replace(' ', '-')}-{pack['version']}"
stage("full", jar)
report = {}
for platform, suffix, command in (("modrinth", ".mrpack", "modrinth"),
("curseforge", "-curseforge.zip", "curseforge")):
dest, left_out = stage(platform, jar, platform)
out = BUILD / f"{base}{suffix}"
out.unlink(missing_ok=True)
packwiz(command, "export", "-o", str(out), cwd=dest)
check_overrides(out, jar)
report[out.name] = left_out
print("\nExports (no third-party jars in overrides):")
for name, left_out in report.items():
print(f" build/{name}")
for mod in left_out:
print(f" left out, not hosted on this platform: {mod}")
print(" build/stage/full/pack.toml (all mods; used by Prism sync and the smoke test)")
if __name__ == "__main__":
main()