plugins/tools/plugin_sigma_heat.py
unimatrixgit f7af3271aa
Some checks failed
Sigma Heat Radius Build / sigma-heat-radius (push) Successful in 1m18s
DuneRealms Plugin CI / plugins (push) Successful in 9m2s
DuneRealms Resourcepack CI / resourcepack (push) Failing after 19s
Melt snow and ice around heat sources on Sigma
2026-12-06 08:13:10 +01:00

49 lines
2.1 KiB
Python

"""Extract and apply the reviewed Sigma heat classes to retained Terrain."""
import argparse
from hashlib import sha256
from pathlib import Path
from zipfile import ZipFile
BASELINE = "3995f59d7ff3c5306332dc9a31049fd8d79dcc488d09fd88e4e464c91834d707"
PACKAGE = "com/example/duneterrain/"
SOIL = PACKAGE + "PlanetSoil.class"
ENTRIES = (SOIL, PACKAGE + "SigmaHeat.class", PACKAGE + "SigmaHeat$Point.class", PACKAGE + "SigmaHeat$ChunkPosition.class")
def extract(compiled, output):
with ZipFile(compiled) as jar, ZipFile(output, "x") as patch:
for name in ENTRIES:
patch.writestr(name, jar.read(name))
def assemble(baseline, patch, output):
if sha256(baseline.read_bytes()).hexdigest() != BASELINE:
raise ValueError("Expected the retained goat-enabled Sigma Terrain")
with ZipFile(baseline) as original, ZipFile(patch) as updates:
entries = original.namelist()
if len(set(entries)) != len(entries) or updates.namelist() != list(ENTRIES):
raise ValueError("Unexpected archive entries")
if SOIL not in entries or any(name in entries for name in ENTRIES[1:]):
raise ValueError("Unexpected class baseline")
updated = {name: updates.read(name) for name in ENTRIES}
if updated[SOIL] == original.read(SOIL) or any(
not data.startswith(bytes.fromhex("cafebabe")) for data in updated.values()
):
raise ValueError("Invalid or unchanged heat patch")
with ZipFile(output, "x") as candidate:
for info in original.infolist():
candidate.writestr(info, updated[SOIL] if info.filename == SOIL else original.read(info))
for name in ENTRIES[1:]:
candidate.writestr(name, updated[name])
if __name__ == "__main__":
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("input", type=Path)
parser.add_argument("output", type=Path)
parser.add_argument("--baseline", type=Path)
args = parser.parse_args()
if args.baseline is None:
extract(args.input, args.output)
else:
assemble(args.baseline, args.input, args.output)