Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Writing a compound tag to a file #163

Open
Matthias1590 opened this issue May 9, 2022 · 1 comment
Open

Writing a compound tag to a file #163

Matthias1590 opened this issue May 9, 2022 · 1 comment

Comments

@Matthias1590
Copy link

Hey there, I've been stuck at what should be a simple thing to do for a while now, I can't manage to write a compound tag to a file. Following the examples on PyPI didn't help much either as they don't write existing tags to files but rather create a new tag (using the nbt.NBTFile class) and write that. Am I missing something or is this just not supported? And if it's not supported, how should I go about doing this?

@twoolie
Copy link
Owner

twoolie commented Feb 14, 2023

Hi @Matthias1590, Sorry to take so long getting back to you.

Essentially, NBTFile subclasses TAG_Compound, so unfortunately you can't just write any arbitrary compound tag at the root of a file.

A workaround would be to create an NBTFile and copy all the root elements into that NBTFile.

tag_compound = nbt.TAG_Compound(...)

nbt_file = nbt.NBTFile()
nbt_file.name = tag_compound.name
nbt_file.tags = tag_compound.tags
nbt_file.write_file("filename.nbt")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants