
命令
/attribute
读取或更改生物实体的属性,例如最大生命值、移动速度或大小。
| /attribute <target> <attribute> base get [<scale>] |
| /attribute <target> <attribute> base reset |
| /attribute <target> <attribute> base set <value> |
| /attribute <target> <attribute> get [<scale>] |
| /attribute <target> <attribute> modifier add <id> <value> (add_multiplied_base|add_multiplied_total|add_value) |
| /attribute <target> <attribute> modifier remove <id> |
| /attribute <target> <attribute> modifier value get <id> [<scale>] |
| 参数 | 值的类型 | 输入内容 |
|---|---|---|
| <target> | 目标选择器 | 要读取或更改的实体。必须恰好是一个实体。仅限一个实体。 |
| <attribute> | 游戏ID | 属性id,例如minecraft:max_health、minecraft:movement_speed、minecraft:attack_damage或minecraft:scale。某个属性的ID。 |
| <scale> | 小数 | 一个数,值会先乘以它,再作为/execute store保存的数返回。默认为1。 |
| <value> | 小数 | 对于 base set,新的基础值。对于 modifier add,修饰符所应用的数值。 |
| <id> | ID | 修饰器带命名空间的ID,例如 example:boost。添加修饰符时选定,之后再次使用它来读取或移除该修饰符。 |
| 权限等级 | 2:管理员、开启作弊的世界、命令方块和函数 |
| 适用于 | 开启作弊的单人游戏和多人游戏服务器。需要权限等级2(游戏管理员):服务器管理员、开启作弊的玩家、命令方块和函数都可以执行。 |
| 结果 | get命令会报告该值,并返回乘以比例后的结果,小数部分被舍去。设置、重置、添加或移除的命令会报告更改内容,并返回1。 |
| get | 显示属性应用所有修饰符后的最终值。 |
| base get | 显示属性在任何修饰符之前的基础值。 |
| base set | 将属性的基础值设为给定的数字。 |
| base reset | 将基础值恢复为该类实体的默认值,并输出默认值。 |
| modifier add | 添加一个带有给定ID、数值和运算方式的永久修饰符。如果该属性已有具有该 ID 的修饰符,则失败。 |
| modifier remove | 移除具有指定ID的修饰符。如果该属性没有这样的修饰符,则失败。 |
| modifier value get | 显示某个修饰符的值。如果该属性没有具有该 ID 的修饰符,则失败。 |
| 运算 | add_value 把该值加到基础值上。add_multiplied_base 加上基础值(在所有 add_value 修饰符之后)乘以该值的结果。add_multiplied_total 把当前总值乘以1加该值。它们按该顺序应用。 |
| 目标必须存活 | 目标必须是单个生物实体,例如玩家或生物。其他实体会失败并提示“不是此命令的有效实体”,没有所选属性的实体会失败并提示“没有该属性”。 |
| 尺寸 | 缩放默认为1。更大的缩放可以保留/execute store所保存数字中的小数,例如100会把0.1变为10。 |
/attribute @s minecraft:max_health get显示你的最大生命值。
/attribute @s minecraft:max_health base set 40将你的基础最大生命值设为40,即20颗心。
/attribute @s minecraft:scale base set 2让你的体型变为两倍。
/attribute @s minecraft:movement_speed modifier add example:sprint_boost 0.5 add_multiplied_base添加一个使你移动速度加快百分之50的修饰符。
/attribute @s minecraft:movement_speed modifier remove example:sprint_boost再次移除该速度修饰符。
/attribute @s minecraft:scale base reset使你恢复正常大小。

