Class Attribute

java.lang.Object
net.minecraft.world.entity.ai.attributes.Attribute
All Implemented Interfaces:
IAttributeExtension
Direct Known Subclasses:
BooleanAttribute, RangedAttribute

public class Attribute extends Object implements IAttributeExtension
Defines an entity attribute. These are properties of entities that can be dynamically modified.
See Also:
  • invalid reference
    net.minecraft.core.Registry#ATTRIBUTE
  • Field Details

    • CODEC

      public static final com.mojang.serialization.Codec<Holder<Attribute>> CODEC
    • STREAM_CODEC

      public static final StreamCodec<RegistryFriendlyByteBuf,Holder<Attribute>> STREAM_CODEC
    • defaultValue

      private final double defaultValue
      The default value of the attribute.
    • syncable

      private boolean syncable
      Whether the value of this attribute should be kept in sync on the client.
    • descriptionId

      private final String descriptionId
      A description Id for the attribute. This is most commonly used as the localization key.
    • sentiment

      private Attribute.Sentiment sentiment
    • MERGED_RED

      protected static final TextColor MERGED_RED
    • MERGED_BLUE

      protected static final TextColor MERGED_BLUE
    • MERGED_GRAY

      protected static final TextColor MERGED_GRAY
  • Constructor Details

    • Attribute

      protected Attribute(String pDescriptionId, double pDefaultValue)
  • Method Details

    • getDefaultValue

      public double getDefaultValue()
    • isClientSyncable

      public boolean isClientSyncable()
    • setSyncable

      public Attribute setSyncable(boolean pWatch)
      Sets whether the attribute value should be synced to the client.
      Parameters:
      pWatch - Whether the attribute value should be kept in sync.
      Returns:
      The same attribute instance being modified.
    • setSentiment

      public Attribute setSentiment(Attribute.Sentiment pSentiment)
    • sanitizeValue

      public double sanitizeValue(double pValue)
      Sanitizes the value of the attribute to fit within the expected parameter range of the attribute.
      Parameters:
      pValue - The value of the attribute to sanitize.
      Returns:
      The sanitized attribute value.
    • getDescriptionId

      public String getDescriptionId()
    • getStyle

      public ChatFormatting getStyle(boolean pIsPositive)
    • getMergedStyle

      public TextColor getMergedStyle(boolean isPositive)
      Description copied from interface: IAttributeExtension
      Returns the color used by merged attribute modifiers. Only used when NeoForgeMod.enableMergedAttributeTooltips() is active.

      Similarly to getStyle(boolean), this method should return a color based on the attribute's Attribute.Sentiment. The returned color should be distinguishable from the color used by getStyle(boolean).

      Specified by:
      getMergedStyle in interface IAttributeExtension