vim-castle/home/.vim/vimwiki/vimwiki/minecraft-command-Usage.wiki

344 lines
24 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

== Command Usage ==
* 1.1 Tilde notation
* 1.2 Target selectors
* 1.2.1 Target selector variables
* 1.2.2 Target selector arguments
* 1.3 Data tags
* 1.4 Raw JSON text
=== Usage ===
In a regular Minecraft client or the stand alone client, commands are entered via Minecraft's chat window, which is displayed by pressing the T key (default) or / key. Using the / key will also enter the forward slash that commands require as a prefix, so it is a useful shortcut. Pressing Tab ↹ while entering commands cycles through possible commands or arguments.
Commands may also be entered in a multiplayer server's console, but are not preceded by a / when entered this way. Commands in command blocks can be preceded by a slash, but it is not required. Commands in a command block may also require an optional argument, usually a player's username.
The majority of commands are only available in the following situations:
* In a Minecraft multiplayer server game, entered by an operator or command block.
* In other multiplayer games, entered by the player who opened a LAN game with cheats enabled, or is hosting their own multiplayer server
* In singleplayer, if cheats were enabled at world creation (via the "More World Options..." button).
Some player commands are also available in singleplayer even when cheats are not enabled.
Note: In singleplayer worlds where cheats were not enabled at creation, they can be enabled on a temporary basis by opening the current game session to LAN play ( Esc -> "Open to LAN", then "Allow Cheats" button and "Start LAN World"). You do not actually need to be on a LAN or have others join. This is not permanent, but will allow the use of commands until you quit the world, and changes you make via commands (items spawned, etc.) will be saved with the world. You can do this each time you start playing the world again. Note that this will disable game pausing for the duration, so while open to LAN, you should get somewhere safe or reload your world before using the Game Menu. Remember that you can disable your LAN world by reloading the world.
==== Tilde notation ====
Many commands allow relative coordinates to be specified using tildes (~). A number following a tilde is an offset from something rather than a coordinate. The sign of the offset specifies whether to go in the positive or negative direction for that axis. A single tilde by itself is shorthand for ~0.
For example, tp 0 64 0 will teleport the user to the coordinate (0, 64, 0), while tp ~3 ~ ~-3 will teleport the user to a position +3 blocks in the "x" direction (i.e., east), keep their current height, and -3 blocks in the "z" direction (i.e., north).
Usually absolute coordinates can be mixed with relative coordinates. For example, tp ~ 64 ~ will keep the user's "x" and "z" coordinates the same, but teleport them to absolute height 64.
The origin for the offset depends on the command. For example, for [[minecraft-command-tp|/tp]] the offset is from the starting position. Other common offsets include from the position of the command's execution or from another coordinate specified by the command.
==== Target selectors ====
In most commands where a player may be specified as an argument, it is possible to "target" one or more players satisfying certain conditions instead of specifying players by name. To target players by condition, choose a target selector variable and, optionally, one or more target selector arguments to modify the conditions to be satisfied.
For example, to change the game mode of all players on team Red to creative mode, instead of specifying them by name individually:
[[minecraft-command-gamemode|/gamemode]] creative @a[team=Red]
===== Target selector variables =====
Summary of target selector variables Variable Function
@p nearest player
@r random player
@a all players
@e all entities
A target selector variable identifies the broad category of targets to select. There are four variables:
@p
Targets the nearest player. If there are multiple nearest players, caused by them being precisely the same distance away, a player is selected by the time the player most recently joined the server.
Target selector arguments may be used to reduce the set of players from which the nearest player will be selected. For example, @p[team=Red] will target the nearest player on team Red even if there are other players closer.
The c target selector argument can be used to increase the number of nearest players targeted (for example, @p[c=3] will target the three nearest players). When negative, c will reverse the order of targeting (for example, @p[c=-1] will target the farthest player).
@r
Targets a random player (or entity with the type target selector argument).
Target selector arguments may be used to reduce the set of players from which a random player will be targeted. For example, @r[team=Red] will only target a random player from team Red.
The c target selector argument can be used to increase the number of random players targeted. For example, @r[c=3] will target three random players.
When used without the type argument, @r always targets a random player. The type argument can be used to target non-player entities (for example, @r[type=Zombie] will target a random zombie, @r[type=!Player] will target a random non-player entity, @r[type=!Zombie] will target a random non-zombie, etc.).
@a
Targets all players.
Target selector arguments may be used to reduce the set of players targeted. For example, @a[team=Red] will only target players on team Red.
@e
Targets all entities (including players).
Target selector arguments may be used to reduce the set of entities targeted. For example, @e[type=Cow] will only target cows.
===== Target selector arguments =====
Summary of target selector arguments Argument(s) Selection criteria
x, y, z coordinate
r, rm radius (max, min)
m game mode
c count
l, lm experience level (max, min)
score_name max score
score_name_min min score
team team name
name entity name
dx, dy, dz volume dimensions
rx, rxm vertical rotation (max, min)
ry, rym horizontal rotation (max, min)
type entity type
After using a target selector, you can optionally use arguments to modify the set of targets selected. When used with @a or @e, arguments narrow down the number of targets from the full list to a specific few. When used with @p or @r, arguments narrow the number of targets down from the full list to a smaller set from which the nearest or random player is selected.
Add argument-value pairs as a comma-separated list contained within square brackets after the target selector variable:
@<variable>[<argument>=<value>,<argument>=<value>,…].
Spaces are not allowed around the brackets, equal signs, or commas, and only commas may be used to separate argument-value pairs.
Arguments are case-sensitive and unsupported arguments are silently ignored. For example, kill @e[type=Creeper,r=20] will kill all creepers in a 20-block radius, but kill @e[Type=Creeper,r=20] ('type' capitalized) will kill all entities (including players) in that radius because there is no longer an argument limiting the targets to just creepers.
If the first few arguments (up to four) are specified simply as values without identifying the arguments, they are assumed to be, in order, x, y, z, and r. Thus, the following two commands are identical:
[[minecraft-command-gamemode|/gamemode]] creative @a[x=10,y=20,z=30,r=4]
[[minecraft-command-gamemode|/gamemode]] creative @a[10,20,30,4]
====== Selecting targets by coordinate ======
[x=X,y=Y,z=Z] — Selects targets based on distance to that exact position. Combine with selecting by radius to select only targets at that specific position.
The coordinates have to be exact - tilde notation is not available for selector argument coordinates.
====== Selecting targets by radius ======
[r=R] — Selects only targets less than R blocks from the command's execution.
[rm=RM] — Selects only targets more than RM blocks from the command's execution.
If a coordinate (above) and either or both radius/i are both defined, the radius/i will center on the coordinate rather than the postion of the command's execution. By using a very distant coordinate and a very large radius, it is possible to simulate a near-linear edge to use to specify targets.
====== Selecting targets by game mode ======
[m=M] — Selects only targets with the specified game mode. Permitted value for M are:
-1: all game modes
0: survival mode
1: creative mode
2: adventure mode
3: spectator mode
====== Selecting targets by count ======
[c=C] — Selects only the specified number of targets. Usually in order of distance from the command executor.
When used with @p or @r, this argument defaults to 1, so using a higher number will increase the number of nearest or random targets returned. When used with @a or @e, this argument returns only the nearest targets.
If there are multiple nearest players, caused by them being precisely the same distance away, a player is selected by the time the player most recently joined the server. For example, if equally distant, @a[c=1] will select the player who has been on the server the longest and @e[type=Creeper,c=3] will select the three oldest creepers.
When used with a negative value, the order of targets is reversed. For example, @p[c=-3] will return the three farthest targets, and, if all potential targets are equally far away, @e[c=-3] will select the last three targets created.
====== Selecting targets by experience level ======
[l=L] — Selects only targets with no more than L experience levels.
[lm=LM] Selects only targets with no less than LM experience levels.
====== Selecting targets by score ======
[score_name=SCORE] — Selects only targets with a score in objective name of no more than SCORE.
[score_name_min=SCOREMIN] — Selects only targets with a score in objective name of no less than SCOREMIN.
For example, @a[score_points_min=30,score_points=39] will select all players with a score in objective "points" between 30 and 39 (inclusive).
See also: Scoreboard#Objectives
====== Selecting targets by team ======
[team=TEAM] — Selects only targets on team TEAM.
[team=!TEAM] — Selects only targets not on team TEAM.
[team=] — Selects only targets not on any team.
See also: Scoreboard#Teams
====== Selecting targets by name ======
[name=NAME] — Selects only targets named NAME.
[name=!NAME] — Selects only targets not named NAME.
====== Selecting targets by volume ======
[dx=DX,dy=DY,dz=DZ]
Selects only targets within the volume defined as starting from the location where the command was executed and extending DX blocks in the positive "x" direction (i.e., east), DY blocks in the positive "y" direction (i.e., upwards), and DZ blocks in the positive "z" direction (i.e., south). All values must be positive. If an initial coordinate is specified with the x, y, and z arguments, that will be used instead of the position of the command's execution for the lower northwestern corner (dx, dy, and dz still specify distances from that coordinate; they do not specify a separate coordinate).
It is possible to combine selection by radius and selection by volume, in which case the command will only select targets within the overlap of both regions (within certain radius/i of the volume's lower northwest corner and not outside the defined volume).
====== Selecting targets by vertical rotation ======
[rx=RX] — Selects only targets with a maximum vertical rotation of RX.
[rxm=RXM] — Selects only targets with a minimum vertical rotation of RXM.
Vertical rotation values vary from -90.0 facing straight up to 90.0 facing straight down (thus vertical rotation values increase with rotation downwards).
====== Selecting targets by horizontal rotation ======
[ry=RY] — Selects only targets with a maximum horizontal rotation of RY.
[rym=RYM] — Selects only targets with a minimum horizontal rotation of RYM.
Horizontal rotation values vary from -180.0 (facing due north), to -90.0 (facing due east), to 0.0 (facing due south), to 90.0 (facing due west), to 179.9 (just west of due north) before wrapping back to -180.0 (thus horizontal rotation values increase with rotation to the right, or clockwise viewed from above).
====== Selecting targets by type ======
[type=TYPE] — Selects only targets of the specific entity type.
[type=!TYPE] — Selects only targets not of the specific entity type.
TYPE must be an entity ID used to identify different types of entities internally (for example, Creeper for creepers, MinecartRideable for regular minecarts, PrimedTnt for primed TNT, etc.). Entity IDs are case-sensitive and invalid entity IDs will cause the command to fail.
When used with @r, can change its normal behavior of targeting only players to target other entities.
==== Data tags ====
A data tag is a sequence of text which describes a data structure using attribute-value pairs. Data tags are used in commands to specify complex data for players, entities, and some blocks.
A data tag consists of zero or more attribute-value pairs separated by commas and delineated by curly brackets. Each attribute-value pair consists of an attribute name and the attribute's value, separated by a colon. Some values, however, may themselves contain attribute-value pairs, allowing a data tag to describe a hierarchical data structure.
Example: {name1:123,name2:"sometext",name3:{subname1:456,subname2:789}}
The data structures that data tags describe are the same ones used in Minecraft's save files. These data structures are described in other articles and commands expect data tags to use the same attribute names (which are case-sensitive):
Data Structure Specification Links Objects Examples
Tile entities chests, furnaces, command blocks, mob spawners, signs, etc.
Items items in inventories (includes specifications for enchantments, lore, custom names, etc.)
Item entities items on the ground
Mobs creepers, cows, villagers, etc.
Projectiles arrows, fireballs, thrown potions, etc.
Vehicles boats, minecarts, etc.
Dynamic tiles primed TNT, falling sand/gravel
Other entities firework rockets, paintings, and item frames
The defined data structures also expect the values to be of the correct type.
Data Tags Value Types Type Description
Byte An integer between -128 and 127 (inclusive).
Short An integer between -32,768 and 32,767 (inclusive).
Int An integer between -2,147,483,648 and 2,147,483,647 (inclusive).
Long An integer between -9,223,372,036,854,775,808 and 9,223,372,036,854,775,807 (inclusive).
Float
Double Numbers which can have a decimal portion (for example, 3.14159).
String A sequence of text, optionally delineated with double quotes.
Double quotes must be used if the String contains commas, curly brackets, or square brackets. To include a double quote inside a String, add a backslash before the double quote.
Example: "Call me \"Ishmael\""
List A sequence of values, separated by commas and delineated with square brackets. The values do not necessarily need to be all the same type -- the types required are specified by the data structure.
Example: [3.2,64,129.5]
Byte Array A sequence of integers between -128 and 127 (inclusive), separated by commas and delineated with square brackets.
Int Array A sequence of integers between -2,147,483,648 and 2,147,483,647 (inclusive), separated by commas and delineated with square brackets.
Compound A sequence of attribute-value pairs, separated by commas and delineated with curly brackets.
Example: {X:3,Y:64,Z:129}
Every data tag argument is itself a Compound.
Some commands may require that a number's type be specified by adding a character to the end of the value. For example, 3i for an int, 3.2f for a float, etc.
When commands such as [[minecraft-command-testfor|/testfor]], [[minecraft-command-testforblock|/testforblock]], and [[minecraft-command-clear|/clear]] are used to match data tags, they only check for the presence of the provided tags in the target entity/block/item. This means that the entity/block/item may have additional tags and will still match. This is true even for lists and arrays: the order of a list is not acknowledged, and as long as every requested element is in the list, it will match even if there are additional elements.
The format used for data tags is a lenient form of JSON.
==== Raw JSON text ====
The [[minecraft-command-tellraw|/tellraw]] and [[minecraft-command-title|/title]] commands use a specific lenient JSON format to specify complicated text. Similar to the NBT format notation above, concepts such as Strings, Objects (Compounds), and Lists are used to represent the various properties of the raw text.
The format of raw JSON text is a JSON Object which supports the following (mostly optional) elements:
The base chat component Object
text: A string representing raw text to display directly in chat. Note that selectors such as "@a" and "@p" are not translated into player names; use selector instead. "\n" is newline (enter).
extra: A list of additional objects, sharing the same format as the base object.
A list element with the same format as the base object (recursive). Note that all properties of this object are inherited by children except for text, extra, translate, with, and score. This means that children will retain the same formatting and events as this object unless they explicitly override them.
color: The color to render this text in. Valid values are "black", "dark_blue", "dark_green", "dark_aqua", "dark_red", "dark_purple", "gold", "gray", "dark_gray", "blue", "green", "aqua", "red", "light_purple", "yellow", "white", and "reset" (cancels out the effects of colors used by parent objects). Technically, "bold", "underline", "italic", "strikethrough", and "obfuscated" are also accepted, but it may be better practice to use the tags below for such formats.
bold: Boolean (true/false) - whether to render text in bold. Defaults to false.
underlined: Boolean (true/false) - whether to render text underlined. Defaults to false.
italic: Boolean (true/false) - whether to render text in italics. Defaults to false.
strikethrough: Boolean (true/false) - whether to render text with a strikethrough. Defaults to false.
obfuscated: Boolean (true/false) - whether to render text obfuscated. Defaults to false.
insertion: When the text is shift-clicked by a player, this string will be inserted in their chat input. It will not overwrite any existing text the player was writing.
clickEvent: Allows for events to occur when the player clicks on text.
action: The action to perform when clicked. Valid values are "open_url" (opens value as a URL in the player's default web browser), "run_command" (has value entered in chat as though the player typed it themselves. This can be used to run commands, but the command will fail if the player does not have the required permissions to use it), "change_page" (can only be used in written books, changes to page value if that page exists), and "suggest_command" (similar to "run_command", but the text only appears in the player's chat input, and is not automatically entered. Unlike insertion, this will replace the existing contents of the chat input).
value: The URL, chat, or command used by the specified action. Note that commands must be prefixed with the usual "/" slash.
hoverEvent: Allows for a tooltip to be displayed when the player hovers their mouse over text.
action: The type of tooltip to show. Valid values are "show_text" (shows raw JSON text), "show_item" (shows the tooltip of an item which can have NBT tags), "show_achievement" (shows formatted text describing an achievement or statistic. Normal achievement names are green, final achievement names are dark_purple, and statistic names are gray. In addition, a description is given for achievements), and "show_entity" (shows an entity's name, possibly its type, and its UUID).
value: The formatting of this tag varies depending on the action. Note that "show_text" is the only action to support an Object as the value; all other action values are Strings and should thus be wrapped in quotes.
"show_text": Can be either a raw String of text, or an Object with the same formatting as this base object. Note that clickEvent and hoverEvent do not function within the tooltip, but the formatting and extra tags still work.
"show_item": A string formatted like item NBT data. Contains the "id" tag, and optionally the "Damage" tag and "tag" tag (which is the same compound used as "dataTag" in the [[minecraft-command-give|/give]] command).
"show_achievement": The achievement or statistic's name. This uses the same format as achievement and statistic Scoreboard objective criteria and the [[minecraft-command-achievement|/achievement]] command.
"show_entity": A string formatted like a compound with the string values "type" (such as "Zombie"), "name", and "id" (should be an entity UUID, but can actually be any string).
translate: The translation identifier of text to be displayed using the player's selected language. This identifier is the same as the identifiers found in lang files from assets or resource packs. The translated text will only be displayed if the text string is not used.
with: A list of chat component arguments and/or string arguments to be used by translate.
The arguments are text corresponding to the arguments used by the translation string in the current language, in order (for example, the first list element corresponds to "%1$s" in a translation string).
score: A compound for displaying a player's score in an objective. Displays nothing if the player is not tracked in the given objective. Ignored completely if text or translate is present.
name: The name of the player whose score should be displayed. Selectors (such as @p) can be used, in addition to "fake" player names created by the scoreboard system. In addition, if the name is "*", it will show the player's own score (for example, [[minecraft-command-tellraw|/tellraw]] @a {score:{name:"*",objective:"obj"}} will show every online player their own score in the "obj" objective). Note that non-player entity scores (such as @e[type=Cow]) do not show, even if the entity has been given a score in the objective.
objective: The internal name of the objective to display the player's score in.
value: Optional. If present, this value is used regardless of what the score would have been.
selector: A string containing a selector (@p,@a,@r, or @e) and, optionally, selector arguments. Unlike text, the selector will be translated into the correct player/entity names. If more than one player/entity is detected by the selector, it will be displayed in a form such as 'Name1 and Name2' or 'Name1, Name2, Name3, and Name4'. Ignored completely if text, translate, or score is present.
Due to the extra tag, the above format may be recursively nested to produce very complex and functional text strings. However, a raw json text doesn't have to be complicated at all: virtually all properties are optional and may be left out.
To be valid, each object must have at least either text, translate, or score (everything else is optional). As a matter of shorthand, however, the entire Object may be substituted with a String. In this case, that string will be considered the value of the text property. For example, "This is raw text" is equivalent to {text:"This is raw text"}. This shorthand substitution is valid anywhere a raw text object is required (including the base <raw json message> argument of [[minecraft-command-tellraw|/tellraw]], the elements of the extra list, and the value of a "show_text" hover_event).
Finally, unlike other commands using JSON, [[minecraft-command-tellraw|/tellraw]] Strings support Unicode via the notation \u####, where #### is the Unicode hexadecimal number for the desired character.