Class DataAttributesAPI
java.lang.Object
com.github.clevernucleus.dataattributes.api.DataAttributesAPI
The core API access - provides access to the modid and safe static attribute instantiation.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Supplier<net.minecraft.entity.attribute.EntityAttribute>getAttribute(net.minecraft.util.Identifier attributeKey) static <T> TifPresent(net.minecraft.entity.LivingEntity livingEntity, Supplier<net.minecraft.entity.attribute.EntityAttribute> entityAttribute, T fallback, Function<Double, T> function) Allows for an Optional-like use of attributes that may or may not exist all the time.
-
Field Details
-
MODID
The modid for Data Attributes.- See Also:
-
-
Constructor Details
-
DataAttributesAPI
public DataAttributesAPI()
-
-
Method Details
-
getAttribute
public static Supplier<net.minecraft.entity.attribute.EntityAttribute> getAttribute(net.minecraft.util.Identifier attributeKey) - Parameters:
attributeKey- Attribute registry key.- Returns:
- A supplier getting the registered attribute assigned to the input key. Uses a supplier because attributes added using json are null until datapacks are loaded/synced to the client, so static initialisation would not work. Using this you can safely access an attribute through a static reference.
-
ifPresent
public static <T> T ifPresent(net.minecraft.entity.LivingEntity livingEntity, Supplier<net.minecraft.entity.attribute.EntityAttribute> entityAttribute, T fallback, Function<Double, T> function) Allows for an Optional-like use of attributes that may or may not exist all the time. This is the correct way of getting and using values from attributes loaded by datapacks.- Type Parameters:
T-- Parameters:
livingEntity-entityAttribute-fallback-function-- Returns:
- If the input attribute is both registered to the game and present on the input entity, returns the returning value of the input function. Else returns the fallback input.
-