60 lines
2.7 KiB
Python
60 lines
2.7 KiB
Python
"""Build the Sigma-only cold pig class graft and two biome mob-list changes."""
|
|
import argparse
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import subprocess
|
|
from tempfile import TemporaryDirectory
|
|
|
|
from plugin_wild_update import digest, read_archive, write_archive
|
|
|
|
TERRAIN_SHA = "2c9d56d64253a8ee49d3411dc32e4da3885e2cd1bc35b00b64ca920f180c1eb5"
|
|
BIOME_SHA = "0116d155df34e6c9c0482c0f7e21404ea69ea1357819005acfdb110ab748b139"
|
|
ENTRY = "com/example/duneterrain/PlanetMobs.class"
|
|
|
|
|
|
def checked(path, sha):
|
|
source = path.read_bytes()
|
|
if digest(source) != sha:
|
|
raise ValueError(f"Unreviewed baseline or donor: {path.name}")
|
|
return read_archive(source)
|
|
|
|
|
|
def assemble(terrain, biomes, donor, donor_sha, terrain_output, biomes_output, classpath):
|
|
existing = checked(terrain, TERRAIN_SHA)
|
|
pack = checked(biomes, BIOME_SHA)
|
|
compiled = checked(donor, donor_sha)
|
|
for name in ("snowy_plains", "snowy_taiga"):
|
|
entry = f"data/minecraft/worldgen/biome/{name}.json"
|
|
data = json.loads(pack[entry])
|
|
spawners = data["spawners"]["creature"]
|
|
if any(spawner["type"] == "minecraft:pig" for spawner in spawners):
|
|
raise ValueError("Pig spawn already registered")
|
|
spawners.append({"type": "minecraft:pig", "weight": 4, "minCount": 2, "maxCount": 3})
|
|
pack[entry] = (json.dumps(data, ensure_ascii=False, indent=2) + "\n").encode()
|
|
java_home = os.environ.get("JAVA_HOME")
|
|
executable = "java.exe" if os.name == "nt" else "java"
|
|
java = str(Path(java_home) / "bin" / executable) if java_home else executable
|
|
with TemporaryDirectory() as temporary:
|
|
temp = Path(temporary)
|
|
old, new, merged = (temp / f"{name}.class" for name in ("retained", "donor", "merged"))
|
|
old.write_bytes(existing[ENTRY])
|
|
new.write_bytes(compiled[ENTRY])
|
|
helper = Path(__file__).with_name("SigmaColdPigMerge.java")
|
|
subprocess.run([java, "--class-path", classpath, str(helper), str(old), str(new), str(merged)], check=True)
|
|
existing[ENTRY] = merged.read_bytes()
|
|
for path, contents in ((terrain_output, existing), (biomes_output, pack)):
|
|
with path.open("xb") as result:
|
|
result.write(write_archive(contents))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("terrain", type=Path)
|
|
parser.add_argument("biomes", type=Path)
|
|
parser.add_argument("donor", type=Path)
|
|
parser.add_argument("donor_sha")
|
|
parser.add_argument("terrain_output", type=Path)
|
|
parser.add_argument("biomes_output", type=Path)
|
|
parser.add_argument("classpath", help="ASM core and tree JARs")
|
|
assemble(**vars(parser.parse_args()))
|

Staff