-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfixtexture.py
70 lines (59 loc) · 2.48 KB
/
fixtexture.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
import json
import os
import jsbeautifier
import setup
unassignedItemModels = list()
unassignedBlockModels = list()
for blockModel in setup.modelBlockFolder.iterdir():
with open(blockModel) as f:
data = json.load(f)
if (not 'textures' in data): continue
textures = data['textures']
for key in textures:
isAssigned = len(str(textures[key]).split(':')) > 1
if (not isAssigned):
unassignedBlockModels.append(blockModel)
break
for itemModel in setup.modelItemFolder.iterdir():
with open(itemModel) as f:
data = json.load(f)
if (not 'textures' in data): continue
textures = data['textures']
for key in textures:
isAssigned = len(str(textures[key]).split(':')) > 1
if (not isAssigned):
unassignedItemModels.append(itemModel)
break
if (len(unassignedBlockModels) == 0 and len(unassignedItemModels) == 0):
print("None unassigned textures were found, make sure to add your items and blocks to the models folder!")
raise SystemExit
print(f"Found {len(unassignedItemModels)} unassigned item textures.")
print(f"Found {len(unassignedBlockModels)} unassigned block textures.")
inp = input('Do you wish to continue? Y/N ')
if (str(inp).lower() == 'n'): raise SystemExit
convertedBlockModels = 0
convertedItemModels = 0
for blockModel in unassignedBlockModels:
with open(blockModel) as f:
model = json.load(f)
if (not 'textures' in model): continue
textures = model['textures']
for key in textures:
model['textures'][key] = f"{setup.modId}:block/{os.path.splitext(blockModel.name)[0]}"
with open(blockModel, 'w') as f:
f.write(jsbeautifier.beautify(json.dumps(model), setup.opts))
convertedBlockModels += 1
for itemModel in unassignedItemModels:
with open(itemModel) as f:
model = json.load(f)
if (not 'textures' in model): continue
textures = model['textures']
for key in textures:
model['textures'][key] = f"{setup.modId}:item/{os.path.splitext(itemModel.name)[0]}"
with open(itemModel, 'w') as f:
f.write(jsbeautifier.beautify(json.dumps(model), setup.opts))
convertedItemModels += 1
if (convertedBlockModels > 0):
print(f"Finished converting {convertedBlockModels} block model(s).")
if (convertedItemModels > 0):
print(f"Finished converting {convertedItemModels} item model(s).")