MC/tools/build-network-artwork-pack.py
2026-11-27 23:43:05 +00:00

39 lines
2.4 KiB
Python

"""Two lobby layers: this static artwork bundle plus native MC GUI's renderer pack.
Only Arrakis' GOLD rabbit and SNOWY worm-pet carrier are retextured. Other
worlds' normal rabbits and wolves retain their vanilla appearance.
"""
import hashlib,json,pathlib,sys,zipfile
def build(gui,items,creatures,output,sand=None):
entries={}
for path in (gui,items):
with zipfile.ZipFile(path) as pack:
for name in pack.namelist():
if name!='pack.mcmeta' and not name.endswith('/'):
assert not name.startswith('/') and '..' not in pathlib.PurePosixPath(name).parts
entries[name]=pack.read(name)
with zipfile.ZipFile(gui) as pack:metadata=json.loads(pack.read('pack.mcmeta'))
metadata['pack'].update(pack_format=64,supported_formats=[64,97],min_format=64,max_format=97,description='DuneRealms network artwork · Spacing Guild lobby')
entries['pack.mcmeta']=json.dumps(metadata).encode()
with zipfile.ZipFile(creatures) as pack:
for name in (
'entity/rabbit/gold.png','entity/rabbit/rabbit_gold.png','entity/rabbit/rabbit_gold_baby.png',
'entity/wolf/wolf_snowy.png','entity/wolf/wolf_snowy_tame.png','entity/wolf/wolf_snowy_angry.png',
'entity/camel/camel.png','entity/camel/camel_baby.png'):
key='assets/minecraft/textures/'+name;entries[key]=pack.read(key)
if sand is not None:
names=('sand','red_sand','suspicious_sand_0','suspicious_sand_1','suspicious_sand_2','suspicious_sand_3')
with zipfile.ZipFile(sand) as pack:
for name in names:
for suffix in ('','_n','_s'):
key='assets/minecraft/textures/block/'+name+suffix+'.png';entries[key]=pack.read(key)
for key in ('LICENSE-Sand-Luanti.txt','CREDITS-Sand.txt'):entries[key]=pack.read(key)
output.parent.mkdir(parents=True,exist_ok=True)
with zipfile.ZipFile(output,'w',zipfile.ZIP_DEFLATED) as pack:
for key,data in sorted(entries.items()):
info=zipfile.ZipInfo(key,(2026,11,23,0,0,0));info.compress_type=zipfile.ZIP_DEFLATED;pack.writestr(info,data)
data=output.read_bytes()
return {'sha1':hashlib.sha1(data).hexdigest(),'sha256':hashlib.sha256(data).hexdigest(),'bytes':len(data),'entries':len(entries)}
if __name__=='__main__':print(json.dumps(build(*(pathlib.Path(p) for p in sys.argv[1:]))))