本站文本内容除另有声明外,转载时均必须注明出处。(详情…本站文本内容除另有声明外,转载时均必须注明出处。(详情…中文Minecraft Wiki是完全公开的。请勇于扩充与修正内容!中文Minecraft Wiki是完全公开的。请勇于扩充与修正内容!Minecraft中文Wiki微博正在更新!或许有兴趣去看看Minecraft中文Wiki微博正在更新!或许有兴趣去看看想与其他用户进行编辑上的沟通?社区专页正是为此创建的。想与其他用户进行编辑上的沟通?社区专页正是为此创建的。翻译或创建页面之前,不妨看看译名标准化Wiki条例页面。翻译或创建页面之前,不妨看看译名标准化Wiki条例页面。需要管理员的协助?在管理员告示板留言也许可以帮到您。需要管理员的协助?在管理员告示板留言也许可以帮到您。

User:AgentKitchenSink/Sandbox

来自Minecraft Wiki
跳转至: 导航搜索

Sand JE5 BE2.png
此页为用户Fgdsiwyh的个人沙盒
你也可以随时编辑并提一些建议。我知道目前还是乱七八糟,但请勿直接删除或撤销。
Iron Shovel Revision 2.png
以下为即将到来的“命令/data”的页面
我正在赶工,欢迎过来帮忙。


Information icon.svg
此特性为Java版独有。
data
限制条件

管理员

加入版本

1.1317w45a

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

语法

/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.13 17w45b Added /data.
1.14 18w43a Added /data modify.

zh:命令/data