plugins/tools/build-resourcepack-repair.py
2026-11-27 23:43:05 +00:00

118 lines
5.8 KiB
Python

"""Build the Java 26.3 resourcepack repair from the exact published artwork.
No artwork is resampled or regenerated. New immutable URLs are mandatory.
"""
import argparse
import hashlib
import json
import pathlib
import re
import zipfile
ROOT = pathlib.Path(__file__).resolve().parents[1]
OLD_PLANETS = ROOT / 'DuneRealmsGUI/planet-artwork/release-v2'
OLD_NETWORK = '15dfd24bbb1760e04a1df1e0556c15b759353be705fbf2bcc9b377704abcf560'
OLD_ARRAKIS = '4a906b4e292221997d7870d63d70303d37d7cd41d872cba6bb7c2a170bd88adc'
BASE_ID = 'a7b5ab7d-d8d8-5b51-b016-71a5f4c00008'
PLANET_ID = '59f34b30-6a86-5e58-a813-6e776f726c64'
PREFIX = 'https://www.dunerealms.com/downloads/'
FAUNA = ('jerboa', 'jerboa_walk_left', 'jerboa_walk_right', 'jerboa_curled', 'tiny_worm')
SPRITE = 'dunerealms:entity/jerboa'
SAND = re.compile(r'^assets/minecraft/textures/block/(?:red_sand|sand|suspicious_sand_[0-3])(?:_[ns])?\.png$')
def digest(data, algorithm='sha256'):
return hashlib.new(algorithm, data).hexdigest()
def read_pack(path, expected):
data = path.read_bytes()
if digest(data) != expected:
raise ValueError(f'Unexpected baseline SHA256: {path.name}')
with zipfile.ZipFile(path) as pack:
entries = {}
for name in pack.namelist():
if name.endswith('/'):
continue
if name in entries or name.startswith('/') or '..' in pathlib.PurePosixPath(name).parts:
raise ValueError(f'Unsafe or duplicate entry: {name}')
entries[name] = pack.read(name)
return entries
def encode(value):
return (json.dumps(value, separators=(',', ':'), ensure_ascii=True) + '\n').encode()
def compatibility(entries, description=None):
result = dict(entries)
meta = json.loads(result['pack.mcmeta'])
meta['pack'].update(pack_format=64, supported_formats={'min_inclusive':64, 'max_inclusive':97},
min_format=64, max_format=[97,1])
if description: meta['pack']['description'] = description
result['pack.mcmeta'] = encode(meta)
return result
def world_artwork(entries):
# Planet-specific native sand/mob overrides belong to the lobby/material layer,
# not the shared item/font/GUI pack; keep the reserved dried-kelp spice carrier.
return compatibility({name:data for name,data in entries.items()
if not SAND.match(name) and not name.startswith('assets/minecraft/textures/entity/')},
'DuneRealms network artwork')
def arrange_fauna(entries):
result = compatibility(entries)
assert result['assets/dunerealms/textures/entity/jerboa.png'].startswith(b'\x89PNG')
for name in FAUNA:
key = f'assets/dunerealms/models/entity/{name}.json'
model = json.loads(result[key])
model['textures']['particle'] = '#body' if name == 'tiny_worm' else '#fur'
result[key] = encode(model)
# 26.3 separates item and block atlases. JSON display models using entity/
# sprites must explicitly include the sprite in either render context.
for atlas in ('blocks','items'):
key = f'assets/minecraft/atlases/{atlas}.json'
spec = json.loads(result.get(key, b'{"sources":[]}'))
source = {'type':'minecraft:single','resource':SPRITE,'sprite':SPRITE}
if source not in spec['sources']: spec['sources'].append(source)
result[key] = encode(spec)
return result
def write_pack(output, filename, entries):
path = output / filename
# PNGs are already compressed. Store entries so pin bytes are independent
# of differences between Windows and Linux zlib builds.
with zipfile.ZipFile(path, 'w', compression=zipfile.ZIP_STORED) as pack:
for name,data in sorted(entries.items()):
info = zipfile.ZipInfo(name, (2026,11,25,0,0,0))
info.compress_type = zipfile.ZIP_STORED
info.create_system = 0
pack.writestr(info, data)
data = path.read_bytes()
return {'filename':filename,'url':PREFIX+filename,'sha1':digest(data,'sha1'),
'sha256':digest(data),'bytes':len(data),'entries':len(entries)}
def build(network, arrakis, output):
output.mkdir(parents=True, exist_ok=True)
base = read_pack(network, OLD_NETWORK)
old = json.loads((OLD_PLANETS/'manifest.json').read_text())
manifest = {'resourcePackVersion':[97,1], 'baseId':BASE_ID, 'planetId':PLANET_ID,
'baseline':{'networkSha256':OLD_NETWORK,'arrakisSha256':OLD_ARRAKIS},
'base':{},'planets':{}}
manifest['base']['world'] = write_pack(output,'DuneRealms-Network-Artwork-v4.zip',world_artwork(base))
manifest['base']['lobby'] = write_pack(output,'DuneRealms-Network-Artwork-Lobby-v4.zip',
compatibility(base,'DuneRealms network artwork · Spacing Guild lobby'))
for key,record in old['packs'].items():
if key == 'arrakis':
data = arrange_fauna(read_pack(arrakis, OLD_ARRAKIS)); version=5
previous = {'url':PREFIX+'DuneRealms-Materials-arrakis-v4.zip','sha1':'694cad97caf75ac00f4e6f819a7172a0cf1b83ef'}
else:
data = compatibility(read_pack(OLD_PLANETS/record['filename'],record['sha256']));version=3
previous = {'url':record['url'],'sha1':record['sha1']}
manifest['planets'][key] = {**write_pack(output,f'DuneRealms-Materials-{key}-v{version}.zip',data),
'name':record['name'],'aliases':record['aliases'],'previous':previous}
(output/'manifest.json').write_text(json.dumps(manifest,indent=2)+'\n', encoding='utf-8',newline='\n')
return manifest
if __name__ == '__main__':
parser=argparse.ArgumentParser(description=__doc__)
parser.add_argument('network',type=pathlib.Path)
parser.add_argument('arrakis',type=pathlib.Path)
parser.add_argument('output',type=pathlib.Path)
args=parser.parse_args()
print(json.dumps(build(args.network,args.arrakis,args.output),indent=2))