Skip to content

feature(nbt): CompoundBinaryTag#builder(existing)#1266

Open
tal5 wants to merge 3 commits into
PaperMC:main/4from
tal5:feature/compound_to_builder
Open

feature(nbt): CompoundBinaryTag#builder(existing)#1266
tal5 wants to merge 3 commits into
PaperMC:main/4from
tal5:feature/compound_to_builder

Conversation

@tal5

@tal5 tal5 commented Jul 9, 2025

Copy link
Copy Markdown
Contributor

Adds CompoundBinaryTag#createBuilder, which creates a builder from the compound tag's current contents.
This is useful if you're editing a couple of values at once, like compound.createBuilder().putInt("num", 6).putString("name", "Timothy").remove("old_value").build().

Might have merge conflicts with #1264, but I'll fix up whichever one is merged last.

@kashike

kashike commented Aug 13, 2025

Copy link
Copy Markdown
Member

Prefer CompoundBinaryTag.builder(existingTag)

@tal5

tal5 commented Aug 26, 2025

Copy link
Copy Markdown
Contributor Author

Prefer CompoundBinaryTag.builder(existingTag)

Switched to that style, with a new CompoundBinaryTag#asMap method (returns an unmodifiable view of the tag's contents as a map) for a cleaner implementation without casting to the impl type or other approaches - that method is nice to have either way imo, for more convenient usage with any general map utility methods.

@tal5 tal5 changed the title feature(nbt): CompoundBinaryTag#createBuilder feature(nbt): CompoundBinaryTag#builder(existing) Sep 4, 2025
@kezz kezz added this to the 4.26.0 milestone Oct 6, 2025
@kezz kezz removed this from the 5.1.0 milestone Apr 28, 2026

@Strokkur424 Strokkur424 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This PR needs rebasing for the main/5 branch, which includes removing/replacing the Jetbrains nullability annotations with JSpecify ones.

* @since 4.0.0
*/
@NotNull Set<String> keySet();
@Unmodifiable @NotNull Map<String, BinaryTag> asMap();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Based on the implementation, this actually returns a view. I would mark it as such.

Suggested change
@Unmodifiable @NotNull Map<String, BinaryTag> asMap();
@UnmodifiableView @NotNull Map<String, BinaryTag> asMap();

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.

4 participants