Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import argparse
- import code # for code.interact(local=dict(globals(), **locals()) ) debugging
- import glob
- import json
- import os
- import re
- import shutil
- import tempfile
- from typing import Dict, List, Tuple # for mypy
- ######################
- # programname
- #
- # What the program is for
- def main():
- cfg = handle_args()
- orig_metadata = jload(os.path.join(cfg.src, 'manifest.json'))
- with tempfile.TemporaryDirectory() as td:
- # In this context manager, we made a directory into which we'll place everything before we zip it
- shutil.copy(src=os.path.join(cfg.src, 'pack_icon.png'), dst=(os.path.join(td, 'pack.png')))
- with open(os.path.join(td, 'pack.mcmeta'), 'w') as mcmf:
- data = {
- "pack": {
- "pack_format": cfg.pack_ver,
- "description": orig_metadata['header']['description']
- }
- }
- json.dump(data, mcmf)
- os.makedirs(os.path.join(td, 'assets', 'minecraft', 'textures', 'block'))
- for btfile in os.listdir(os.path.join(cfg.src, 'textures', 'blocks')):
- if '_mer' in btfile:
- continue
- if 'texture_set' in btfile:
- continue
- if not os.path.isfile(os.path.join(cfg.src, 'textures', 'blocks', btfile)):
- continue # Embedded dir?
- print(f"Processing texture {btfile}")
- targfn = btfile
- # TODO add more specific rules for remapping names here.
- if btfile.startswith('wool_colored_'):
- targfn = re.sub('wool_colored_(.*).png', '\\1_wool.png', btfile)
- # We may also bail for textures that are too different in format (e.g. lava flow), or figure out how to convert them
- shutil.copy(src=os.path.join(cfg.src, 'textures', 'blocks', btfile), dst=os.path.join(td, 'assets', 'minecraft', 'textures', 'block', targfn))
- shutil.make_archive(f"{orig_metadata['header']['name']}-{orig_metadata['header']['version'][0]}.{orig_metadata['header']['version'][1]}.{orig_metadata['header']['version'][2]}", 'zip', td)
- def handle_args():
- parser = argparse.ArgumentParser(description="This does a thing")
- parser.add_argument("--src", default='dlight', type=str, help="source dir for bedrock pack")
- parser.add_argument("--pack_ver", default=6, type=int, help="Pack version")
- ret = parser.parse_args()
- return ret
- #####
- def jload(fn:str):
- with open(fn, 'r') as fh:
- ret = json.load(fh)
- return ret
- #####
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement