forked from Mrthomas20121-Mods/TFCompat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerateResources.py
435 lines (390 loc) · 13.2 KB
/
generateResources.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
"""
This file generates a whole list of resources for the TerraFirmaCraft mod.
Any resource files generated by this script should set a root JSON tag:
"__comment": "Generated by generateResources.py function: model"
This is a modified version from the original TFC repository to use in TFCompat.
"""
import json
import os
import time
import zipfile
def zipfolder(zip_name, target_dir):
zipobj = zipfile.ZipFile(zip_name, 'w', zipfile.ZIP_DEFLATED)
rootlen = len(target_dir) + 1
for base, dirs, files in os.walk(target_dir):
for file in files:
fn = os.path.join(base, file)
zipobj.write(fn, fn[rootlen:])
if not os.path.isdir('assets_backups'):
os.mkdir('assets_backups')
with open('assets_backups/.gitignore', 'w') as f:
print(
'# This folder does not belong on git. Not even as an empty folder, so we ignore everything, incl. this file.',
file=f)
print('*', file=f)
zipfolder('assets_backups/{}.zip'.format(int(time.time())), 'src/main/resources/assets/tfc')
os.chdir('src/main/resources/assets/tfc/')
# True - Generate Tools
# False - Generate only non tools (ingot, double ingot, sheet, etc..)
METAL_TYPES = {
'soulforged_steel':False,
'signalum':True,
'lumium':True,
'enderium':True,
'refined_obsidian':False,
'refined_glowstone':False,
'thaumium':True,
'void_metal':False,
}
OTHER_METAl_TYPE = {
'chromium':True,
'kanthal':False,
'solder':False,
'aluminium_steel':True,
'weak_aluminium_steel':False,
'bismuth_steel':True,
'weak_bismuth_steel':False,
'damascus_steel':True,
'weak_damascus_steel':False,
'stainless_steel':False,
'weak_stainless_steel':False,
'rose_alloy':False,
'ferrochrome':False,
'cadmium':False,
'nichrome':True,
'alnico':False,
'vanadium':False,
'rhodium':False,
'palladium':False,
'antimony': False,
'constantan': False,
'electrum': False,
'red_alloy': False,
'mithril': True,
'nickel_silver': True,
'invar': True,
'aluminium': True,
'aluminium_brass': False,
'ardite': False,
'cobalt': True,
'manyullyn': True,
'osmium': True,
'titanium': True,
'tungsten': True,
'tungsten_steel': True,
'boron': True,
'thorium': False,
'manganese': False,
'magnesium': False,
'lithium': False,
'zirconium': False,
'zircaloy': True,
'beryllium': False,
'beryllium_copper': True,
'hsla_steel': False,
'ferroboron': False,
'tough': False,
'magnesium_diboride': False,
'uranium': False,
'soulforged_steel':False,
'signalum':True,
'lumium':True,
'enderium':True,
'refined_obsidian':False,
'refined_glowstone':False,
'thaumium':True,
'void_metal':False,
'bismuth': False,
'bismuth_bronze': True,
'black_bronze': True,
'brass': False,
'bronze': True,
'copper': True,
'gold': False,
'lead': False,
'nickel': False,
'rose_gold': False,
'silver': False,
'tin': False,
'zinc': False,
'sterling_silver': False,
'wrought_iron': True,
'pig_iron': False,
'steel': True,
'platinum': False,
'black_steel': True,
'blue_steel': True,
'red_steel': True
}
METAL_ITEMS = {
# 'unshaped': False, Special
'ingot': False,
'double_ingot': False,
'scrap': False,
'dust': False,
'nugget': False,
'sheet': False,
'double_sheet': False,
'anvil': True,
'trapdoor': False,
'tuyere': True,
'lamp': False,
'pick': True,
'pick_head': True,
'shovel': True,
'shovel_head': True,
'axe': True,
'axe_head': True,
'hoe': True,
'hoe_head': True,
'chisel': True,
'chisel_head': True,
'sword': True,
'sword_blade': True,
'mace': True,
'mace_head': True,
'saw': True,
'saw_blade': True,
'javelin': True,
'javelin_head': True,
'hammer': True,
'hammer_head': True,
'propick': True,
'propick_head': True,
'knife': True,
'knife_blade': True,
'scythe': True,
'scythe_blade': True,
'shears': True,
'unfinished_chestplate': True,
'chestplate': True,
'unfinished_greaves': True,
'greaves': True,
'unfinished_boots': True,
'boots': True,
'unfinished_helmet': True,
'helmet': True,
}
RECIPE_ITEMS = {
'pick_head': 'pick',
'shovel_head': 'shovel',
'axe_head': 'axe',
'hoe_head': 'hoe',
'chisel_head': 'chisel',
'sword_blade': 'sword',
'mace_head': 'mace',
'saw_blade': 'saw',
'javelin_head': 'javelin',
'hammer_head': 'hammer',
'propick_head': 'propick',
'knife_blade': 'knife',
'scythe_blade': 'scythe',
}
TOOLS = [
'pick', 'propick', 'shovel', 'axe', 'hoe', 'chisel', 'sword', 'mace', 'saw', 'shears', 'javelin', 'hammer', 'knife',
'scythe'
]
def del_none(d):
"""
https://stackoverflow.com/a/4256027/4355781
Modifies input!
"""
for key, value in list(d.items()):
if value is None:
del d[key]
elif isinstance(value, dict):
del_none(value)
return d
def blockstate(filename_parts, model, textures, variants=None):
"""
Magic.
:param filename_parts: Iterable of strings.
:param model: String or None
:param textures: Dict of <string>:<string> OR <iterable of strings>:<string>
:param variants: Dict of <string>:<variant> OR "normal":None (to disable the normal default)
"""
_variants = {
'normal': [{}]
}
if variants:
_variants.update(variants)
# Unpack any tuple keys to simple string->string pairs
_textures = {}
for key, val in textures.items():
if isinstance(key, str):
_textures[key] = val
else:
for x in key:
_textures[x] = val
p = os.path.join('blockstates', *filename_parts) + '.json'
os.makedirs(os.path.dirname(p), exist_ok=True)
with open(p, 'w') as file:
json.dump(del_none({
'__comment': 'Generated by generateResources.py function: blockstate',
'forge_marker': 1,
'defaults': {
'model': model,
'textures': _textures,
},
'variants': _variants,
}), file, indent=2)
def cube_all(filename_parts, texture, variants=None, model='cube_all'):
blockstate(filename_parts, model, textures={'all': texture}, variants=variants)
def model(filename_parts, parent, textures):
p = os.path.join('models', *filename_parts) + '.json'
os.makedirs(os.path.dirname(p), exist_ok=True)
with open(p, 'w') as file:
json.dump(del_none({
'__comment': 'Generated by generateResources.py function: model',
'parent': parent,
'textures': textures,
}), file, indent=2)
def item(filename_parts, *layers, parent='item/generated'):
model(('item', *filename_parts), parent,
None if len(layers) == 0 else {'layer%d' % i: v for i, v in enumerate(layers)})
def itemHandHeld(filename_parts, *layers, parent='item/handheld'):
model(('item', *filename_parts), parent,
None if len(layers) == 0 else {'layer%d' % i: v for i, v in enumerate(layers)})
def tool_recipe(filename_parts, pattern, key, result):
p = os.path.join('recipes', *filename_parts) + '.json'
os.makedirs(os.path.dirname(p), exist_ok=True)
with open(p, 'w') as file:
json.dump(del_none({
'__comment': 'Generated by generateResources.py function: tool_recipe',
'type': 'tfc:shaped_skill',
'pattern': pattern,
'key': key,
'result': result,
}), file, indent=2)
def backpackStorageModel(filename_parts, metal) :
model(filename_parts, parent="item/generated", textures={
"layer0": "tfcompat:items/metal/backpack_base/%s" % metal,
"layer1": "tfcompat:items/metal/backpack_border/%s" % metal,
"layer2": "tfcompat:items/metal/backpack_latch_light/%s" % metal
})
def backpackUpgradeModel(filename_parts, metal) :
model(filename_parts, parent="item/generated", textures={
"layer0": "tfcompat:items/metal/backpack_base/%s" % metal,
"layer1": "tfcompat:items/metal/backpack_border/%s" % metal,
"layer2": "tfcompat:items/metal/backpack_latch_dark/%s" % metal
})
# ____ _ _ _ _
# | _ \| | | | | | | |
# | |_) | | ___ ___| | _____| |_ __ _| |_ ___ ___
# | _ <| |/ _ \ / __| |/ / __| __/ _` | __/ _ \/ __|
# | |_) | | (_) | (__| <\__ \ || (_| | || __/\__ \
# |____/|_|\___/ \___|_|\_\___/\__\__,_|\__\___||___/
#
# BLOCKSTATES
# METAL FLUIDS
for name in METAL_TYPES.keys():
blockstate(('fluid', name), 'forge:fluid', {}, {
'normal': {
'transform': "forge:default-item",
'custom': {
'fluid': name
}
}
})
# ANVILS
for key in METAL_TYPES:
if METAL_TYPES[key]:
blockstate(('anvil', key), 'tfc:anvil', textures={
('all', 'particle'): 'tfc:blocks/metal/%s' % key
}, variants={
'axis': {
'north': {'y': 180},
'east': {'y': 270},
'south': {},
'west': {'y': 90}
}
})
# LAMP
for key in METAL_TYPES:
blockstate(('lamp', key), 'tfc:lamp/up', textures={
('sheet', 'particle') : 'tfc:blocks/metal/%s' % key,
'lamp' : "tfc:blocks/lamp_unlit"
}, variants={
'lit': {
'true': {
"textures": {
'lamp': 'tfc:blocks/lamp_lit'
}
},
'false': {}
},
'facing': {'up': {}, 'down': {'model': "tfc:lamp/down"}}
})
# METAL SHEETS
for key in METAL_TYPES:
blockstate(('sheet', key), 'tfc:empty', textures={
('all', 'particle'): 'tfc:blocks/metal/%s' % key
}, variants={
'normal': None,
"north": {"true": {"submodel": {"north": {"model": "tfc:sheet", "x": 90}}}, "false": {}},
"south": {"true": {"submodel": {"south": {"model": "tfc:sheet", "y": 180, "x": 90}}}, "false": {}},
"east": {"true": {"submodel": {"east": {"model": "tfc:sheet", "y": 90, "x": 90}}}, "false": {}},
"west": {"true": {"submodel": {"west": {"model": "tfc:sheet", "y": 270, "x": 90}}}, "false": {}},
"up": {"true": {"submodel": {"up": {"model": "tfc:sheet"}}}, "false": {}},
"down": {"true": {"submodel": {"down": {"model": "tfc:sheet", "x": 180}}}, "false": {}}
})
# METALS
for item_type, tool_item in METAL_ITEMS.items():
for metal, tool_metal in METAL_TYPES.items():
if tool_item and not tool_metal:
continue
if item_type == 'anvil':
model(('item', 'metal', 'anvil', metal), 'tfc:item/metal/anvil/transformations',
{'all': 'tfc:blocks/metal/%s' % metal})
elif item_type == 'trapdoor':
model(('item', 'metal', 'trapdoor', metal), 'block/trapdoor_bottom',
{'texture': 'tfc:blocks/trapdoor/%s' % metal})
else:
parent = 'item/handheld' if item_type in TOOLS else 'item/generated'
if item_type in ['knife', 'javelin']:
parent = 'tfc:item/handheld_flipped'
item(('metal', item_type, metal), 'tfc:items/metal/%s/%s' % (item_type, metal),
parent=parent)
for metal, tool_metal in OTHER_METAl_TYPE.items() :
if tool_metal :
itemHandHeld(('%s_mallet' % metal), "firmalife:items/metal/mallet/%s" % metal)
item(('%s_mallet_head' % metal), "firmalife:items/metal/mallet_head/%s" % metal)
if metal == 'copper':
backpackStorageModel(('item', 'backpack', metal, 'none'), metal)
else :
backpackStorageModel(('item', 'backpack', metal, 'storage'), metal)
backpackUpgradeModel(('item', 'backpack', metal, 'upgrade'), metal)
# TOOLS RECIPES
for tool_head, tool in RECIPE_ITEMS.items():
for metal, tool_metal in METAL_TYPES.items():
if not tool_metal:
continue
tool_recipe(('metal', metal, '%s_%s' % (metal, tool)), ('X', 'S'), key={
'X': { 'item': 'tfc:metal/%s/%s' % (tool_head, metal)},
'S': { 'type': 'forge:ore_dict', 'ore': 'stickWood' }
}, result={
'item': 'tfc:metal/%s/%s' % (tool, metal)
})
# CERAMICS
_heads = [x + '_head' for x in TOOLS] + [x + '_blade' for x in TOOLS]
for item_type in METAL_ITEMS:
if item_type not in _heads:
continue
# unfired molds
item(('ceramics', 'unfired', 'mold', item_type), 'tfc:items/ceramics/unfired/mold/%s' % item_type)
# fired, empty molds
item(('ceramics', 'fired', 'mold', item_type, 'empty'), 'tfc:items/ceramics/fired/mold/%s/empty' % item_type)
# fired, filled molds
for metal in ('copper', 'bronze', 'black_bronze', 'bismuth_bronze'):
item(('ceramics', 'fired', 'mold', item_type, metal),
'tfc:items/ceramics/fired/mold/%s/%s' % (item_type, metal))
del _heads
# unfired ingot molds
item(('ceramics', 'unfired', 'mold', 'ingot'), 'tfc:items/ceramics/unfired/mold/ingot')
# fired ingot molds for all metals
_ingotMetals = {} # metal name -> texture
for metal in METAL_TYPES.keys():
_ingotMetals[metal] = metal
for metal, texture in _ingotMetals.items():
item(('ceramics', 'fired', 'mold', 'ingot', metal), 'tfc:items/ceramics/fired/mold/ingot/' + texture)
del _ingotMetals