此特性為Java版獨有。
用於變更或讀取屬性。
語法
attribute <target> <attribute> [base] get [<scale>]
attribute <target> <attribute> base set <value>
attribute <target> <attribute> modifier add <uuid> <name> <value> (add|multiply|multiply_base)
attribute <target> <attribute> modifier remove <uuid>
attribute <target> <attribute> modifier value get <uuid> [<scale>]
具體用法
attribute <target> <attribute> ...
... get [<scale>]
- 返回指定屬性的總值。
... base get [<scale>]
- 返回指定屬性的基礎值。
... base set <value>
- 用給定值覆蓋指定屬性的基礎值。
... modifier (add|remove|value get)
... add <uuid> <name> <value> (add|multiply|multiply_base)
- 如果已不存在具有相同UUID的修飾符,則加入具有指定屬性的屬性修飾符。
... remove <uuid>
- 刪除具有指定UUID的屬性修飾符。
... value get <uuid> [<scale>]
- 返回具有指定UUID的修飾符的值。
參數
<target>
:entity
<attribute>
:resource_location
<scale>
:double
<uuid>
:uuid
<name>
:string
- 指定該屬性修飾器的名稱。
- 必須為字串。且必須為帶引號詞組(單個詞或者引號括起的字串,允許的字元包括:
-
、+
、.
、_
、A
-Z
、a
-z
和0
-9
)。
<value>
:double
- 指定使用的值。
- 必須為倍精度浮點數。
結果
指令 | 觸發條件 | Java版 |
---|---|---|
任意 | 不正確的參數 | 無法解析 |
<target> 無法解析為單個玩家、盔甲座、生物(指定的玩家必須線上) | 執行失敗 | |
... modifier add ... | 屬性不存在(例如玩家沒有minecraft:horse.jump_strength 屬性) | |
... modifier add ... | 修飾符已存在 | |
... modifier remove ... modifier value get ... | 修飾符不存在 | |
任意 | 執行成功時 | 變更或返回屬性值。 |
輸出
指令 | 版本 | 條件 | 成功次數 | /execute store success ... | /execute store result ... |
---|---|---|---|---|---|
任意 | Java版 | 執行失敗 | 0 | 0 | 0 |
... get [<scale>] | 執行成功 | 1 | 1 | 指定屬性的值 (乘以 <倍率> ),小數會向下取整。) | |
... base get [<scale>] | 執行成功 | 1 | 1 | 指定屬性的基礎值 (乘以 <倍率> ),小數會向下取整。) | |
... modifier value get <uuid> [<scale>] | 執行成功 | 1 | 1 | 指定屬性修飾符的值 (乘以 <倍率> ),小數會向下取整。) | |
... base set ... | 執行成功 | 1 | 1 | 1 |
示例
將自己的基礎盔甲值設定為5:
/attribute @s minecraft:generic.armor base set 5
將所有玩家的最高生命值設定為2(經典極限生存):
/execute as @a run attribute @s minecraft:generic.max_health base set 2
歷史
Java版 | |||||
---|---|---|---|---|---|
1.16 | 20w17a | 加入了/attribute 。 |
語言