你也可以随时编辑并提一些建议。我知道目前还是乱七八糟,但请勿直接删除或撤销。
我正在赶工,欢迎过来帮忙。
命令/infobox
允许玩家获取、修改、合并或是移除实体或方块的数据标签。其中,修改数据标签可以是将一个标签的值设为和另一个方块或实体的某个标签的值相同,或者在一个列表中插入值,或者直接修改为一个具体的数值。
- 语法
/data
有四个子命令(get
,merge
,modify
,remove
),每个子命令提及的目标或源都是block <目标方块坐标>
或entity <目标>
。
data get block <目标方块坐标> [<路径>] [<倍率>]
data get entity <目标实体> [<路径>] [<倍率>]
data merge block <目标方块坐标> <nbt>
data merge entity <目标实体> <nbt>
data modify block <目标方块坐标> <目标路径> (append|insert <索引>|merge|prepend|set) from block <源方块坐标> <路径>
data modify block <目标方块坐标> <目标路径> (append|insert <索引>|merge|prepend|set) from entity <源实体> <路径>
data modify block <目标方块坐标> <目标路径> (append|insert <索引>|merge|prepend|set) value <nbt>
data modify entity <目标实体> <目标路径> (append|insert <索引>|merge|prepend|set) from block <源方块坐标> <路径>
data modify entity <目标实体> <目标路径> (append|insert <索引>|merge|prepend|set) from entity <源实体> <路径>
data modify entity <目标实体> <目标路径> (append|insert <索引>|merge|prepend|set) value <值>
data remove block <目标方块坐标> <目标路径>
data remove entity <目标实体> <路径>
- 语法树状图
简化的语法树:
Comprehensive tree: /data
… get
… block <targetPos> [<path>] [<scale>]
… entity <target> [<path>] [<scale>]
… merge
… block <targetPos> <nbt>
… entity <target> <nbt>
… modify
… block <targetPos> <targetPath> (append|insert <index>|merge|prepend|set)
… from
… block <sourcePos> [<sourcePath>]
… entity <source> [<sourcePath>]
… value <value>
… entity <target> <targetPath> (append|insert <index>|merge|prepend|set)
… from
… block <sourcePos> [<sourcePath>]
… entity <source> [<sourcePath>]
… value <value>
… remove
… block <targetPos> [<targetPath>]
… entity <target> [<targetPath>]
Squished tree: /data
… get (block <targetPos>|entity <target>) [<path>] [<scale>]
… merge (block <targetPos>|entity <target>) <nbt>
… modify (block <targetPos>|entity <target>)<targetPath> (append|insert <index>|merge|prepend|set)
… from (block <sourcePos>|entity <source>) [<sourcePath>]
… value <value>
… remove (block <targetPos>|entity <target>) <path>
On one line: /data (get (block <targetPos>|entity <target>) [<path>] [<scale>]|merge (block <targetPos>|entity <target>) <nbt>|modify (block <targetPos>|entity <target>) (append|insert <index>|merge|prepend|set) (from (block <sourcePos>|entity <source>) <sourcePath>|value <value>)|remove (block <targetPos>|entity <target>) <path>)
- Arguments
(block <targetPos>|entity <target>)
:
<targetPos>
—The<x> <y> <z>
position of the target tile entity whose NBT is to be operated on<target>
—Valid UUID, or target selector variable for an entity whose NBT is to be operated on
get . . . [<path>] [<scale>]
:
<path>
—Valid path name defining the specific NBT to retrieve<scale>
—Scalar for the command's return value
merge . . . <nbt>
:
<nbt>
—Compound tag. The simplest valid imput is{}
.
modify . . . <targetPath> (append|insert <index>|merge|prepend|set)
:
<targetPath>
—Valid path name defining the specific target NBT to modify<index>
—Valid integer specifying an item's index within a list
… from (block <sourcePos>|entity <source>) <sourcePath>
:
<sourcePos>
—The<x> <y> <z>
position of the source block whose NBT is to be used<source>
—Valid player name, UUID, or target selector variable of a source entity whose NBT is to be used<sourcePath>
—Valid path name defining the specific source NBT to be used bymodify
… value <value>
:
<value>
—Numeric value to use in modifying the target NBT. Must match in data type
remove . . . <path>
:
<path>
—Valid path name to the NBT to remove
- See §NBT path
- Results
- Command fails if the arguments are not specified correctly.
- On success:
/data get
-
/data get . . .
- Read off the entire NBT data from the targeted block position or entity to the executor with syntax highlighting.
- If applicable, returns 1 on success.
/data get . . . <path>
- Send the subsection of the NBT data from the targeted block position or entity to the executor without syntax highlighting.
- Return value depends on the type of the NBT element:
- Retrieving a number returns that number.
- Retrieving a string returns the length of the string.
- Retrieving a list returns the number of elements in that list.
- Retrieving a compound returns the number of tags that are direct children of that compound.
/data get . . . <path> <scale>
- Return the value of the tag, scaled by <scale>.
- <path> needs to specify a numeric tag—TAG_byte, TAG_short, TAG_int, TAG_long, TAG_float, or TAG_double.
/data merge
- Merge the NBT data from the sourced block position or entity with the specified <nbt> data.
- If applicable, returns 1 on success.
/data modify
-
append
- Append the source data onto the end of the pointed-to list.
<targetPath>
must specify a tag of the TAG_list type, and the source data should be of an item type appropriate for the list.insert <index>
- Insert the source data into the pointed-to list as element
<index>
, then shift higher elements one position upwards. <targetPath>
must specify a tag of the TAG_list type, and the source data should be of an item type appropriate for the list.merge
- Merge the source data with the pointed-to object.
<targetPath>
must specify a tag of the TAG_list type, and source data must be of the TAG_compound type.prepend
- Prepend the source data onto the beginning of the pointed-to list.
<targetPath>
must specify a tag of the TAG_list type, and the source data should be of an item type appropriate for the list.set
- Set the tag specified by
<targetPath>
to the source data.
/data remove
- Removes NBT data at <path> from the targeted block position or entity. Player NBT data cannot be removed.
- If applicable, returns 1 on success.
NBT path
An NBT data path is a descriptive label used to specify any particular element from an NBT data tree. A path has the general form superTag.childTag.childTag……parentTag.tag
, where tag
is the specified tag and superTag
is one of the most superficial tags.
After each key, it is possible to give an NBT object which gets compared to the value of that tag. The tag only is targeted by the path if the comparison has a positive result.
When defining an element from a list, brackets are used after the key of the list. The content of the brackets can be one of 3 things:
- Blank space—This returns every element in the list.
- An index number—For a nonnegative index n, this returns the (n + 1)th element in the list. For a negative index n, this returns the nth element from the end of the list.
- An NBT compound. This returns all objects in the list that match the specifications of that compound.
The valid character set for a path seems to be all non-whitespace characters, as long as any opening brackets and braces ([
and {
) are closed and at the end of each term (that is, followed by nothing but a period or the end of the path—.
or
). That being said, the reasonable character set for defining a data tag would be: a-z A-Z 0-9 _ . [ ] { }
(To put this as a Regular expression, [][}{a-zA-Z0-9.]*
) "Quoted strings" may be used if a name of a key needs to be escaped.
Examples
Fubar example:
/data get entity @p foo.bar[0]."A [crazy name]!".baz
These names have been arbitrarily picked, for demonstrative purposes.
foo
—Specifies the top-level element named "foo"foo.bar
—Specifies foo's child named "bar". Let's pretend this is a list.foo.bar[0]
—Specifies the first element of the list "bar"foo.bar[0]."A [crazy name]!"
—Specifies the child named "A [crazy name]!" under the that first elementfoo.bar[0]."A [crazy name]!".baz
—Specifies the child named "baz" under the that crazily named elementfoo.bar[]
—Specifies all elements of the list "bar"foo.bar[].baz
—Specifies the children of all elements of the list "bar"foo.bar[{baz:5b}]
—Specifies all elements of the list "bar" of which the "baz" tag is set to5b
{}
—Specifies the root tag of the targeted entity or block{foo:4.0f}
—Specifies the root tag of the targeted entity or block if the "foo" tag is set to4.0f
foo{bar:"baz"}
—Specifies the "foo" tag if its child "bar" has the value"baz"
foo{bar:"baz"}.bar
—Specifies the "bar" tag if it matches the value"baz"
The tree structure
- The root entity data
- foo: The "foo" element
- bar: The "bar" element
- The first element of list "bar"
- A [crazy name]!: The "A [crazy name]!" element
- baz: The "baz" element; the target element of this example.
- A [crazy name]!: The "A [crazy name]!" element
- Another unrelated element in list "bar"
- The first element of list "bar"
- bar: The "bar" element
- foo: The "foo" element
Book-in-a-chest example:
/data get block ~ ~ ~ Items[1].tag.pages[3]
The player has written a book and placed it inside a chest at her feet. She's going to work up to the above command in stages.
Chat log * Alex jumps on top of a chest. * Alex runs the command: /data get block ~ ~ ~ 0 55 0 has the following block data: {x: 0, y: 55, z: 0, Items: [{Slot: 0b, id: "clock", Count: 1b}, {Slot: 9b, id: "written_book", Count: 1b, tag: {pages: ['{"text":"\'twas brillig and the slithy toves"}', '{"text":"Did gyre and gimble in the wabe."}', '{"text":"All mimsy were the borogoves,"}', '{"text":"And the mome raths outgrabe."}'], author: "LewisCarroll", title: "Jabberwocky"}}], id: "chest"} * Alex only wants to look at the chest's inventory. She could search the Official Minecraft Wiki for what the name of that tag is, but because she understands how to read NBT format, she decides to figure it out from that last command's output. * Alex runs the command: /data get block ~ ~ ~ Items 0 55 0 has the following block data: {x: 0, y: 55, z: 0, Items: [{Slot: 0b, id: "clock", Count: 1b}, {Slot: 9b, id: "written_book", Count: 1b, tag: {pages: ['{"text":"\'twas brillig and the slithy toves"}', '{"text":"Did gyre and gimble in the wabe."}', '{"text":"All mimsy were the borogoves,"}', '{"text":"And the mome raths outgrabe."}'], author: "LewisCarroll", title: "Jabberwocky"}}], id: "chest"} * Alex wants to narrow this down to the second item in the chest. She starts counting from 0, so the second item would be element 1. * Alex runs the command: /data get block ~ ~ ~ Items[1] 0 55 0 has the following block data: {x: 0, y: 55, z: 0, Items: [{Slot: 0b, id: "clock", Count: 1b}, {Slot: 9b, id: "written_book", Count: 1b, tag: {pages: ['{"text":"\'twas brillig and the slithy toves"}', '{"text":"Did gyre and gimble in the wabe."}', '{"text":"All mimsy were the borogoves,"}', '{"text":"And the mome raths outgrabe."}'], author: "LewisCarroll", title: "Jabberwocky"}}], id: "chest"} * Alex wants just the "tag" tag. * Alex runs the command: /data get block ~ ~ ~ Items[1].tag 0 55 0 has the following block data: {x: 0, y: 55, z: 0, Items: [{Slot: 0b, id: "clock", Count: 1b}, {Slot: 9b, id: "written_book", Count: 1b, tag: {pages: ['{"text":"\'twas brillig and the slithy toves"}', '{"text":"Did gyre and gimble in the wabe."}', '{"text":"All mimsy were the borogoves,"}', '{"text":"And the mome raths outgrabe."}'], author: "LewisCarroll", title: "Jabberwocky"}}], id: "chest"} * Alex wants just the "pages" tag. * Alex runs the command: /data get block ~ ~ ~ Items[1].tag.pages 0 55 0 has the following block data: {x: 0, y: 55, z: 0, Items: [{Slot: 0b, id: "clock", Count: 1b}, {Slot: 9b, id: "written_book", Count: 1b, tag: {pages: ['{"text":"\'twas brillig and the slithy toves"}', '{"text":"Did gyre and gimble in the wabe."}', '{"text":"All mimsy were the borogoves,"}', '{"text":"And the mome raths outgrabe."}'], author: "LewisCarroll", title: "Jabberwocky"}}], id: "chest"} * Alex wants just the fourth element from this list. * Alex runs the command: /data get block ~ ~ ~ Items[1].tag.pages[3] 0 55 0 has the following block data: {x: 0, y: 55, z: 0, Items: [{Slot: 0b, id: "clock", Count: 1b}, {Slot: 9b, id: "written_book", Count: 1b, tag: {pages: ['{"text":"\'twas brillig and the slithy toves"}', '{"text":"Did gyre and gimble in the wabe."}', '{"text":"All mimsy were the borogoves,"}', '{"text":"And the mome raths outgrabe."}'], author: "LewisCarroll", title: "Jabberwocky"}}], id: "chest"} * Alex has what she needs now... She uses the paths she's gathered to edit the book from outside the chest. * Alex runs the command: /data modify block ~ ~ ~ Items[1].tag.pages[3] set value '{"text":"And this pig here\'s named Babe."}' Modified block data of 0 55 0 * Alex runs the command: /data modify block ~ ~ ~ Items[1].tag.pages prepend value '{"text":"Call me Ishmael."}' Modified block data of 0 55 0 * Alex runs the command: /data modify block ~ ~ ~ Items[1].tag.author set value "Cthulhu the Sleeper"
History
Java版 | |||||
---|---|---|---|---|---|
1.13 | 17w45b | Added /data . | |||
1.14 | 18w43a | Added /data modify . |
zh:命令/data