Skip to content

Commit 8c9896b

Browse files
committed
Dynamically customize metadata
1 parent 5e7137f commit 8c9896b

File tree

6 files changed

+23
-7
lines changed

6 files changed

+23
-7
lines changed
Binary file not shown.

gen_pack.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,14 @@ def generateCarpetAssets(carpet):
356356
with open(block_model_file, "w") as f:
357357
json.dump(block_model_data, f, indent=4)
358358

359+
def writeMetadata(args):
360+
edition = args.edition
361+
if isinstance(edition, list): edition = " ".join(args.edition)
362+
with open("./input/pack.mcmeta") as infile, open("pack.mcmeta", "w") as outfile:
363+
for line in infile:
364+
line = line.replace("${version}", args.version).replace("${edition}", edition)
365+
outfile.write(line)
366+
359367
# See https://stackoverflow.com/a/1855118
360368
def zipdir(path, ziph):
361369
# ziph is zipfile handle
@@ -366,8 +374,8 @@ def zipdir(path, ziph):
366374
os.path.join(path, '..')))
367375

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

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

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

400409
autoGen(data, args);
410+
writeMetadata(args)
401411
print()
402412
print("Zipping it up...")
403-
makeZip(args.version);
413+
makeZip(f"Better-Leaves-{args.version}.zip");
404414
print("Done!")
405415
print("--- Finished in %s seconds ---" % (round((time.perf_counter() - start_time)*1000)/1000))
406416

input/pack.mcmeta

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"pack": {
3+
"pack_format": 15,
4+
"supported_formats": [15, 99],
5+
"description": "§2Version ${version} §a${edition}\n§e©Motschen 2024 | MIT Licence"
6+
}
7+
}

leaves.bbmodel

Lines changed: 0 additions & 1 deletion
This file was deleted.

pack.mcmeta

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"pack": {
33
"pack_format": 15,
44
"supported_formats": [15, 99],
5-
"description": "§2Version 0.1 §aby Motschen §e©Motschen 2024 | MIT Licence"
5+
"description": "§2Version 9.0 §aVanilla Edition\n§e©Motschen 2024 | MIT Licence"
66
}
7-
}
7+
}

pack.png

12.6 KB
Loading

0 commit comments

Comments
 (0)