This repository has been archived by the owner on Nov 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
66 lines (57 loc) · 2.37 KB
/
main.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
from tkinter import filedialog
from PIL import Image
import json
import os
def calculate_scale_fp(texture_size: int):
default_scale = 0.039 # nearly correct
calculated_scale = round(default_scale*16/texture_size, 8)
return [calculated_scale]*3
def calculate_scale_fp_offhand(texture_size: int):
default_scale = 0.065
calculated_scale = round(default_scale*16/texture_size, 8)
return [calculated_scale]*3
def calculate_scale_tp(texture_size: int):
default_scale = 0.0965
calculated_scale = round(default_scale*16/texture_size, 8)
return [calculated_scale]*3
def calculate_scale_tp_offhand(texture_size: int):
default_scale = 0.0965
calculated_scale = round(default_scale*16/texture_size, 8)
return [calculated_scale]*3
def create_render_offsets(image_size: int) -> dict:
main_hand = calculate_scale_fp(image_size)
main_hand_tp = calculate_scale_tp(image_size)
off_hand = calculate_scale_fp_offhand(image_size)
off_hand_tp = calculate_scale_tp_offhand(image_size)
render_offsets = {
'minecraft:render_offsets': {
'main_hand': {
'first_person': {'scale': main_hand},
'third_person': {'scale': main_hand_tp}
},
'off_hand': {
'first_person': {'scale': off_hand},
'third_person': {'scale': off_hand_tp}
}
}
}
return render_offsets
def main():
image_path = filedialog.askopenfilename()
if not image_path.endswith('.png'):
print("Please, select a .png texture!")
else:
(image_width, image_height) = Image.open(image_path).size
if image_width != image_height:
print("Your texture height and size need to be the same!")
else:
image_size = image_height
render_offsets = create_render_offsets(image_size)
render_offsets_output_path = os.path.join(os.getcwd(), 'render_offsets.txt')
with open(render_offsets_output_path, 'w') as render_offsets_output_file:
json.dump(render_offsets, render_offsets_output_file, indent=4)
print(json.dumps(render_offsets, indent=4))
print("Your render offsets have also been written to file in the same folder this script is.")
print("Thank you for using this render offsets generator. Created by MJ105#0448.")
if __name__ == '__main__':
main()