Skip to content

Commit

Permalink
Added Code that allows for the creation of the datapack
Browse files Browse the repository at this point in the history
  • Loading branch information
Negative-light committed May 13, 2024
1 parent 10d90d4 commit d0c2f4d
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 35 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,5 @@ cython_debug/
.vscode/

# OUTPUT
output/
output/
summon-stands*.zip
115 changes: 81 additions & 34 deletions BUILD_COMMAND.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import os
import json
import zipfile

# Goal: Write Datapack that sets up all display items
DIR_OUTPUT = "./output/"
VERSION = (1, 0, 0) # Major, Minor, Fix per semantic versioning v2 https://semver.org/
MC_PACK_VERSION = 26
DIR_OUTPUT = "./output"
DIR_DATA = f"{DIR_OUTPUT}/data"
DIR_PACK = f"{DIR_DATA}/summon-stands"
DIR_FUNC = f"{DIR_PACK}/functions"
OUTPUT_FILE = f"summon-stands_{MC_PACK_VERSION}_{VERSION[0]}.{VERSION[1]}.{VERSION[2]}.zip"
armor_elements = ["boots", "leggings", "chestplate", "helmet"]

armor_class = ["leather", "iron", "diamond", "golden", "chainmail", "netherite"]
Expand Down Expand Up @@ -40,10 +48,7 @@
]


x_off = 1
y_off = 0
z_off = -1
commands = []



def getPos(x, y, z):
Expand Down Expand Up @@ -84,36 +89,78 @@ def makeSummon(x, y, z, material, trim, type):
out += "}"
return out

def main():

x_off = 1
y_off = 0
z_off = -1
commands = []

if not os.path.exists(DIR_OUTPUT):
os.mkdir(DIR_OUTPUT)

if not os.path.exists(DIR_DATA):
os.mkdir(DIR_DATA)

if not os.path.exists(DIR_PACK):
os.mkdir(DIR_PACK)

if not os.path.exists(DIR_FUNC):
os.mkdir(DIR_FUNC)

if not os.path.exists(DIR_OUTPUT):
os.mkdir(DIR_OUTPUT)

trim_x_off = 1
trim_commands = []
for trim in trims:
# Generate Each Trim Type
for mat in materials:
# Generate Command
for armor in armor_class:
print(f"{mat}-{trim}-{armor}")
commands.append(f"setblock {getPos(x_off, y_off, z_off )} stone")
commands.append(makeSummon(x_off, 15, z_off, mat, trim, armor))

trim_commands.append(f"setblock {getPos(trim_x_off, y_off, z_off )} stone")
trim_commands.append(makeSummon(trim_x_off, 15, z_off, mat, trim, armor))
z_off -= 1
y_off += 2
x_off += 2
trim_x_off += 2
z_off = -1
y_off = 0
trim_x_off = 1
with open(f"{DIR_OUTPUT}load_{trim}.mcfunction", "w") as file:
for cmd in trim_commands:
trim_commands = []
for trim in trims:
# Generate Each Trim Type
for mat in materials:
# Generate Command
for armor in armor_class:
print(f"{mat}-{trim}-{armor}")
commands.append(f"setblock {getPos(x_off, y_off, z_off )} stone")
commands.append(makeSummon(x_off, 15, z_off, mat, trim, armor))

trim_commands.append(f"setblock {getPos(trim_x_off, y_off, z_off )} stone")
trim_commands.append(makeSummon(trim_x_off, 15, z_off, mat, trim, armor))
z_off -= 1
y_off += 2
x_off += 2
trim_x_off += 2
z_off = -1
y_off = 0
trim_x_off = 1
with open(f"{DIR_FUNC}/load_{trim}.mcfunction", "w") as file:
for cmd in trim_commands:
file.write(cmd + "\n")
# print(commands)


with open(f"{DIR_FUNC}/load_all.mcfunction", "w") as file:
for cmd in commands:
file.write(cmd + "\n")
# print(commands)


with open(f"{DIR_OUTPUT}load_all.mcfunction", "w") as file:
for cmd in commands:
file.write(cmd + "\n")
# Add the load.mcfunction file
with open(f"{DIR_FUNC}/load.mcfunction", "w") as file:
file.write("# Load all functions")

with open(f"{DIR_OUTPUT}/pack.mcmeta", "w") as file:
print("Writing Pack meta data")
mcmeta = {
"pack": {
"pack_format": 26,
"description": "Summon armor stands with all trims in all armor types."
}
}
json.dump(mcmeta, file, indent=4)

# Create ZIP
final_output = zipfile.ZipFile(OUTPUT_FILE, "w", zipfile.ZIP_DEFLATED)
final_output.write(DIR_OUTPUT)
with zipfile.ZipFile(OUTPUT_FILE, 'w', zipfile.ZIP_DEFLATED) as zfile:
for folder, subs, files in os.walk(DIR_OUTPUT):
for file in files:
p = os.path.join(folder, file)
zfile.write(p, arcname=os.path.relpath(p, DIR_OUTPUT))


if __name__ == "__main__":
main()

0 comments on commit d0c2f4d

Please sign in to comment.