twoolie / NBT

Python Parser/Writer for the NBT file format, and it's container the RegionFile.
MIT License
361 stars 74 forks source link

Unable to set value for Compound #162

Open alex4200 opened 2 years ago

alex4200 commented 2 years ago

When I just want to copy data, I usually can do something like this

block_entities = nbt.TAG_List(name="block_entitites", value=self.nbt_data["block_entities"])

except for the type "compound":

heightmaps = nbt.TAG_Compound(name="Heightmaps", value=self.nbt_data["Heightmaps"])

where I get an error

    heightmaps = nbt.TAG_Compound(name="Heightmaps", value=self.nbt_data["Heightmaps"])
TypeError: __init__() got an unexpected keyword argument 'value'

Why is that? Why can't I copy the data as for all the other data types?

And how to best copy data like that?

twoolie commented 1 year ago

TAG_Compound doesn't have a single value, it's a collection of other tags. The following code should work.

    heightmaps = nbt.TAG_Compound(name="Heightmaps")
    heightmaps.tags = self.nbt_data["Heightmaps"]

I'll probably add a values kwarg to TAG_Compound to make it behave like the other tags. good idea.