Skip to content

NBT Component Serializer #1084

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 87 commits into
base: main/4
Choose a base branch
from

Conversation

Codestech1
Copy link

Adds a support for serializing components as NBT Binary Tags.

Resolves #995

@Codestech1
Copy link
Author

Codestech1 commented Jun 9, 2024

The serialization works now, but i need to clean it up, add backwards compatibility (old nbt), add javadocs and deserialization. But the hardest part with understanding how everything realted to this (in both adventure and Minecraft) is done.

@Codestech1
Copy link
Author

Codestech1 commented Jun 9, 2024

Component deserialization works properly (tested with a large component with many children and styling), component serialization however doesn't serialize lists of components (children, etc.) as anything else than compounds. I'll check if there's a way to make it check if all types of components can be serialized as a string without looping through the entire list twice (one time for checks, second time for creating the list).

What's left (let me know if i forgot anything):

  • JUnit tests
  • Services (for custom serializer imlementation, like the gson serializer)
  • Cleanup (maybe split the serialization process to more classes?)
  • More serializer options
  • Make sure that legacy tags in hover event are serialized properly (I can't do it now, because i cannot even make them work through a /tellraw command in Minecraft)
  • Javadocs

@Codestech1
Copy link
Author

Another TODO:
The hover event serializer should serialize legacy show achievement hover events with value key instead of contents key

@Codestech1 Codestech1 marked this pull request as ready for review June 15, 2024 12:39
@Codestech1 Codestech1 marked this pull request as draft June 15, 2024 12:57
@Codestech1
Copy link
Author

I forgot to add tests for hover event and click event, i'm adding them right now

@Codestech1 Codestech1 marked this pull request as ready for review June 15, 2024 13:23
@Codestech1
Copy link
Author

Ok, it's ready now, i think

@Codestech1
Copy link
Author

I added support for deserializing legacy hover events (those where contents are serialized as text components) as they were still valid for vanilla component serializer while deserializing in versions with NBT component serializing and camel case hover events, however serialization is not supported. I did it like that since I want to make this serializer work the same as the vanilla one, so developers can easily switch to this serializer.

@Codestech1 Codestech1 marked this pull request as ready for review July 1, 2025 02:03
@Codestech1
Copy link
Author

I'd say this serializer is done. It's definitely better than the previous one, it also follows new approach used in the GSON serializer - vanilla-like output. There is one thing left (output comparisons with the dfu serializer) in a list posted by me few comments above, however I'm going to do that in a different repo and it's more like a "proof" that the serializer is stable and world properly and it shouldn't block the PR from being marked as "ready".

@Codestech1 Codestech1 requested a review from kezz July 1, 2025 02:08
@Codestech1
Copy link
Author

Oh, I just realized that there are checkstyle errors, I'm going to fix them soon

@Codestech1 Codestech1 changed the base branch from main/4 to feat/dfu July 1, 2025 06:38
@Codestech1 Codestech1 changed the base branch from feat/dfu to main/4 July 1, 2025 06:38
@Codestech1
Copy link
Author

All of the checkstyle errors have been fixed.

@Codestech1
Copy link
Author

Codestech1 commented Jul 1, 2025

Btw, you probably want to squash-merge this PR since it has over 80 commits ( 😮 ).

@Codestech1
Copy link
Author

Codestech1 commented Jul 3, 2025

The latest commit fixes the order in which TagStringWriter writes compound tag entries. It's in this PR as I noticed it during comparison between this serializer and dfu serializer. I hope that it's not a blocker on a merge.

@Codestech1
Copy link
Author

I'd say this serializer is done. It's definitely better than the previous one, it also follows new approach used in the GSON serializer - vanilla-like output. There is one thing left (output comparisons with the dfu serializer) in a list posted by me few comments above, however I'm going to do that in a different repo and it's more like a "proof" that the serializer is stable and world properly and it shouldn't block the PR from being marked as "ready".

Tests comparing 23w40a (first Minecraft version serializing components in NBT) serializer and this serializer's output are running successfully (https://github.com/Codestech1/nbt-dfu-comparison). Now I only need to copy-paste these tests, replace the testing version to 1.21.7, remove legacy features from testing components and add tests for new features.

…zerOptions#EMIT_SHADOW_COLOR, fix: versioned option state of NBTSerializerOptions serializes shadow color as a list by default
@Codestech1
Copy link
Author

Codestech1 commented Jul 6, 2025

Ok, now the dfu comparison tests are complete (they're available here). All issues have been fixed, the output is the same as in vanilla, so there is really no need to test it in-game. I'd say it's stable enough, hopefully this gets merged soon, the PR is now fully completed.

All you need to run these tests is to publish adventure (on the branch associated with this PR) to maven local.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NBT Component serializer
6 participants