Add vararg helper methods for multi-tag support in the FabricTagBuilder ()

* 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()`
This commit is contained in:
ImVeryBad 2025-02-20 19:02:48 +01:00 committed by GitHub
parent 360374ac64
commit 60b6f1b7ce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -25,7 +25,6 @@ import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.function.Function;
import java.util.stream.Stream;
import org.jetbrains.annotations.Nullable;
@ -304,8 +303,11 @@ public abstract class FabricTagProvider<T> extends TagProvider<T> {
* @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;
}
@ -372,6 +374,20 @@ public abstract class FabricTagProvider<T> extends TagProvider<T> {
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.
*
@ -392,11 +408,25 @@ public abstract class FabricTagProvider<T> extends TagProvider<T> {
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
*/
@ -405,6 +435,23 @@ public abstract class FabricTagProvider<T> extends TagProvider<T> {
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.
*