Class DataAttributesAPI

java.lang.Object
com.github.clevernucleus.dataattributes.api.DataAttributesAPI

public final class DataAttributesAPI extends Object
The core API access - provides access to the modid and safe static attribute instantiation.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The modid for Data Attributes.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static Supplier<net.minecraft.entity.attribute.EntityAttribute>
    getAttribute(net.minecraft.util.Identifier attributeKey)
     
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • 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.