/data
指令允許執行者取得、合併、修改或是移除方塊、實體或指令儲存的NBT資料。
語法
/data
有四個子指令(get
、merge
、modify
、remove
)。
data ...
... get (block <targetPos>|entity <target>|storage <target>) [<path>] [<scale>]
- 取得指定NBT的值。
... merge (block <targetPos>|entity <target>|storage <target>) <nbt>
- 將指定NBT與
<nbt>
合併。 ... modify (block <targetPos>|entity <target>|storage <target>) <targetPath> ...
- 修改指定NBT ...
... append ...
- ...在列表最後插入一個值...
... insert <index> ...
- ...在列表指定位置插入一個值...
... merge ...
- ...將指定的複合NBT與另一個值合併...
... prepend ...
- ...在列表最前面插入一個值...
... set ...
- ...將NBT覆蓋為新的值...
... from (block <sourcePos>|entity <source>|storage <source>) [<sourcePath>]
- ...使用特定方塊、實體或儲存的指定NBT。
... string (block <sourcePos>|entity <source>|storage <source>) [<sourcePath>] [<start>] [<end>]
- ...使用特定方塊、實體或儲存的指定NBT中的子字串。
... value <value>
- ...使用
<value>
。
... remove (block <targetPos>|entity <target>|storage <target>) <path>
- 刪除指定NBT。
- 以多種方式展示語法
/data
- 上述可代入參數有:
<target>
=(block <targetPos> | entity <target> | storage <target>)
<修改>
=(append|insert <index>|merge|prepend|set)
<source>
=(block <sourcePos> | entity <source> | storage <source>)
/data
… get
… block <targetPos> [<path>] [<scale>]
… entity <target> [<path>] [<scale>]
… storage <target> [<path>] [<scale>]
… merge
… block <targetPos> <nbt>
… entity <target> <nbt>
… storage <target> <nbt>
… modify
… block <targetPos> <targetPath> (append|insert <index>|merge|prepend|set)
… from
… block <sourcePos> [<sourcePath>]
… entity <source> [<sourcePath>]
… storage <source> [<sourcePath>]
… string
… block <sourcePos> [<sourcePath>] [<start>] [<end>]
… entity <source> [<sourcePath>] [<start>] [<end>]
… storage <source> [<sourcePath>] [<start>] [<end>]
… value <value>
… entity <target> <targetPath> (append|insert <index>|merge|prepend|set)
… from
… block <sourcePos> [<sourcePath>]
… entity <source> [<sourcePath>]
… storage <source> [<sourcePath>]
… string
… block <sourcePos> [<sourcePath>] [<start>] [<end>]
… entity <source> [<sourcePath>] [<start>] [<end>]
… storage <source> [<sourcePath>] [<start>] [<end>]
… value <value>
… storage <target> <targetPath> (append|insert <index>|merge|prepend|set)
… from
… block <sourcePos> [<sourcePath>]
… entity <source> [<sourcePath>]
… storage <source> [<sourcePath>]
… string
… block <sourcePos> [<sourcePath>] [<start>] [<end>]
… entity <source> [<sourcePath>] [<start>] [<end>]
… storage <source> [<sourcePath>] [<start>] [<end>]
… value <value>
… remove
… block <targetPos> <path>
… entity <target> <path>
… storage <target> <path>
/data
… get (block <targetPos>|entity <target>|storage <target>) [<path>] [<scale>]
… merge (block <targetPos>|entity <target>|storage <target>) <nbt>
… modify (block <targetPos>|entity <target>|storage <target>) <targetPath> (append|insert <index>|merge|prepend|set)
… from (block <sourcePos>|entity <source>|storage <source>) [<sourcePath>]
… string (block <sourcePos>|entity <source>|storage <source>) [<sourcePath>] [<start>] [<end>]
… value <value>
… remove (block <targetPos>|entity <target>|storage <target>) <path>
/data (get (block <targetPos>|entity <target>|storage <target>) [<path>] [<scale>]|merge (block <targetPos>|entity <target>|storage <target>) <nbt>|modify (block <targetPos>|entity <target>|storage <target>) <targetPath> (append|insert <index>|merge|prepend|set) (from (block <sourcePos>|entity <source>|storage <source>) [<sourcePath>]|string (block <sourcePos>|entity <source>|storage <source>) [<sourcePath>] [<start>] [<end>]|value <value>)|remove (block <targetPos>|entity <target>|storage <target>) <path>)
data get block <targetPos> [<path>] [<scale>]
data get entity <target> [<path>] [<scale>]
data get storage <target> [<path>] [<scale>]
data merge block <targetPos> <nbt>
data merge entity <target> <nbt>
data merge storage <target> <nbt>
data modify block <targetPos> <targetPath> append from block <sourcePos> [<sourcePath>]
data modify block <targetPos> <targetPath> append from entity <source> [<sourcePath>]
data modify block <targetPos> <targetPath> append from storage <source> [<sourcePath>]
data modify block <targetPos> <targetPath> append string block <sourcePos> [<sourcePath>] [<start>] [<end>]
data modify block <targetPos> <targetPath> append string entity <source> [<sourcePath>] [<start>] [<end>]
data modify block <targetPos> <targetPath> append string storage <source> [<sourcePath>] [<start>] [<end>]
data modify block <targetPos> <targetPath> append value <value>
data modify block <targetPos> <targetPath> insert <index> from block <sourcePos> [<sourcePath>]
data modify block <targetPos> <targetPath> insert <index> from entity <source> [<sourcePath>]
data modify block <targetPos> <targetPath> insert <index> from storage <source> [<sourcePath>]
data modify block <targetPos> <targetPath> insert <index> string block <sourcePos> [<sourcePath>] [<start>] [<end>]
data modify block <targetPos> <targetPath> insert <index> string entity <source> [<sourcePath>] [<start>] [<end>]
data modify block <targetPos> <targetPath> insert <index> string storage <source> [<sourcePath>] [<start>] [<end>]
data modify block <targetPos> <targetPath> insert <index> value <value>
data modify block <targetPos> <targetPath> merge from block <sourcePos> [<sourcePath>]
data modify block <targetPos> <targetPath> merge from entity <source> [<sourcePath>]
data modify block <targetPos> <targetPath> merge from storage <source> [<sourcePath>]
data modify block <targetPos> <targetPath> merge string block <sourcePos> [<sourcePath>] [<start>] [<end>]
data modify block <targetPos> <targetPath> merge string entity <source> [<sourcePath>] [<start>] [<end>]
data modify block <targetPos> <targetPath> merge string storage <source> [<sourcePath>] [<start>] [<end>]
data modify block <targetPos> <targetPath> merge value <value>
data modify block <targetPos> <targetPath> prepend from block <sourcePos> [<sourcePath>]
data modify block <targetPos> <targetPath> prepend from entity <source> [<sourcePath>]
data modify block <targetPos> <targetPath> prepend from storage <source> [<sourcePath>]
data modify block <targetPos> <targetPath> prepend string block <sourcePos> [<sourcePath>] [<start>] [<end>]
data modify block <targetPos> <targetPath> prepend string entity <source> [<sourcePath>] [<start>] [<end>]
data modify block <targetPos> <targetPath> prepend string storage <source> [<sourcePath>] [<start>] [<end>]
data modify block <targetPos> <targetPath> prepend value <value>
data modify block <targetPos> <targetPath> set from block <sourcePos> [<sourcePath>]
data modify block <targetPos> <targetPath> set from entity <source> [<sourcePath>]
data modify block <targetPos> <targetPath> set from storage <source> [<sourcePath>]
data modify block <targetPos> <targetPath> set string block <sourcePos> [<sourcePath>] [<start>] [<end>]
data modify block <targetPos> <targetPath> set string entity <source> [<sourcePath>] [<start>] [<end>]
data modify block <targetPos> <targetPath> set string storage <source> [<sourcePath>] [<start>] [<end>]
data modify block <targetPos> <targetPath> set value <value>
data modify entity <target> <targetPath> append from block <sourcePos> [<sourcePath>]
data modify entity <target> <targetPath> append from entity <source> [<sourcePath>]
data modify entity <target> <targetPath> append from storage <source> [<sourcePath>]
data modify entity <target> <targetPath> append string block <sourcePos> [<sourcePath>] [<start>] [<end>]
data modify entity <target> <targetPath> append string entity <source> [<sourcePath>] [<start>] [<end>]
data modify entity <target> <targetPath> append string storage <source> [<sourcePath>] [<start>] [<end>]
data modify entity <target> <targetPath> append value <value>
data modify entity <target> <targetPath> insert <index> from block <sourcePos> [<sourcePath>]
data modify entity <target> <targetPath> insert <index> from entity <source> [<sourcePath>]
data modify entity <target> <targetPath> insert <index> from storage <source> [<sourcePath>]
data modify entity <target> <targetPath> insert <index> string block <sourcePos> [<sourcePath>] [<start>] [<end>]
data modify entity <target> <targetPath> insert <index> string entity <source> [<sourcePath>] [<start>] [<end>]
data modify entity <target> <targetPath> insert <index> string storage <source> [<sourcePath>] [<start>] [<end>]
data modify entity <target> <targetPath> insert <index> value <value>
data modify entity <target> <targetPath> merge from block <sourcePos> [<sourcePath>]
data modify entity <target> <targetPath> merge from entity <source> [<sourcePath>]
data modify entity <target> <targetPath> merge from storage <source> [<sourcePath>]
data modify entity <target> <targetPath> merge string block <sourcePos> [<sourcePath>] [<start>] [<end>]
data modify entity <target> <targetPath> merge string entity <source> [<sourcePath>] [<start>] [<end>]
data modify entity <target> <targetPath> merge string storage <source> [<sourcePath>] [<start>] [<end>]
data modify entity <target> <targetPath> merge value <value>
data modify entity <target> <targetPath> prepend from block <sourcePos> [<sourcePath>]
data modify entity <target> <targetPath> prepend from entity <source> [<sourcePath>]
data modify entity <target> <targetPath> prepend from storage <source> [<sourcePath>]
data modify entity <target> <targetPath> prepend string block <sourcePos> [<sourcePath>] [<start>] [<end>]
data modify entity <target> <targetPath> prepend string entity <source> [<sourcePath>] [<start>] [<end>]
data modify entity <target> <targetPath> prepend string storage <source> [<sourcePath>] [<start>] [<end>]
data modify entity <target> <targetPath> prepend value <value>
data modify entity <target> <targetPath> set from block <sourcePos> [<sourcePath>]
data modify entity <target> <targetPath> set from entity <source> [<sourcePath>]
data modify entity <target> <targetPath> set from storage <source> [<sourcePath>]
data modify entity <target> <targetPath> set string block <sourcePos> [<sourcePath>] [<start>] [<end>]
data modify entity <target> <targetPath> set string entity <source> [<sourcePath>] [<start>] [<end>]
data modify entity <target> <targetPath> set string storage <source> [<sourcePath>] [<start>] [<end>]
data modify entity <target> <targetPath> set value <value>
data modify storage <target> <targetPath> append from block <sourcePos> [<sourcePath>]
data modify storage <target> <targetPath> append from entity <source> [<sourcePath>]
data modify storage <target> <targetPath> append from storage <source> [<sourcePath>]
data modify storage <target> <targetPath> append string block <sourcePos> [<sourcePath>] [<start>] [<end>]
data modify storage <target> <targetPath> append string entity <source> [<sourcePath>] [<start>] [<end>]
data modify storage <target> <targetPath> append string storage <source> [<sourcePath>] [<start>] [<end>]
data modify storage <target> <targetPath> append value <value>
data modify storage <target> <targetPath> insert <index> from block <sourcePos> [<sourcePath>]
data modify storage <target> <targetPath> insert <index> from entity <source> [<sourcePath>]
data modify storage <target> <targetPath> insert <index> from storage <source> [<sourcePath>]
data modify storage <target> <targetPath> insert <index> string block <sourcePos> [<sourcePath>] [<start>] [<end>]
data modify storage <target> <targetPath> insert <index> string entity <source> [<sourcePath>] [<start>] [<end>]
data modify storage <target> <targetPath> insert <index> string storage <source> [<sourcePath>] [<start>] [<end>]
data modify storage <target> <targetPath> insert <index> value <value>
data modify storage <target> <targetPath> merge from block <sourcePos> [<sourcePath>]
data modify storage <target> <targetPath> merge from entity <source> [<sourcePath>]
data modify storage <target> <targetPath> merge from storage <source> [<sourcePath>]
data modify storage <target> <targetPath> merge string block <sourcePos> [<sourcePath>] [<start>] [<end>]
data modify storage <target> <targetPath> merge string entity <source> [<sourcePath>] [<start>] [<end>]
data modify storage <target> <targetPath> merge string storage <source> [<sourcePath>] [<start>] [<end>]
data modify storage <target> <targetPath> merge value <value>
data modify storage <target> <targetPath> prepend from block <sourcePos> [<sourcePath>]
data modify storage <target> <targetPath> prepend from entity <source> [<sourcePath>]
data modify storage <target> <targetPath> prepend from storage <source> [<sourcePath>]
data modify storage <target> <targetPath> prepend string block <sourcePos> [<sourcePath>] [<start>] [<end>]
data modify storage <target> <targetPath> prepend string entity <source> [<sourcePath>] [<start>] [<end>]
data modify storage <target> <targetPath> prepend string storage <source> [<sourcePath>] [<start>] [<end>]
data modify storage <target> <targetPath> prepend value <value>
data modify storage <target> <targetPath> set from block <sourcePos> [<sourcePath>]
data modify storage <target> <targetPath> set from entity <source> [<sourcePath>]
data modify storage <target> <targetPath> set from storage <source> [<sourcePath>]
data modify storage <target> <targetPath> set string block <sourcePos> [<sourcePath>] [<start>] [<end>]
data modify storage <target> <targetPath> set string entity <source> [<sourcePath>] [<start>] [<end>]
data modify storage <target> <targetPath> set string storage <source> [<sourcePath>] [<start>] [<end>]
data modify storage <target> <targetPath> set value <value>
data remove block <targetPos> <path>
data remove entity <target> <path>
data remove storage <target> <path>
參數
<targetPos>
:block_pos
<target>
:entity(僅entity <target>
模式)
- 指定需要改變NBT標籤的實體。
- 必須為玩家名、目標選擇器或UUID。且目標選擇器只允許1個實體。
<target>
:resource_location(僅storage <target>
模式)
- 指定需要改變NBT標籤的儲存。
- 必須為命名空間ID。
<path>
:nbt_path
- 指定NBT的路徑。
- 必須為NBT路徑。
<scale>
:double
- NBT具體數值的縮放倍率。
- 必須為倍精度浮點數。
<nbt>
:nbt_compound_tag
- 指定要合併的複合標籤。
- 必須為SNBT格式的複合類型NBT。
<targetPath>
:nbt_path
- 指定的NBT的合法路徑。
- 必須為NBT路徑。
<index>
:integer
- 指定一個列表中的元素位置。
- 必須為32位元整型數值。且必須在-2147483648和2147483647(含)之間。
<sourcePos>
:block_pos
<source>
:entity(僅entity <source>
模式)
- 需要使用其NBT標籤的實體。
- 必須為玩家名、目標選擇器或UUID。且目標選擇器只允許1個實體。
<source>
:resource_location(僅storage <source>
模式)
- 需要使用其NBT標籤的儲存。
- 必須為命名空間ID。
<sourcePath>
:nbt_path
- 使用NBT的合法路徑名。
- 必須為NBT路徑。
<start>
:integer
- 提取子字串時需要從源字串中包含的首個字元的索引值(從0開始)。
- 必須為32位元整型數值。且必須在0和2147483647(含)之間。
<end>
- 提取子字串時需要從源字串中排除的首個字元的索引值(從0開始)。
- 必須為32位元整型數值。且必須在0和2147483647(含)之間。
<value>
:nbt_tag
- 修改目標NBT要使用的值。必須符合資料類型。
- 必須為SNBT格式的任意類型NBT。
效果
指令 | 觸發條件 | Java版 |
---|---|---|
任意 | 參數不正確 | 無法解析 |
<targetPos> 位於世界外或未被載入 | 執行失敗 | |
位於<targetPos> 的方塊不是方塊實體 | ||
<target> 無法解析為單個實體(指定的玩家必須線上) | ||
/data get ... | 取得了多個標籤 | |
/data get ... <path> | <path> 不存在 | |
/data get ... <path> <scale> | 指定的不是數字類標籤 | |
/data merge ... | 未變更任何NBT | |
嘗試變更玩家的NBT | ||
/data remove ... | <path> 指定了根標籤 | |
/data modify ... (from|string) block ... | <sourcePos> 位於世界外或未被載入 | |
位於<sourcePos> 的方塊不是方塊實體 | ||
/data modify ... (from|string) entity ... | <source> 無法解析為單個實體(指定的玩家必須線上) | |
/data modify ... (from|string) ... <sourcePath> | <sourcePath> 不存在 | |
/data modify ... string ... <sourcePath> <start> <end> | <sourcePath> 的值不是字串且無法轉換為字串 | |
<start> 或<end> 超出範圍(0 ~ 231-1) | ||
<start> 大於<end> | ||
<end> 超出源字串最大索引值 | ||
/data modify ... append ... | 指定的標籤不是陣列或列表 | |
源資料的類型不適用於列表 | ||
/data modify ... insert <index> ... | 指定的索引無效 | |
/data modify ... merge ... | 指定的NBT不是複合標籤 | |
來源NBT不是複合標籤 | ||
任意 | 執行成功時 | 讀取、合併、修改或刪除指定NBT。 詳見下: |
若成功:
/data get
-
/data get ...
- 返回目標方塊或實體的NBT資料,並且帶有語法高亮。
- 若適用,成功時的回傳值為1。
/data get ... <path>
- 返回目標方塊或實體的一部分NBT資料,也帶有語法高亮。
- 回傳值取決於取得的NBT元素的類型。
- 取得一個數字,則回傳值為數字。
- 取得一個字串,則返回該字串的長度。
- 取得一個列表會返回該列表中元素的個數。
- 取得一個複合標籤會返回該標籤下一級子元素(不包括子元素的子元素)的數量。
/data get ... <path> <scale>
- 返回該標籤的值並乘以
<scale>
。 - 此時
<path>
需要指向一個數字類型的標籤,即該標籤的類型可以為TAG_byte
、TAG_short
、TAG_int
、TAG_long
、TAG_float
或TAG_double
。
/data merge
- 將目標方塊或實體的特定NBT資料與指定的
<nbt>
資料合併。
/data modify
-
append
- 在指定列表的末尾增加一個元素。
<targetPath>
必須指定一個TAG_list
類型的元素,源資料應該適用於作為列表中的一個元素。insert <index>
- 將資料以第
<index>
個元素插入指定列表,其後的元素的編號自動加一。 <targetPath>
必須指定一個TAG_list
類型的元素,源資料應該適用於作為列表中的一個元素。merge
- 將源資料與指定的對象合併。
<targetPath>
必須指定一個TAG_compound
類型的元素,源資料必須是TAG_compound
類型。prepend
- 在指定列表的開頭增加一個元素。
<targetPath>
必須指定一個TAG_list
類型的元素,源資料應該適用於作為列表中的一個元素。set
- 將
<targetPath>
指定的標籤設定為源資料。
- 若適用,成功時的回傳值為1。
/data remove
- 移除指定方塊或實體的
<path>
指向的NBT資料。無法移除玩家的NBT資料。 - 若適用,成功時的回傳值為1。
輸出
指令 | 版本 | 條件 | 成功次數 | /execute store success ... | /execute store result ... |
---|---|---|---|---|---|
任意 | Java版 | 執行失敗 | 0 | 0 | 0 |
/data get ... | 執行成功 | 1 | 1 | 1 | |
/data get ... <path> | 取得數字類標籤 | 1 | 1 | 向下取整後取得的值[1] | |
取得列表或陣列標籤 | 1 | 1 | 此列表或陣列含有的元素數量 | ||
取得字串標籤 | 1 | 1 | 字串的長度 | ||
取得複合標籤 | 1 | 1 | 此複合標籤含有的一級子標籤的數量 | ||
/data get ... <path> <scale> | 執行成功 | 1 | 1 | 取得的值乘以<scale> 後向下取整[2] | |
/data merge ... | 執行成功 | 1 | 1 | 1 | |
/data remove ... | 執行成功 | 1 | 1 | 1 | |
/data modify ... append ... | 執行成功 | 1 | 1 | 被加入新元素的列表或陣列的數量 | |
/data modify ... set ... | 執行成功 | 1 | 1 | 成功變更的目標標籤的數量 | |
/data modify ... merge ... | 執行成功 | 1 | 1 | 成功變更的目標複合標籤的數量 |
NBT路徑
容器
使用NBT資料儲存的指令儲存是訪問或儲存NBT資料的有效方法,且其無需透過方塊實體或實體讀取或寫入NBT資料。
每個指令儲存都儲存著通用的鍵值對。指令儲存使用命名空間ID進行區分。
/data get
和/data modify
可以讀取容器,而/data merge
、/data modify
、/data remove
和/execute store
可以寫入容器。
指令儲存也可以透過原始JSON文字讀取。
示例
- 取得執行者的飽食度:
/data get entity @s foodSaturationLevel
- 使10格內最近的物品無法被玩家撿起:
/data modify entity @e[type=item,distance=..10,limit=1,sort=nearest] PickupDelay set value -1
- 取得隨機物品的Y軸位置:
/data get entity @e[type=item,limit=1,sort=random] Pos[1]
- 取得最近玩家快捷欄第一格物品的命名空間ID:
/data get entity @p Inventory[{Slot:0b}].id
- 將距離座標(0, 64, 0)最近的海豚的護甲屬性設定為20:
/data modify entity @e[x=0,y=64,z=0,type=dolphin,limit=1] Attributes[{Name:"minecraft:generic.armor"}].Base set value 20
- 將位於(1, 64, 1)處容器內的第一個物品設定為鑽石(保留原有的其他NBT):
/data modify block 1 64 1 Items[0].id set value "minecraft:diamond_block"
- 將最近的殭屍非慣用手物品的掉落機率調整為80%,慣用手物品的掉落機率調整為0%:
/data merge entity @e[type=zombie,limit=1,sort=nearest] {HandDropChances: [0f, 0.8f]}
歷史
Java版 | |||||
---|---|---|---|---|---|
1.13 | 17w45b | 加入了/data 。 | |||
18w03a | 帶有路徑的/data get 現在適用於非數字的值。 | ||||
1.14 | 18w43a | 加入了/data modify 。 | |||
1.15 | 19w38a | 加入了指令儲存。 | |||
加入了storage <命名空間ID> 作為來源或目標。 | |||||
19w39a | 為NBT storage加入了聊天組件。 | ||||
1.19.4 | 23w03a | 加入了string 資料源。 |
注釋
語言