Package net.neoforged.neoforge.common
Class PercentageAttribute
java.lang.Object
net.minecraft.world.entity.ai.attributes.Attribute
net.minecraft.world.entity.ai.attributes.RangedAttribute
net.neoforged.neoforge.common.PercentageAttribute
- All Implemented Interfaces:
IAttributeExtension
A Percentage Attribute is one which always displays modifiers as percentages, including for
AttributeModifier.Operation.ADD_VALUE.
This is used for attributes that would not make sense being displayed as flat additions (ex: +0.05 Swim Speed).
-
Nested Class Summary
Nested classes/interfaces inherited from class net.minecraft.world.entity.ai.attributes.Attribute
Attribute.Sentiment -
Field Summary
FieldsFields inherited from class net.minecraft.world.entity.ai.attributes.Attribute
CODEC, MERGED_BLUE, MERGED_GRAY, MERGED_RED, STREAM_CODECFields inherited from interface net.neoforged.neoforge.common.extensions.IAttributeExtension
FORMAT -
Constructor Summary
ConstructorsConstructorDescriptionPercentageAttribute(String pDescriptionId, double pDefaultValue, double pMin, double pMax) Creates a new PercentageAttribute with the default scale factor of 100.PercentageAttribute(String pDescriptionId, double pDefaultValue, double pMin, double pMax, double scaleFactor) Creates a new PercentageAttribute with the given description, value information, and scale factor. -
Method Summary
Modifier and TypeMethodDescriptiontoValueComponent(AttributeModifier.Operation op, double value, TooltipFlag flag) Converts the value of an attribute modifier to the value that will be displayed.Methods inherited from class net.minecraft.world.entity.ai.attributes.RangedAttribute
getMaxValue, getMinValue, sanitizeValueMethods inherited from class net.minecraft.world.entity.ai.attributes.Attribute
getDefaultValue, getDescriptionId, getMergedStyle, getStyle, isClientSyncable, setSentiment, setSyncableMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.neoforged.neoforge.common.extensions.IAttributeExtension
getBaseId, getDebugInfo, toBaseComponent, toComponent
-
Field Details
-
scaleFactor
protected final double scaleFactor
-
-
Constructor Details
-
PercentageAttribute
public PercentageAttribute(String pDescriptionId, double pDefaultValue, double pMin, double pMax, double scaleFactor) Creates a new PercentageAttribute with the given description, value information, and scale factor.If your attribute's "real" value correlates 1 == 100%, you would use a scale factor of 100 to convert to 1 to 100%.
- Parameters:
pDescriptionId- The description id used for generating the attribute's lang key.pDefaultValue- The default value of the attributepMin- The minimum valuepMax- The maximum valuescaleFactor- The scale factor, used to convert the literal value to a percentage value.
-
PercentageAttribute
Creates a new PercentageAttribute with the default scale factor of 100.- See Also:
-
-
Method Details
-
toValueComponent
public MutableComponent toValueComponent(AttributeModifier.Operation op, double value, TooltipFlag flag) Description copied from interface:IAttributeExtensionConverts 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.
-