Skip to content

Commit

Permalink
Added NBT type
Browse files Browse the repository at this point in the history
 - Reading from Buffer object
 - Writing to Buffer object
 - Converting from/to python objects

 100% test coverage for the nbt.py, Pyright and Ruff are happy
  • Loading branch information
LiteApplication committed Apr 27, 2024
1 parent 2836898 commit f079cf3
Show file tree
Hide file tree
Showing 3 changed files with 2,400 additions and 0 deletions.
9 changes: 9 additions & 0 deletions changes/257.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
- Added the `NBTag` to deal with NBT data:
- The `NBTag` class is the base class for all NBT tags and provides the basic functionality to serialize and deserialize NBT data from and to a `Buffer` object.
- The classes `EndNBT`, `ByteNBT`, `ShortNBT`, `IntNBT`, `LongNBT`, `FloatNBT`, `DoubleNBT`, `ByteArrayNBT`, `StringNBT`, `ListNBT`, `CompoundNBT`, `IntArrayNBT`and `LongArrayNBT` were added and correspond to the NBT types described in the [NBT specification](https://wiki.vg/NBT#Specification).
- NBT tags can be created using the `NBTag.from_object()` method, which automatically selects the correct tag type based on the object's type and works recursively for lists and dictionaries.
- The `NBTag.to_object()` method can be used to convert an NBT tag back to a Python object.
- The `NBTag.serialize()` can be used to serialize an NBT tag to a new `Buffer` object.
- The `NBTag.deserialize(buffer)` can be used to deserialize an NBT tag from a `Buffer` object.
- If the buffer already exists, the `NBTag.write_to(buffer, with_type=True, with_name=True)` method can be used to write the NBT tag to the buffer (and in that case with the type and name in the right format).
- The `NBTag.read_from(buffer, with_type=True, with_name=True)` method can be used to read an NBT tag from the buffer (and in that case with the type and name in the right format).
Loading

0 comments on commit f079cf3

Please sign in to comment.