Class BooleanAttribute

java.lang.Object
net.minecraft.world.entity.ai.attributes.Attribute
net.neoforged.neoforge.common.BooleanAttribute
All Implemented Interfaces:
IAttributeExtension

public class BooleanAttribute extends Attribute
A boolean attribute only has two states, on or off, represented by a value of 0 (false) or 1 (true).

For boolean attributes, only use the following modifier values:

This behavior allows for multiple enabling modifiers to coexist, not removing the effect unless all enabling modifiers are removed.

Additionally, it permits forcibly disabling the effect through multiply total.

  • Constructor Details

    • BooleanAttribute

      public BooleanAttribute(String descriptionId, boolean defaultValue)
  • Method Details

    • sanitizeValue

      public double sanitizeValue(double value)
      Description copied from class: Attribute
      Sanitizes the value of the attribute to fit within the expected parameter range of the attribute.
      Overrides:
      sanitizeValue in class Attribute
      Parameters:
      value - The value of the attribute to sanitize.
      Returns:
      The sanitized attribute value.
    • toValueComponent

      public MutableComponent toValueComponent(@Nullable @Nullable AttributeModifier.Operation op, double value, TooltipFlag flag)
      Description copied from interface: IAttributeExtension
      Converts the value of an attribute modifier to the value that will be displayed.

      For multiplicative modifiers, this method is responsible for converting the value to percentage form.

      Parameters:
      op - The operation of the modifier. Null if we are just displaying the raw value and not a modifier.
      value - The value to convert. Either the current attribute value (if null operation) or the attribute modifier's amount.
      flag - The tooltip flag.
      Returns:
      The component form of the formatted value.
    • toComponent

      public MutableComponent toComponent(AttributeModifier modif, TooltipFlag flag)
      Description copied from interface: IAttributeExtension
      Converts an attribute modifier into its tooltip representation.

      This method does not handle formatting of "base" modifiers, such as Attack Damage or Attack Speed.

      The returned component may append additional debug information based on the tooltip flag.

      Parameters:
      modif - The attribute modifier being converted to a component.
      flag - The tooltip flag.
      Returns:
      The component representation of the passed attribute modifier, with debug info appended if enabled.