Created
December 26, 2020 00:34
-
-
Save tofran/87a5d712e5646fccacc25304e4d38d2c to your computer and use it in GitHub Desktop.
Copy minecraft NBT properties from one file into another
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
#!/usr/bin/env python3 | |
# Copy minecraft NBT properties from one file into another | |
# Usage: | |
# ./nbt-copy.py <source_file> <destination_file> <property> [properties] | |
# | |
# Requires nbt: | |
# pip install nbt | |
import argparse | |
from nbt import nbt | |
def copy_attributes(nbt_src, nbt_dest, keys_to_copy): | |
for key in keys_to_copy: | |
if key not in nbt_src: | |
raise ValueError(f"{key} not in source file") | |
nbt_dest[key] = nbt_src[key] | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser() | |
parser.add_argument("source_file") | |
parser.add_argument("destination_file") | |
parser.add_argument("properties", nargs="+") | |
args = parser.parse_args() | |
nbt_src = nbt.NBTFile(args.source_file, "rb") | |
nbt_dest = nbt.NBTFile(args.destination_file, "rb") | |
copy_attributes( | |
nbt_src, | |
nbt_dest, | |
list(args.properties), | |
) | |
nbt_dest.write_file(args.destination_file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment