Skip to content

Conversation

@Fisch37
Copy link
Contributor

@Fisch37 Fisch37 commented Oct 23, 2025

Currently, the various Nbt types only implement std::fmt::Debug, which displays the internal structure and is very hard to read. A more readable format (for non-debugging purposes) would be to format the data as SNBT, completing one half of #32 in so doing.

As such, I have implemented std::fmt::Display on Nbt, NbtTag, and NbtCompound, which produces valid SNBT matching the formatting used by Minecraft. I have also added various unit tests that match, again, the output produced by CrabNBT with real Minecraft SNBT output.

Following the SNBT standard ensures a lossless representation of the data, moreover one that is easily machine parsable. This opens up the possibility of implementing std::str::FromStr in the future, which would also handily complete the other side of #32.

if I'm honest, this should already be complete. I have also added unit tests. Every unit test is matching against actual SNBT produced by Minecraft (1.21.1)*

* actually, 1.21.1 doesn't allow nameless compound values yet, so I had to manually add those in (c. compound_with_basic_numbers and others)
I would rather we could keep them, but that would mean making escape_string_value and its module public
Copy link
Member

@Norbiros Norbiros left a comment

Choose a reason for hiding this comment

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

Overall, pretty good job! Sorry for the delay, but I was away from home for a while.

@Fisch37
Copy link
Contributor Author

Fisch37 commented Oct 28, 2025

Not sure what happened there... will investigate tomorrow

@Fisch37
Copy link
Contributor Author

Fisch37 commented Oct 29, 2025

Finally figured out how to run Clippy and formatter. Should be fine now

@Fisch37
Copy link
Contributor Author

Fisch37 commented Oct 29, 2025

okay, I don't think I've done anything to cause that. Compiled and tested perfectly fine on my machine too

can someone else have a look at that log?

@Norbiros
Copy link
Member

Norbiros commented Nov 2, 2025

Sorry for the delay. Yeah, it wasn't your fault - it was a change introduced in recent versions of clippy. I fixed this issue in 8e0cd21, so please, just rebase your branch on top of main.

Copy link
Member

@Norbiros Norbiros left a comment

Choose a reason for hiding this comment

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

Good job :shipit: (just update your branch, so our checks can run)

@Fisch37
Copy link
Contributor Author

Fisch37 commented Nov 3, 2025

it is done

@Norbiros Norbiros merged commit 708b387 into CrabCraftDev:main Nov 3, 2025
1 check passed
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.

3 participants