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
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.function.Function;
import java.util.stream.Stream;

import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -304,8 +303,11 @@ public FabricTagBuilder add(T element) {
* @return the {@link FabricTagBuilder} instance
*/
@SafeVarargs
public final FabricTagBuilder add(T... element) {
Stream.of(element).map(FabricTagProvider.this::reverseLookup).forEach(this::add);
public final FabricTagBuilder add(T... elements) {
for (T element : elements) {
add(reverseLookup(element));
}

return this;
}

Expand Down Expand Up @@ -372,6 +374,20 @@ public FabricTagBuilder addTag(TagKey<T> tag) {
return this;
}

/**
* 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 another optional tag to this tag.
*
Expand All @@ -392,11 +408,25 @@ public FabricTagBuilder addOptionalTag(TagKey<T> tag) {
return addOptionalTag(tag.id());
}

/**
* 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 another tag to this tag, ignoring any warning.
*
* <p><b>Note:</b> only use this method if you sure that the tag will be always available at runtime.
* If not, use {@link #addOptionalTag(Identifier)} instead.
* <p><b>Note:</b> only use this method if you are sure that the tag will be always available at runtime.
* If not, use {@link #addOptionalTag(TagKey)} instead.
*
* @return the {@link FabricTagBuilder} instance
*/
Expand All @@ -405,6 +435,23 @@ public FabricTagBuilder forceAddTag(TagKey<T> 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;
}

/**
* Add multiple elements to this tag.
*
Expand Down