-
Notifications
You must be signed in to change notification settings - Fork 0
/
lootfix.py
76 lines (66 loc) · 3.39 KB
/
lootfix.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import argparse
import json
import os
def edit_json_files(folder_path):
for subdir, dirs, files in os.walk(folder_path):
for file in files:
file_path = os.path.join(subdir, file)
if file_path.endswith('.json'):
print(f"Processing file: {file_path}")
with open(file_path, 'r+') as json_file:
data = json.load(json_file)
for pool in data.get("pools", []):
try:
try:
if pool['rools']['min'] == pool['rools']['max'] == 1:
pass
else:
if pool['rools']['min'] > 1:
pool['rools']['min'] = int(pool['rools']['min'] // 2)
if pool['rools']['max'] > 1:
pool['rools']['max'] = int(pool['rools']['max'] // 2)
except:
if pool['rools'] > 1:
pool['rools'] = int(pool['rools'] // 2)
except:
print("no rools found")
for entry in pool['entries']:
if entry['type'] == "empty":
entry['weight'] = entry['weight'] * 4
else:
try:
if entry['weight'] > 1:
entry['weight'] = entry['weight'] // 2
except:
print("no weight found")
try:
for func in entry["functions"]:
try:
if func["count"]['min'] == func["count"]['max'] == 1:
pass
else:
if func["count"]['min'] > 1:
func["count"]['min'] = 0.0
if func["count"]['max'] > 1:
if func["count"]['max'] // 4 == 0:
func["count"]['max'] = float(func["count"]['max'] // 2)
else:
func["count"]['max'] = float(func["count"]['max'] // 4)
except:
if func["count"] > 1:
func["count"] = int(func["count"] // 2)
except:
print("no count found")
# Save the modified JSON back to the file
with open(file_path, 'w+') as json_file:
json.dump(data, json_file, indent=2)
def main():
parser = argparse.ArgumentParser(description='Edit JSON files in loot tables.')
parser.add_argument('-f', '--folder', required=True, help='Root folder containing JSON files.')
args = parser.parse_args()
root_folder = args.folder
paths = ["data\\pixelmon\\loot_tables", "data\\minecraft\\loot_tables"]
for path in paths:
edit_json_files(os.path.join(root_folder, path))
if __name__ == "__main__":
main()