Skip to content

Conversation

@tal5
Copy link
Contributor

@tal5 tal5 commented Sep 5, 2025

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 single ComponentLike into a TranslationArgument, with an optional int index for extra error info (ignored when -1, from e.g. the new addArgument ^).

Changes

  • TranslatableComponentImpl$BuilderImpl.args - now defaults to null, with:
  • TranslatableComponentImpl$BuilderImpl#args - acting as a getter that defaults it to a new ArrayList if unset and returns its value (similarly to other builders around the API).
  • TranslatableComponentImpl$BuilderImpl#arguments - now initializes args to a new ArrayList of the correct size and adds each argument manually using the new TranslatableComponentImpl#asArgument, so that the list is mutable (unlike the one returned by asArguments) .
  • TranslatableComponentImpl$BuilderImpl#build - now defaults args to Collections.emptyList() if null.

Note

TranslatableComponentImpl#asArgument's logic to include/exclude the int index param 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 requireNonNull instead of computing the error strings every time.

image

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));
}
Copy link
Member

Choose a reason for hiding this comment

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

why the new defensive copy here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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)

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.

2 participants