-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathrecipeReplacer.py
47 lines (39 loc) · 1.39 KB
/
recipeReplacer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/python3
""" Recipe Replacer for Minecraft 1.20.5
Created at Apr 30, 2024 by lonefelidae16 <kow161206@gmail.com>
Usage:
> recipeReplacer.py [--help | -h] [--test | -t] /path/to/target/recipe.json
"""
import json
import sys
import argparse
parser = argparse.ArgumentParser(
prog='RecipeReplacer',
description='Make recipe.json compatible with MC1.20.5')
parser.add_argument('filename')
parser.add_argument('-t', '--test', action='store_true', help='show result JSON to STDOUT, no changes to the specified file')
args = parser.parse_args()
if __name__ == '__main__':
struct = {}
replaced = False
with open(args.filename, 'r') as target_file:
struct = json.load(target_file)
if not 'result' in struct:
exit()
if 'item' in struct['result']:
struct['result']['id'] = struct['result']['item']
del struct['result']['item']
replaced = True
elif type(struct['result']) is str:
_result = struct['result']
struct['result'] = {}
struct['result']['id'] = _result
replaced = True
if replaced:
if args.test:
print(json.dumps(struct, indent=2))
else:
with open(args.filename, 'w') as target_file:
json.dump(struct, target_file, indent=2)
else:
print(args.filename + ": no changes made")