/attribute 命令

/attribute 命令

来源:Commands/attribute,英文修订 ID:3766700。

此命令仅适用于 Java 版,所需权限等级为 2。

更改或读取属性。

语法

命令 功能
attribute <target> <attribute> get [<scale>] 返回指定属性的总值
attribute <target> <attribute> base get [<scale>] 返回指定属性的基础值
attribute <target> <attribute> base set <value> 用给定值覆盖指定属性的基础值
attribute <target> <attribute> base reset 将指定属性的基础值恢复为默认值
attribute <target> <attribute> modifier add <id> <value> (add_value|add_multiplied_base|add_multiplied_total) 若不存在相同 ID 的修饰符,则添加具有指定属性的修饰符
attribute <target> <attribute> modifier remove <id> 移除具有指定 ID 的属性修饰符
attribute <target> <attribute> modifier value get <id> [<scale>] 返回具有指定 ID 的修饰符的值

参数

<target>: entity:属性所属的实体。只有玩家、盔甲架和生物具有属性。必须为玩家名称、目标选择器或 UUID;目标选择器必须只能选中一个实体。

<attribute>: resource:指定属性,必须为 minecraft:attribute 注册表中已存在、已注册的资源位置。

<scale>: double:通过 /execute 存储数值前要乘的倍率。必须为双精度浮点数,范围为 -(2-2^-52)×2^1023 至 (2-2^-52)×2^1023,约为 -1.8×10^308 至 1.8×10^308。

<id>: resource_location:指定修饰符 ID,使用可表示未注册内容的资源位置语法。

<value>: double:指定要使用的值,数值类型与范围同 scale。

结果

情况 结果
命令不完整,或任一参数指定错误 无法解析
目标未解析为玩家、盔甲架或生物 失败
目标实体没有该属性,例如玩家没有 minecraft:flying_speed 失败
modifier add 的 ID 已存在 失败
modifier remove 或 modifier value get 的 ID 不存在 失败
其他情况 成功

输出

失败时成功次数、success 值和 result 值均为 0。成功时成功次数和 success 值均为 1。

  • get:result 为属性值乘以 scale 后转换成整数的值。
  • base get:result 为属性基础值乘以 scale 后转换成整数的值。
  • modifier value get:result 为修饰符值乘以 scale 后转换成整数的值。
  • base set、modifier add 和 modifier remove:result 为 1。原文输出表未单独列出 base reset。

示例

将当前实体的基础护甲值设为 5:

/attribute @s minecraft:armor base set 5

原文接着给出“将当前实体的最小缩放值设为 .5”的示例,但代码仍使用 minecraft:armor;以下按原样保留:

/attribute @s minecraft:armor base set .5

将最近生物的跟随范围设为 5:

/attribute @n[type=!player] minecraft:follow_range base set 5

本文为 Minecraft Wiki 对应英文条目的中文翻译与改编,已按要求省略变更历史。原作者与贡献者见来源页及其历史;除另有说明外,按 CC BY-NC-SA 3.0 非商业、署名、相同方式共享。