Open gilesknap opened 2 years ago
Out of interest, here is a function in MCIWB using the parser
https://github.com/gilesknap/mciwb/blob/dev/src/demo/arrows.py
Note that it quite easily enables extraction of of a position from the NBT. Also note that this code creates an NBT to send in the data get
but its trivial enough that having a serializer would not have added a great deal.
UPDATE:
Some good news on this. When merging NBT data the command is happy to take any number for numeric types and cast them appropriately.
So this means at present the following code adds 10 eatra items to slot 0 of a chest
In [58]: nbt = parse_nbt(c.data.get(block=Vec3(625, 73, -1646)))
In [59]: nbt['Items'][0]["Count"] += 10
In [60]: c.data.merge(block=Vec3(625, 73, -1646),nbt=str(nbt))
Out[60]: 'Modified block data of 625, 73, -1646'
This appears to mean that the only special handling for serialization is the quoted JSON snippets.
I'm opening this issue to discuss NBT parsing.
(I note that NBTs are a Java edition feature and I'm not familiar with how similar information is handled in other editions)
I have implemented a simple deserializer for Stringified Named Binary Tag data which is the format returned by commands like
data get
I'm not sure the above approach is worthy of the nicely typed mcipc library.
There is a lot more work to do to make a serializable NBT class in python. A useful NBT class would need to:
This would mean you could do something like this:
So is this worth implementing? The nbt serialize would be limited to the following commands that I can think of:
Wheras the dumb deserialize specified above is useful for querying information about Players, Mobs, Entities, Block Entities etc.