TranslatableComponent$Builder#addArgument#1298
Open
tal5 wants to merge 1 commit intoPaperMC:main/4from
Open
Conversation
kezz
requested changes
Sep 23, 2025
Comment on lines
+188
to
+192
| requireNonNull(args, "args"); | ||
| this.args = new ArrayList<>(args.size()); | ||
| for (int i = 0; i < args.size(); i++) { | ||
| this.args.add(asArgument(args.get(i), i)); | ||
| } |
Contributor
Author
There was a problem hiding this comment.
You mean the manual ArrayList? Because it needed to be a mutable list for the builder, so it couldn't use the existing asArguments (and I didn't want to change that method around because it's used in other places)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Additions
TranslatableComponent$Builder#addArgument- adds a single translation argument, as opposed to the current methods which only allow setting the entire list.TranslatableComponentImpl#asArgument- converts a singleComponentLikeinto aTranslationArgument, with an optionalintindex for extra error info (ignored when-1, from e.g. the newaddArgument^).Changes
TranslatableComponentImpl$BuilderImpl.args- now defaults to null, with:TranslatableComponentImpl$BuilderImpl#args- acting as a getter that defaults it to a newArrayListif unset and returns its value (similarly to other builders around the API).TranslatableComponentImpl$BuilderImpl#arguments- now initializesargsto a newArrayListof the correct size and adds each argument manually using the newTranslatableComponentImpl#asArgument, so that the list is mutable (unlike the one returned byasArguments) .TranslatableComponentImpl$BuilderImpl#build- now defaultsargstoCollections.emptyList()ifnull.Note
TranslatableComponentImpl#asArgument's logic to include/exclude theint indexparam from errors may be a little messy? I don't think it's a very big problem as it's just an internal util method, but let me know if you'd prefer a different approach.Or maybe using the string supplier variants for
requireNonNullinstead of computing the error strings every time.