この項目はJava Edition限定の要素です。
ブロックエンティティおよびエンティティのNBTデータの取得(get)、併合(merge)、編集(modify)、削除(remove)を行う。
構文[]
/dataには4つの命令文(get、merge、modify、remove)があり、それぞれの命令で対象/参照元にblock <targetPos>、entity <target>、storage <target>を選択できる。
/data ...... get... (block <targetPos>|entity <target>|storage <target>) [<path>] [<scale>]<taegetPos>座標のブロック、<target>で指定したエンティティ、<target>で指定したストレージのNBTデータ全体もしくは一部を取得する。<scale>が指定されている場合その値でスケーリング(乗算)される.
... merge... (block <targetPos>|entity <target>|storage <target>) <nbt><taegetPos>座標のブロック、<target>で指定したエンティティ、<target>で指定したストレージのNBTデータを<nbt>で指定したデータで併合(merge)する。
... modify (block <targetPos>|entity <target>|storage <target>) <targetPath> ...... append from (block <sourcePos>|entity <source>|storage <source>) [<sourcePath>]... append string (block <sourcePos>|entity <source>|storage <source>) [<sourcePath>] [<start>] [<end>]... append value <value>- 参照元のデータを対象のリストの末尾に追加する。
... insert <index> from (block <sourcePos>|entity <source>|storage <source>) [<sourcePath>]... insert <index> string (block <sourcePos>|entity <source>|storage <source>) [<sourcePath>] [<start>] [<end>]... insert <index> value <value>- 参照元のデータを対象のリストの
<index>の位置に挿入する、リストにある挿入位置以上の<index>は末尾方向にずれる。
- 参照元のデータを対象のリストの
... merge from (block <sourcePos>|entity <source>|storage <source>) [<sourcePath>]... merge string (block <sourcePos>|entity <source>|storage <source>) [<sourcePath>] [<start>] [<end>]... merge value <value>- 参照元のデータで対象のリストを併合する。
... prepend from (block <sourcePos>|entity <source>|storage <source>) [<sourcePath>]... prepend string (block <sourcePos>|entity <source>|storage <source>) [<sourcePath>] [<start>] [<end>]... prepend value <value>- 参照元のデータを対象のリストの先頭に追加する。リストのデータは末尾方向にずれる。
... set from (block <sourcePos>|entity <source>|storage <source>) [<sourcePath>]... set string (block <sourcePos>|entity <source>|storage <source>) [<sourcePath>] [<start>] [<end>]... set value <value>- 指定した
<targetPath>のデータを参照元のデータに設定する。
- 指定した
... remove... (block <targetPos>|entity <target>|storage <target>) <path><taegetPos>座標のブロック、<target>で指定したエンティティ、<target>で指定したストレージの<path>にあるデータを削除する。プレイヤーのNBTデータは削除できない。
様々な形式での表記
Simplified tree: /data- where substituted arguments are:
<TARGET>=(block <targetPos> | entity <target> | storage <target>)<MODIFICATION>=(append|insert <index>|merge|prepend|set)<SOURCE>=(block <sourcePos> | entity <source> | storage <source>)
Squished tree: /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>
Maximised: 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 <nbt>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 <nbt>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 <nbt>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 <nbt>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 <nbt>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>:ブロック座標- NBTデータ操作の対象とするブロックエンティティの座標。
- 整数またはチルダ・キャレット表記法で表記された<x>、<y>、<z>でブロック座標を指定する。
<target>:エンティティ (inentity <target>mode)- NBTデータ操作の対象とするエンティティの指定。
- プレイヤー名、ターゲットセレクターまたはUUIDで指定する。また、ターゲットセレクターは単一のものである必要がある。
<target>:resource_location (instorage <target>mode)- NBTデータ操作の対象とするストレージの指定。
- 名前空間IDで指定する。
<nbt>:Compound型のNBT- 併合の参照元にするcompound tagを指定する。
- SNBTフォーマットのcompound NBTで指定する。
<index>:32ビット整数- リスト内の添字を指定する。
- 32ビットの整数値で指定する。また、値は-2,147,483,648以上2,147,483,647以下で指定する。
<sourcePos>:ブロック座標- NBTを参照するブロックエンティティの座標を指定する。
- 整数またはチルダ・キャレット表記法で表記された<x>、<y>、<z>でブロック座標を指定する。
<source>:エンティティ (inentity <source>mode)modifyのNBT参照元にするエンティティを指定する。- プレイヤー名、ターゲットセレクターまたはUUIDで指定する。また、ターゲットセレクターは単一のものである必要がある。
<source>:resource_location (instorage <source>mode)modifyのNBT参照元にするストレージを指定する。- 名前空間IDで指定する。
<start>:32ビット整数- 文字列に含める最初の文字の位置を前から何文字目かで指定する。負の数を指定した場合は、後ろから何文字目かを指定したものとしてみなされる。
- 32ビットの整数値で指定する。また、値は-2,147,483,648以上2,147,483,647以下で指定する。
<end>:32ビット整数- 文字列から除外する最初の文字の位置を前から何文字目かで指定する。負の数を指定した場合は、後ろから何文字目かを指定したものとしてみなされる。
- 32ビットの整数値で指定する。また、値は-2,147,483,648以上2,147,483,647以下で指定する。
結果[]
| コマンド | トリガー | Java Edition |
|---|---|---|
| 任意 | 引数の指定が正しくない場合 | 構文解析不能 |
<targetPos>がロードされた範囲でないもしくはワールドの外の場合 | 失敗 | |
<targetPos>のブロックがブロックエンティティでない場合 | ||
<target>で1つ以上の(in entity <target> mode)に解決できない場合(名前のついたプレイヤーはオンラインでなければならない) | ||
/data get ... | 複数のタグが取得された場合 | |
/data get ... <path> | <path>が存在しない場合 | |
/data get ... <path> <scale> | 取得したタグが数値でない場合 | |
/data merge ... | 変更点がない場合 | |
| プレイヤーのデータを編集しようとした場合 | ||
/data remove ... | <path>が複合タグのルートだった場合 | |
/data modify ... (from|string) block ... | <sourcePos>のブロックがブロックエンティティでない場合 | |
<sourcePos>のブロックがブロックエンティティでない場合 | ||
/data modify ... (from|string) entity ... | <sourceEntity>で1つ以上のエンティティに解決できない場合(名前のついたプレイヤーはオンラインでなければならない) | |
/data modify ... (from|string) ... <sourcePath> | <sourcePath>が存在しない場合 | |
/data modify ... append ... | 対象のタグがリストや配列でない場合 | |
| 参照元のデータ型がリストに追加できる型でない場合 | ||
/data modify ... string ... <sourcePath> <start> <end> | <sourcePath>が文字列でないか、文字列への変換が不能な場合 | |
<start>や<end>が0〜231-1の範囲外の場合 | ||
<start>が<end>より大きい場合 | ||
<end>が文字列長より大きい場合 | ||
/data modify ... insert <index> ... | <index>が無効な場合 | |
/data modify ... merge ... | 編集対象に指定の複合タグがない場合 | |
| 参照元のデータが複合タグでない場合 | ||
| 任意 | 成功時 | NBTデータを取得、併合、編集、削除する。 |
出力[]
| コマンド | エディション | 状況 | 成功回数 | /execute store success ... | /execute store result ... |
|---|---|---|---|---|---|
| 任意 | Java Edition | 失敗 | 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 | 編集に成功した複合タグの数 |
使用例[]
- 実行者の満腹度を取得する:
/data get entity @s foodSaturationLevel
- 10ブロック以内に落ちているアイテムのうち最も近い位置のものをプレイヤーが拾えないようにする:
/data modify entity @e[type=item,distance=..10,limit=1,sort=nearest] PickupDelay set value -1
- 落ちているアイテムのうちランダムで選んだ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)から最も近いイルカの防御力(attribute)を20に設定する:
/data modify entity @e[x=0,y=64,z=0,type=dolphin,limit=1] Attributes[{Name:"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]}
- 最も近いゾンビが死んだ時左手のアイテムを80%の確率でドロップするように設定するが、右手のアイテムの確率は変更しない:
/data modify entity @e[type=zombie,limit=1,sort=nearest] HandDropChances[1] set value 0.8f
ストレージ[]
「command storage format」も参照
NBTデータのコマンドストレージはブロックエンティティやエンティティへの書き込みや読み込み負荷なしに、commandsで効率的にNBTデータにアクセスできる方法です。
それぞれのコマンドストレージは、汎用のキーとデータがセットになった形式で、意図しない競合を防ぐためにresource locationによって識別される。
/data get と /data modify はストレージから読み込みが、/data merge、 /data modify、/data remove、/execute store はストレージに書き込むことができる。
コマンドストレージはJSON textを用いても同じ様にアクセスできる。
歴史[]
| Java Edition | |||||
|---|---|---|---|---|---|
| 1.13 | 17w45b | /dataが追加された。 | |||
| 17w47a | コマンド /blockdata と /entitydata が削除され /data に併合された。 | ||||
| 18w03a | /data get (block|entity|storage) とpathを用いて数字でない値も取得できるようになった。 | ||||
| 1.14 | 18w43a | /data modify (block|entity|storage)が追加された。 | |||
| 1.15 | 19w38a | storage <resource location>が参照元、対象として追加された。 | |||
| 1.19.4 | 23w03a | stringが参照方式として追加された。 | |||
| 1.20 | Pre-release 1 | string構文において、負の値を指定した場合に末尾から数えた場所の値を指定したものとして見做されるようになった。 | |||
注釈[]