Skip to content
New issue

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

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

Already on GitHub? # to your account

Add vararg helper methods for multi-tag support in the FabricTagBuilder #4452

Merged
merged 7 commits into from
Feb 20, 2025

Conversation

Starexify
Copy link
Contributor

@Starexify Starexify commented Feb 19, 2025

This makes it possible to use multiple arguments in the new addTags methods so that modders using datagen (like me) no loger have to call the addTag() method for each TagKey<T>.

This PR will add the following vararg methods:

/**
 * Add multiple tags to this tag.
 *
 * @return the {@link FabricTagBuilder} instance
 */
@SafeVarargs
public final FabricTagBuilder addTags(TagKey<T>... tags) {
	for (TagKey<T> tag : tags) {
		addTag(tag);
	}

	return this;
}

/**
 * Add multiple optional tags to this tag.
 *
 * @return the {@link FabricTagBuilder} instance
 */
@SafeVarargs
public final FabricTagBuilder addOptionalTags(TagKey<T>... tags) {
	for (TagKey<T> tag : tags) {
		addOptionalTag(tag);
	}

	return this;
}

/**
 * Add multiple tags to this tag, ignoring any warning.
 *
 * <p><b>Note:</b> only use this method if you are sure that the tags will be always available at runtime.
 * If not, use {@link #addOptionalTags(TagKey[])} instead.
 *
 * @return the {@link FabricTagBuilder} instance
 */
@SafeVarargs
public final FabricTagBuilder forceAddTags(TagKey<T>... tags) {
	for (TagKey<T> tag : tags) {
		forceAddTag(tag);
	}

	return this;
}

Also changed the JavaDocs at line 421 to link the addOptionalTag(TagKey<T>) instead of * If not, use {@link #addOptionalTag(Identifier)} instead.

Also changed the add(T... elements) method to use a for loop instead of a Stream.of():

@SafeVarargs
public final FabricTagBuilder add(T... elements) {
	for (T element : elements) {
		add(reverseLookup(element));
	}

	return this;
}

@Starexify Starexify changed the title Tag vararg helper methods for the FabricTagBuilder Add vararg helper methods for multi-tag support in the FabricTagBuilder Feb 19, 2025
@modmuss50 modmuss50 added the enhancement New feature or request label Feb 19, 2025
@modmuss50 modmuss50 added the last call If you care, make yourself heard right away! label Feb 19, 2025
@modmuss50
Copy link
Member

Just some checkstyle failuires now, you need a blank line after the for loop.

@modmuss50 modmuss50 added the merge me please Pull requests that are ready to merge label Feb 20, 2025
@modmuss50 modmuss50 merged commit 60b6f1b into FabricMC:1.21.4 Feb 20, 2025
4 checks passed
modmuss50 pushed a commit that referenced this pull request Feb 20, 2025
…er (#4452)

* Add multiple helper varargs methods for tags

* Fixed a bit the JavaDocs grammar

* More clarity for the addTags in JavaDocs

* Changed the Stream.of() with a for loop

* Added blank lines after block at same indentation  level

* Small grammar mistakes

* Changed the `add(T... elements)` to use for loop instead of `Stream.of()`

(cherry picked from commit 60b6f1b)
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request last call If you care, make yourself heard right away! merge me please Pull requests that are ready to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants