Skip to content

Commit

Permalink
Add vararg helper methods for multi-tag support in the FabricTagBuild…
Browse files Browse the repository at this point in the history
…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()`
  • Loading branch information
Starexify authored Feb 20, 2025
1 parent 360374a commit 60b6f1b
Showing 1 changed file with 52 additions and 5 deletions.
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

0 comments on commit 60b6f1b

Please sign in to comment.