Skip to content

Commit 68b57df

Browse files
Large updates to make this functionally compatiable
1 parent 68619e3 commit 68b57df

File tree

1 file changed

+38
-28
lines changed

1 file changed

+38
-28
lines changed

BUILD_COMMAND.py

+38-28
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1-
import os
21
import json
3-
import zipfile
2+
from shutil import make_archive
3+
from pathlib import Path
44

55
# Goal: Write Datapack that sets up all display items
6-
VERSION = (1, 0, 0) # Major, Minor, Fix per semantic versioning v2 https://semver.org/
7-
MC_PACK_VERSION = 41
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"
6+
VERSION = (1, 0, 1) # Major, Minor, Fix per semantic versioning v2 https://semver.org/
7+
MC_PACK_VERSION = 61
8+
DIR_OUTPUT = "./output/"
9+
BUILD_DIR = "./output/build"
10+
FUNC_DIR_NAME = "function"
11+
12+
DIR_DATA = f"{BUILD_DIR}/data"
13+
DIR_PACK = f"{BUILD_DIR}/summon-stands"
14+
MC_NAMESPACE = f"{BUILD_DIR}/minecraft"
15+
MC_FUNC = f"{MC_NAMESPACE}/tags/{FUNC_DIR_NAME}"
16+
DIR_FUNC = f"{DIR_PACK}/{FUNC_DIR_NAME}"
17+
OUTPUT_FILE = f"{DIR_OUTPUT}/summon-stands_{MC_PACK_VERSION}_{VERSION[0]}.{VERSION[1]}.{VERSION[2]}"
1318
armor_elements = ["boots", "leggings", "chestplate", "helmet"]
1419

1520
armor_class = ["leather", "iron", "diamond", "golden", "chainmail", "netherite"]
@@ -89,27 +94,24 @@ def makeSummon(x, y, z, material, trim, type):
8994
out += "}"
9095
return out
9196

97+
def checkDirectories():
98+
Path(DIR_FUNC).mkdir(parents=True, exist_ok=True)
99+
Path(MC_FUNC).mkdir(parents=True, exist_ok=True)
100+
101+
102+
92103
def main():
93104

94105
x_off = 1
95106
y_off = 0
96107
z_off = -1
97108
commands = []
98-
99-
if not os.path.exists(DIR_OUTPUT):
100-
os.mkdir(DIR_OUTPUT)
101109

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)
110+
checkDirectories()
110111

111112
trim_x_off = 1
112113
trim_commands = []
114+
print("BUILDING TRIM COMMANDS")
113115
for trim in trims:
114116
# Generate Each Trim Type
115117
for mat in materials:
@@ -132,17 +134,20 @@ def main():
132134
for cmd in trim_commands:
133135
file.write(cmd + "\n")
134136
# print(commands)
137+
print("#################################################################################")
135138

136139

137140
with open(f"{DIR_FUNC}/load_all.mcfunction", "w") as file:
141+
print("WRITING LOAD ALL FUNCTION")
138142
for cmd in commands:
139143
file.write(cmd + "\n")
140144

141145
# Add the load.mcfunction file
142146
with open(f"{DIR_FUNC}/load.mcfunction", "w") as file:
147+
print("WRITING PACK LOAD FUNCTION")
143148
file.write("# Load all functions")
144149

145-
with open(f"{DIR_OUTPUT}/pack.mcmeta", "w") as file:
150+
with open(f"{BUILD_DIR}/pack.mcmeta", "w") as file:
146151
print("Writing Pack meta data")
147152
mcmeta = {
148153
"pack": {
@@ -151,15 +156,20 @@ def main():
151156
}
152157
}
153158
json.dump(mcmeta, file, indent=4)
159+
160+
with open(f"{MC_FUNC}/load.json", "w") as file:
161+
print("Writing Minecraft Load JSON")
162+
mcload = {
163+
"values": [
164+
"summon-stands:load"
165+
]
166+
}
167+
154168

155169
# 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))
170+
print("WRITING ZIP FILE")
171+
make_archive(OUTPUT_FILE, "zip", BUILD_DIR)
172+
163173

164174

165175
if __name__ == "__main__":

0 commit comments

Comments
 (0)