Skip to content

Instantly share code, notes, and snippets.

@RedstoneWizard08
Created March 12, 2024 21:59
Show Gist options
  • Save RedstoneWizard08/4e61ba8c90f306e93f7e1c855be8b299 to your computer and use it in GitHub Desktop.
Save RedstoneWizard08/4e61ba8c90f306e93f7e1c855be8b299 to your computer and use it in GitHub Desktop.
VisualOres Merger
# 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