Skip to content

Commit

Permalink
Dynamically customize metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
Motschen committed Dec 26, 2024
1 parent 5e7137f commit 8c9896b
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 7 deletions.
Binary file not shown.
18 changes: 14 additions & 4 deletions gen_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,14 @@ def generateCarpetAssets(carpet):
with open(block_model_file, "w") as f:
json.dump(block_model_data, f, indent=4)

def writeMetadata(args):
edition = args.edition
if isinstance(edition, list): edition = " ".join(args.edition)
with open("./input/pack.mcmeta") as infile, open("pack.mcmeta", "w") as outfile:
for line in infile:
line = line.replace("${version}", args.version).replace("${edition}", edition)
outfile.write(line)

# See https://stackoverflow.com/a/1855118
def zipdir(path, ziph):
# ziph is zipfile handle
Expand All @@ -366,8 +374,8 @@ def zipdir(path, ziph):
os.path.join(path, '..')))

# Creates a compressed zip file
def makeZip(version):
with zipfile.ZipFile('Better-Leaves-Lite-'+version+".zip", 'w', zipfile.ZIP_DEFLATED) as zipf:
def makeZip(filename):
with zipfile.ZipFile(filename, 'w', zipfile.ZIP_DEFLATED) as zipf:
zipdir('assets/', zipf)
zipf.write('pack.mcmeta')
zipf.write('pack.png')
Expand All @@ -383,7 +391,8 @@ def makeZip(version):
epilog='Feel free to ask for help at http://discord.midnightdust.eu/')

parser.add_argument('version', type=str)
parser.add_argument('--legacy', '-l', action='store_true')
parser.add_argument('edition', nargs="*", type=str, default="§cCustom Edition", help="Define your edition name")
parser.add_argument('--legacy', '-l', action='store_true', help="Use legacy models (from 8.1) for all leaves")
args = parser.parse_args()

print(f"Arguments: {args}")
Expand All @@ -398,9 +407,10 @@ def makeZip(version):
f.close()

autoGen(data, args);
writeMetadata(args)
print()
print("Zipping it up...")
makeZip(args.version);
makeZip(f"Better-Leaves-{args.version}.zip");
print("Done!")
print("--- Finished in %s seconds ---" % (round((time.perf_counter() - start_time)*1000)/1000))

7 changes: 7 additions & 0 deletions input/pack.mcmeta
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"pack": {
"pack_format": 15,
"supported_formats": [15, 99],
"description": "§2Version ${version} §a${edition}\n§e©Motschen 2024 | MIT Licence"
}
}
1 change: 0 additions & 1 deletion leaves.bbmodel

This file was deleted.

4 changes: 2 additions & 2 deletions pack.mcmeta
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"pack": {
"pack_format": 15,
"supported_formats": [15, 99],
"description": "§2Version 0.1 §aby Motschen §e©Motschen 2024 | MIT Licence"
"description": "§2Version 9.0 §aVanilla Edition\n§e©Motschen 2024 | MIT Licence"
}
}
}
Binary file modified pack.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8c9896b

Please sign in to comment.