Minecraft Wiki

除另有声明,转载时均必须注明出处若簡繁轉換出錯,請以遊戲內為準请勇于扩充与修正内容有兴趣逛逛我们的微博沟通交流,欢迎到社区专页需要协助,请在告示板留言

了解更多

Minecraft Wiki
Advertisement

Sand
此页为用户Fgdsiwyh的个人沙盒

你也可以随时编辑并提一些建议。我知道目前还是乱七八糟,但请勿直接删除或撤销。

Iron Shovel
以下为即将到来的“命令/data”的页面

我正在赶工,欢迎过来帮忙。

Information icon
此特性为Java版独有。

命令/infobox

允许玩家获取、修改、合并或是移除实体方块数据标签。其中,修改数据标签可以是将一个标签的值设为和另一个方块或实体的某个标签的值相同,或者在一个列表中插入值,或者直接修改为一个具体的数值。

语法

/data有四个子命令(getmergemodifyremove),每个子命令提及的目标或源都是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 <目标实体> <路径>
语法树状图
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 by modify
… 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 element
  • foo.bar[0]."A [crazy name]!".baz—Specifies the child named "baz" under the that crazily named element
  • foo.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 to 5b
  • {}—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 to 4.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"

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.

History

Java版
1.1317w45bAdded /data.
1.1418w43aAdded /data modify.

zh:命令/data

Advertisement