-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathwrap_conditional.py
More file actions
51 lines (43 loc) · 1.39 KB
/
wrap_conditional.py
File metadata and controls
51 lines (43 loc) · 1.39 KB
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
import os
import json
# Set your folder path here
RECIPES_DIR = "D:/Minecraft Mods/Overgeared New instance/src/main/resources/data/slavicarmory/recipes"
MOD_ID = "slavicarmory"
def wrap_with_forge_conditional(recipe_json):
return {
"type": "forge:conditional",
"recipes": [
{
"conditions": [
{
"type": "forge:mod_loaded",
"modid": MOD_ID
}
],
"recipe": recipe_json
}
]
}
def process_recipe_file(file_path):
with open(file_path, 'r', encoding='utf-8') as f:
try:
original = json.load(f)
except json.JSONDecodeError:
print(f"Skipping invalid JSON: {file_path}")
return
# Skip if already conditional
if original.get("type") == "forge:conditional":
print(f"Already conditional: {file_path}")
return
# Wrap and overwrite
wrapped = wrap_with_forge_conditional(original)
with open(file_path, 'w', encoding='utf-8') as f:
json.dump(wrapped, f, indent=2)
print(f"Wrapped: {file_path}")
def process_folder(folder):
for root, _, files in os.walk(folder):
for file in files:
if file.endswith(".json"):
process_recipe_file(os.path.join(root, file))
# Run it
process_folder(RECIPES_DIR)