/attribute
< Commands
This feature is exclusive to Java Edition.
/attribute| Permission level required |
2 |
|---|---|
| Restrictions |
None |
{
"title": "<code>/attribute</code>",
"rows": [
{
"field": "2",
"label": "(link to Permission level article, displayed as Permission level<br>required)"
},
{
"field": "None",
"label": "(link to Commands#Restrictions article, displayed as Restrictions)"
}
],
"invimages": [],
"images": []
}
Used to change or read attributes.
Syntax
attribute <target> <attribute> get [<scale>]- Returns the total value of the specified attribute.
attribute <target> <attribute> base get [<scale>]- Returns the base value of the specified attribute.
attribute <target> <attribute> base set <value>- Overwrites the base value of the specified attribute with the given value.
attribute <target> <attribute> base reset- Resets the base value of the specified attribute to its default value.
attribute <target> <attribute> modifier add <id> <value> (add_value|add_multiplied_base|add_multiplied_total)- Adds an attribute modifier with the specified properties if no modifier with the same ID already existed.
attribute <target> <attribute> modifier remove <id>- Removes the attribute modifier with the specified ID.
attribute <target> <attribute> modifier value get <id> [<scale>]- Returns the value of the modifier with the specified ID.
Arguments
<target>: entity
- The entity that the attribute is applied to. Only players, armor stands, and mobs have attributes.
- Must be a player name, a target selector or a UUID. And the target selector must be in single type.
<attribute>: resource
- Specifies the attribute.
- Must be an existing registered resource location in
minecraft:attributeregistry.
<scale>: double
- The number the value is multiplied with before being stored with
/executecommand. - Must be a [Double]Double-precision floating-point number (from -(2-2-52)×21023 (≈-1.8×10308) to (2-2-52)×21023 (≈1.8×10308) ).
<id>: resource_location
- Specifies the id of a modifier.
- Must be a resource location for an unregistered content.
<value>: double
- Specifies the value to use.
- Must be a [Double]Double-precision floating-point number (from -(2-2-52)×21023 (≈-1.8×10308) to (2-2-52)×21023 (≈1.8×10308) ).
Result
| Command | Trigger | Java Edition |
|---|---|---|
| Any | The command is incomplete, or any argument is not specified correctly. | Unparseable |
<targets> fails to resolve to a player, an armor stand, or a mob. | Failed | |
The attribute doesn't exist for the entity (for example, a player entity has no minecraft:flying_speed). | ||
/... modifier add ... | A modifier with the specified ID is already present. | |
/... modifier remove ... | The modifier with the specified ID doesn't exist. | |
| Any | Otherwise | Successful |
Output
| Command | Edition | Situation | Success Count | /execute store success ... | /execute store result ... |
|---|---|---|---|---|---|
| Any | Java Edition | On fail | 0 | 0 | 0 |
/... get [<scale>] | On success | 1 | 1 | The attribute value (multiplied by <scale>, then cast to int) | |
/... base get [<scale>] | On success | 1 | 1 | The attribute base value (multiplied by <scale>, then cast to int) | |
/... modifier value get <id> [<scale>] | On success | 1 | 1 | The modifier value (multiplied by <scale>, then cast to int) | |
/... base set ... | On success | 1 | 1 | 1 |
Examples
- To set the minimum armor value of the current entity to 5:
/attribute @s minecraft:armor base set 5
History
| Java Edition | |||||||
|---|---|---|---|---|---|---|---|
| 1.16 | 20w17a | Added /attribute. | |||||
| 1.18.2 | 1.18.2-pre3 | Changed from resource_location to resource argument type for the attribute argument. | |||||
| 1.20.5 | 24w09a | Modifier operations have been renamed: add → add_value, multiply_base → add_multiplied_base, multiply → add_multiplied_total. | |||||
| 1.21 | 24w21b | The uuid and name arguments have been replaced with a singular id argument. | |||||
| 1.21.4 | 24w44a | Added /attribute <target> <attribute> base reset.
| |||||
| Suggestions will now be shown for attribute modifier IDs existing on the target. | |||||||