Created
March 12, 2024 21:59
-
-
Save RedstoneWizard08/4e61ba8c90f306e93f7e1c855be8b299 to your computer and use it in GitHub Desktop.
VisualOres Merger
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A fixer for the VisualOres mod (https://www.curseforge.com/minecraft/mc-mods/visualores). | |
# This merges players' data when adding the mod to the server for the first time. | |
import os | |
import nbtlib | |
CLIENT_DIR = "changeme!" | |
SERVER_DIR = "world_changeme!" | |
paths = list(os.listdir("visualores")) | |
paths = filter(lambda x: os.path.isdir("visualores/" + x) and x != "merged", paths) | |
paths = [f"./visualores/{x}/{CLIENT_DIR}/immeng/excavator_DIM0" for x in paths] | |
data = nbtlib.Compound() | |
for path in paths: | |
file = nbtlib.load(path) | |
for key in file.keys(): | |
data[key] = file[key] | |
file = nbtlib.File(data) | |
if not os.path.exists(f"./visualores/merged/{SERVER_DIR}/immeng/"): | |
os.makedirs(f"./visualores/merged/{SERVER_DIR}/immeng/") | |
file.save(f"./visualores/merged/{SERVER_DIR}/immeng/excavator_DIM0", gzipped=True) | |
with open(f"./visualores/merged/{SERVER_DIR}/immeng/excavator_DIM0.snbt", "w") as f: | |
f.write(data.snbt(compact=False, indent=4)) | |
with open(f"./visualores/merged/{SERVER_DIR}/immeng/excavator_DIM0.literal", "w") as f: | |
f.write(nbtlib.serialize_tag(data, compact=False)) | |
files = [] | |
for path in paths: | |
files.append(("_".join(path.split("/")[-4].split("_")[:-1]), os.stat(path).st_size)) | |
total_size = os.stat(f"./visualores/merged/{SERVER_DIR}/immeng/excavator_DIM0").st_size | |
print(f"Merged:") | |
for (user, size) in files: | |
perc = (size / total_size) * 100 | |
print(f" ---> {user}: {size} bytes ({perc:.2f}%)") | |
print(f" -> Total: {total_size} bytes") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment