This repository has been archived by the owner on Mar 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen.py
executable file
·160 lines (127 loc) · 4.36 KB
/
gen.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
This script generates the Garden Cloche recipes for Thermal Cultivation.
It takes the thermal_cultivation-1.18.2-*.jar file as an argument.
Usage: gen.py <path to thermal_cultivation-1.18.2-*.jar> <output folder>
"""
import sys
import os
import json
import zipfile
def main():
# Check if the number of arguments is correct
if len(sys.argv) != 3:
print(
"Usage: gen.py",
"<path to thermal_cultivation-1.18.2-*.jar>",
"<output folder>",
sep=" ",
)
sys.exit(1)
# Path to the thermal_cultivation-1.18.2-*.jar file
path = sys.argv[1]
# Check if the file exists
if not os.path.isfile(path):
print("File does not exist")
sys.exit(1)
# Check if the file is a jar file
if not path.endswith(".jar"):
print("File is not a jar file")
sys.exit(1)
# Check if the file has the correct name
if not os.path.basename(path).startswith("thermal_cultivation-1.18.2-"):
print("File has the wrong name")
sys.exit(1)
# Output folder path
output_folder = sys.argv[2]
# Check if the output folder exists
if not os.path.isdir(output_folder):
print("Output folder does not exist")
sys.exit(1)
# Check if the output folder is empty
if os.listdir(output_folder):
print("Warning: Output folder is not empty")
input("Press Enter to continue...")
# Open the jar file as a zip file
jar = zipfile.ZipFile(path, "r")
# Read the files starting with "data/thermal/recipes/machines/insolator/"
files = jar.namelist()
files = [
file
for file in files
if file.startswith("data/thermal/recipes/machines/insolator/")
and file.endswith(".json")
]
# Iterate over the files
for file in files:
# Read the file
data: dict = json.loads(jar.read(file).decode("utf-8"))
# Get the name of the item
item_id: str = data.get("ingredient").get("item")
# Create the output file name
output_file_name: str = item_id.split(":")[1] + ".json"
# Create the output file path
output_path: str = os.path.join(output_folder, output_file_name)
# Get the time modifier
time_modifier: float = data.get("energy_mod", 1.0)
# Get the results list and reform it
results: list[dict] = []
for result in data.get("result", []):
results.append(
{
"item": result.get("item"),
"count": int(result.get("chance", 1)),
}
)
# Create the base output data
output_data: dict = {
"type": "immersiveengineering:cloche",
"results": results,
"input": {
"item": item_id,
},
"soil": [
{
"item": "minecraft:dirt",
}
],
"time": 800 * time_modifier,
"render": {
"type": "crop",
},
}
if item_id == "thermal:frost_melon_seeds":
# Update the render type
output_data["render"]["type"] = "stem"
# Get the stem block
stem_block: str = item_id.split("_seeds")[0]
# Update the render block
output_data["render"]["block"] = stem_block
elif item_id.endswith("_seeds"):
# Get the crop block
crop_block: str = item_id.split("_seeds")[0]
# Update the output data
output_data["render"]["block"] = crop_block
elif item_id.endswith("_spores"):
# Get the crop block
crop_block: str = item_id.split("_spores")[0]
# Update the output data
output_data["render"]["block"] = crop_block
# Change the soil list
output_data["soil"] = [
{
"item": "minecraft:mycelium",
},
{
"item": "minecraft:podzol",
},
]
# Write the output data to the output file
output_file = open(output_path, "w")
output_file.write(json.dumps(output_data, indent=4))
output_file.close()
# Close the jar file
jar.close()
if __name__ == "__main__":
main()