Skip to content

Conversation

@MSKatKing
Copy link
Contributor

I've implemented NetEncode and NetDecode for NBT types. Here's how it works:

We have a struct, NBT, which is just a wrapper around T.

This type, when T: NBTSerializable, implement NetEncode. The NBTSerializable trait has been modified to use a std::io::Write instead of a hard-coded Vec. It's also been given an async version of the serialize fn. The NetEncode implementation basically just calls these functions for T.

NBT also implements NetDecode when T: for<'a> FromNbt<'a>. NetDecode works a little differently. It will first read the data into a Vec, then create a new NbtTape, finally using that to deserialize into T.

NBT implements Deref<Output=T> and DerefMut, so you can access fields of T without unwrapping it. To use it, just place NBT on the packet field you want to have serialized/deserialized to/from NBT.

This is still a draft PR because I have not tested it yet. Once I know it works, I'll submit this for review.

@MSKatKing
Copy link
Contributor Author

Can confirm it works, I tested it with the play Disconnect packet and the packet sent as normal and the client recognized it and displayed the correct message.

@MSKatKing MSKatKing marked this pull request as ready for review November 23, 2025 11:15
Copy link
Member

@Sweattypalms Sweattypalms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@Sweattypalms Sweattypalms merged commit 63c0c10 into ferrumc-rs:master Nov 24, 2025
6 checks passed
@MSKatKing MSKatKing deleted the feature/network-nbt branch November 24, 2025 06:26
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

Successfully merging this pull request may close these issues.

2 participants