1
1
import os
2
+ import json
3
+ import zipfile
2
4
3
5
# Goal: Write Datapack that sets up all display items
4
- DIR_OUTPUT = "./output/"
6
+ VERSION = (1 , 0 , 0 ) # Major, Minor, Fix per semantic versioning v2 https://semver.org/
7
+ MC_PACK_VERSION = 26
8
+ DIR_OUTPUT = "./output"
9
+ DIR_DATA = f"{ DIR_OUTPUT } /data"
10
+ DIR_PACK = f"{ DIR_DATA } /summon-stands"
11
+ DIR_FUNC = f"{ DIR_PACK } /functions"
12
+ OUTPUT_FILE = f"summon-stands_{ MC_PACK_VERSION } _{ VERSION [0 ]} .{ VERSION [1 ]} .{ VERSION [2 ]} .zip"
5
13
armor_elements = ["boots" , "leggings" , "chestplate" , "helmet" ]
6
14
7
15
armor_class = ["leather" , "iron" , "diamond" , "golden" , "chainmail" , "netherite" ]
40
48
]
41
49
42
50
43
- x_off = 1
44
- y_off = 0
45
- z_off = - 1
46
- commands = []
51
+
47
52
48
53
49
54
def getPos (x , y , z ):
@@ -84,36 +89,78 @@ def makeSummon(x, y, z, material, trim, type):
84
89
out += "}"
85
90
return out
86
91
92
+ def main ():
93
+
94
+ x_off = 1
95
+ y_off = 0
96
+ z_off = - 1
97
+ commands = []
98
+
99
+ if not os .path .exists (DIR_OUTPUT ):
100
+ os .mkdir (DIR_OUTPUT )
101
+
102
+ if not os .path .exists (DIR_DATA ):
103
+ os .mkdir (DIR_DATA )
104
+
105
+ if not os .path .exists (DIR_PACK ):
106
+ os .mkdir (DIR_PACK )
107
+
108
+ if not os .path .exists (DIR_FUNC ):
109
+ os .mkdir (DIR_FUNC )
87
110
88
- if not os .path .exists (DIR_OUTPUT ):
89
- os .mkdir (DIR_OUTPUT )
90
-
91
- trim_x_off = 1
92
- trim_commands = []
93
- for trim in trims :
94
- # Generate Each Trim Type
95
- for mat in materials :
96
- # Generate Command
97
- for armor in armor_class :
98
- print (f"{ mat } -{ trim } -{ armor } " )
99
- commands .append (f"setblock { getPos (x_off , y_off , z_off )} stone" )
100
- commands .append (makeSummon (x_off , 15 , z_off , mat , trim , armor ))
101
-
102
- trim_commands .append (f"setblock { getPos (trim_x_off , y_off , z_off )} stone" )
103
- trim_commands .append (makeSummon (trim_x_off , 15 , z_off , mat , trim , armor ))
104
- z_off -= 1
105
- y_off += 2
106
- x_off += 2
107
- trim_x_off += 2
108
- z_off = - 1
109
- y_off = 0
110
111
trim_x_off = 1
111
- with open (f"{ DIR_OUTPUT } load_{ trim } .mcfunction" , "w" ) as file :
112
- for cmd in trim_commands :
112
+ trim_commands = []
113
+ for trim in trims :
114
+ # Generate Each Trim Type
115
+ for mat in materials :
116
+ # Generate Command
117
+ for armor in armor_class :
118
+ print (f"{ mat } -{ trim } -{ armor } " )
119
+ commands .append (f"setblock { getPos (x_off , y_off , z_off )} stone" )
120
+ commands .append (makeSummon (x_off , 15 , z_off , mat , trim , armor ))
121
+
122
+ trim_commands .append (f"setblock { getPos (trim_x_off , y_off , z_off )} stone" )
123
+ trim_commands .append (makeSummon (trim_x_off , 15 , z_off , mat , trim , armor ))
124
+ z_off -= 1
125
+ y_off += 2
126
+ x_off += 2
127
+ trim_x_off += 2
128
+ z_off = - 1
129
+ y_off = 0
130
+ trim_x_off = 1
131
+ with open (f"{ DIR_FUNC } /load_{ trim } .mcfunction" , "w" ) as file :
132
+ for cmd in trim_commands :
133
+ file .write (cmd + "\n " )
134
+ # print(commands)
135
+
136
+
137
+ with open (f"{ DIR_FUNC } /load_all.mcfunction" , "w" ) as file :
138
+ for cmd in commands :
113
139
file .write (cmd + "\n " )
114
- # print(commands)
115
-
116
140
117
- with open (f"{ DIR_OUTPUT } load_all.mcfunction" , "w" ) as file :
118
- for cmd in commands :
119
- file .write (cmd + "\n " )
141
+ # Add the load.mcfunction file
142
+ with open (f"{ DIR_FUNC } /load.mcfunction" , "w" ) as file :
143
+ file .write ("# Load all functions" )
144
+
145
+ with open (f"{ DIR_OUTPUT } /pack.mcmeta" , "w" ) as file :
146
+ print ("Writing Pack meta data" )
147
+ mcmeta = {
148
+ "pack" : {
149
+ "pack_format" : 26 ,
150
+ "description" : "Summon armor stands with all trims in all armor types."
151
+ }
152
+ }
153
+ json .dump (mcmeta , file , indent = 4 )
154
+
155
+ # Create ZIP
156
+ final_output = zipfile .ZipFile (OUTPUT_FILE , "w" , zipfile .ZIP_DEFLATED )
157
+ final_output .write (DIR_OUTPUT )
158
+ with zipfile .ZipFile (OUTPUT_FILE , 'w' , zipfile .ZIP_DEFLATED ) as zfile :
159
+ for folder , subs , files in os .walk (DIR_OUTPUT ):
160
+ for file in files :
161
+ p = os .path .join (folder , file )
162
+ zfile .write (p , arcname = os .path .relpath (p , DIR_OUTPUT ))
163
+
164
+
165
+ if __name__ == "__main__" :
166
+ main ()
0 commit comments