plugins/tools/plugin_elytra_anvil.py
unimatrixgit c470f2e983
Some checks failed
Elytra Anvil Overlay / elytra-anvil (push) Successful in 2m28s
DuneRealms Plugin CI / plugins (push) Has been cancelled
DuneRealms Resourcepack CI / resourcepack (push) Failing after 54s
Reject stale armor and wings at anvil pickup
2026-12-05 01:42:12 +01:00

60 lines
2.5 KiB
Python

"""Build the native anvil merge overlay on the two retained planetary JARVIS variants."""
import argparse
import os
from pathlib import Path
import subprocess
from tempfile import TemporaryDirectory
from plugin_wild_update import digest, read_archive, write_archive
PKG = "com/dunerealms/jarvis/"
CHANGED = ("JarvisTranslator", "ExchangeInventory", "QuestObservations")
ADDED = ("ExchangeInventory$MergedFlight", "ElytraAnvil", "ElytraAnvil$Preview", "ElytraMerge", "ElytraMerge$1")
BASELINES = {
"535f4c6d60a9486358dfb70b6982ba2db52249ca439170ba458b8d8d1befbad1",
"faf1124cb818f37c76dc90b1e8b112a4da422a35b7d117169cff87b301aa2891",
}
def entry(name):
return PKG + name + ".class"
def assemble(baseline, donor, donor_sha, output, classpath):
existing = baseline.read_bytes()
compiled = donor.read_bytes()
if digest(existing) not in BASELINES or digest(compiled) != donor_sha:
raise ValueError("Unexpected baseline or donor checksum")
retained = read_archive(existing)
source = read_archive(compiled)
if any(entry(name) in retained for name in ADDED):
raise ValueError("Baseline already contains the anvil merge")
home = os.environ.get("JAVA_HOME")
executable = "java.exe" if os.name == "nt" else "java"
java = str(Path(home) / "bin" / executable) if home else executable
helper = Path(__file__).with_name("ElytraAnvilOverlay.java")
with TemporaryDirectory() as temporary:
root = Path(temporary)
old, new, merged = (root / name for name in ("retained", "donor", "merged"))
for directory in (old, new, merged):
directory.mkdir()
for name in CHANGED:
(old / (name + ".class")).write_bytes(retained[entry(name)])
(new / (name + ".class")).write_bytes(source[entry(name)])
subprocess.run([java, "--class-path", classpath, str(helper), str(old), str(new), str(merged)], check=True)
for name in CHANGED:
retained[entry(name)] = (merged / (name + ".class")).read_bytes()
for name in ADDED:
retained[entry(name)] = source[entry(name)]
with output.open("xb") as candidate:
candidate.write(write_archive(retained))
if __name__ == "__main__":
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("baseline", type=Path)
parser.add_argument("donor", type=Path)
parser.add_argument("donor_sha")
parser.add_argument("output", type=Path)
parser.add_argument("classpath", help="ASM core and tree JARs")
assemble(**vars(parser.parse_args()))