Translation notice
This page was translated with machine translation and may contain inaccuracies. If you can help improve it, please open an issue or submit a pull request.

Basic theory related to coordinate system and coordinate parameters
summary
The game world of Minecraft is three-dimensional. When writing a command, sometimes you need to determine the positional parameters required by the command's action object. Such parameters are called coordinates. This article lists the coordinate parameter formats used by the command system and provides a theoretical explanation of their properties and uses.
introduction
The spatial rectangular coordinate system used by Minecraft is a right-handed coordinate system. In this space rectangular coordinate system, In most cases, three parameters can be used to represent the position of a certain point, which is an ordered triple of real numbers:
<x> <y> <z>For example, a point represented mathematically0 4 4.
Example There are two points in the space rectangular coordinate system
、 ,but The point is located horizontally Which direction is the point? untie point coordinate is located at point The negative direction of coordinate, so The point is located in the east-west direction point west; point coordinate is located at point The positive direction of coordinate, therefore The point is located in the east-west direction point south. In summary, The point is located at southwest of the point.
Although different coordinate expressions are basically the same, different commands act on different objects, and their coordinate parameter types are not completely consistent. The following will sort out all types of coordinate parameters used by the command system.
Parameter type
The command uses four coordinate-related parameter types: blockcoordinateminecraft:block_pos, three-dimensional coordinateminecraft:vec3, plane blockcoordinateminecraft:column_pos and two-dimensional coordinateminecraft:vec2. Their relationships and application scenarios can be clearly listed in the following table:
| Generally used in blocks | Generally used in non-block game content | |
|---|---|---|
| 3D | minecraft:block_pos | minecraft:vec3 |
| 2D | minecraft:column_pos | minecraft:vec2 |
blockcoordinate
Coordinate represents a point without volume, while block has volume, so a datum point needs to be specified for the block, and the coordinate of this datum point is used to represent the coordinate of the object. Minecraft regulations: The length, width and height of most blocks are 1 meter, and the volume is 1 cubic meter. When using the coordinate system to represent these positions, it is assumed that the side length of the block and the unit length of the coordinate system are numerically equal, which means that the basic unit of the coordinate system is meters, or "grids". A block uses its lower northwest corner point as its blockcoordinate (Block position). If the coordinate of the northwest lower vertex of a block is
Since the corners of the block are always located at the integer coordinate point, the blockcoordinate used as the command parameter minecraft:block_pos must be an ordered triplet composed of three integers. Relative coordinates and local coordinates are allowed in blockcoordinate. Command/setblock, /fill, /clone, /fillbiome, /spawnpointand/setworldspawnall use blockcoordinate. In addition, the subcommands used to process block entity data in/data, /itemand/execute also use blockcoordinate.
Example As shown in the picture, which block is the one with blockcoordinate
0 0 0?Solution blockcoordinate is calculated strictly based on the northwest lower corner vertex, while due west and due north are respectively
Axis and The negative direction of the axis, so the block position indicated by blockcoordinate is always located in the southeast direction of the actual coordinate and is located above the vertical direction. The reflection in the space rectangular coordinate system is 、 、 The positive direction of the three coordinate axes. Therefore, the block with blockcoordinate 0 0 0is located in the first hexagram, that is, block。
Three-dimensional coordinate
Three-dimensional coordinates is a coordinate parameter that accurately represents a position. The command parameter type is minecraft:vec3. The three elements used to represent the coordinate position are all double-precision floating point numbers. Three-dimensional coordinate is generally applied to entities. The commands that use three-dimensional coordinate include /tp (/teleport), /rotate, /summon, /particle, /playsound, /damage, and the facingandpositionedsub-commands of/execute. It can be seen that most of the above commands are commands related to entities. When an entity uses three-dimensional coordinates, the bottom center point of its collision box is the coordinate of this entity. For example, use command
tp 5.0 56.0 17.0Finally, the center point of the player's sole is located
The offsets of these positions are located on the center line of the two opposite sides of the block. This is because the three-dimensional coordinate uses Center correct, that is, using the three-dimensional coordinate in the form of an integer, when one of its coordinate parameters is5 56 17.0 is actually located at
Plane block coordinate
As the name suggests, the plane block coordinate minecraft:column_posis a two-dimensional block coordinate. The two-dimensional coordinate of the northwest corner is used as the plane coordinate of a block column. Both elements are integers. Currently, the only command that uses this parameter format is/forceload.
two-dimensional coordinate
That is only byminecraft:vec2, and both elements are double-precision floating point numbers. If the two-dimensional coordinate is an integer, center calibration is also used. Both /spreadplayersand/worldborder use this parameter format. ,
Relative coordinate and local coordinate
In addition to using the numeric form, the coordinate parameter can also use the tilde or caret to represent relative or local coordinates.
relative coordinate
World coordinate is a fixed coordinate system based on the space rectangular coordinate system. Each position has its fixed coordinate. When expressing these coordinates, sometimes it is necessary to determine the "relative position", that is, to put aside the inherent coordinate system based on the origin, and use "relative offset" to express the coordinate of one position relative to another position, which is the relative coordinates (Relative world coordinates) to be introduced below. The relative fixed space rectangular coordinate system coordinate is called absolute coordinates (Absolute world coordinates). In the relative coordinate system, an origin must be determined, which is usually the command execution position. If the command is executed by the player, the origin is the location of the player; if the command is executed by the command block, the origin is the location of the command block. The relative coordinate is represented by the tilde ~ and the relative offset. If it is a two-dimensional coordinate, it is
~[<dx>] ~[<dz>]If it is a three-dimensional coordinate, that is
~[<dx>] ~[<dy>] ~[<dz>]If the relative offsets [<dx>], [<dy>], and [<dz>]are not filled in, the offset will be 0, and the offset can be negative. This is equivalent to establishing a spatial rectangular coordinate system with the command execution position as the origin. For example, the distance of 3 blocks due east of the point can be expressed as~3~~. 
Example A point located at
The command block of the command block, the block coordinate pointed to by its relative coordinates ~12 ~-3 ~-5is ____________. Solution Relative coordinates stipulate that the position of the command block is the origin. When converting relative coordinates to absolute coordinates, you only need to make corresponding additions and subtractions based on the absolute coordinates. The blockcoordinate in this question is, can be calculated 。
**Relative coordinates can be mixed with absolute coordinates. ** In the coordinate parameter without using the tilde, the absolute coordinate is calculated. For example, ~10 10 ~10 will change according to the execution position10 70 -10. The above four coordinate parameter types, minecraft:block_pos, minecraft:vec3, minecraft:column_posandminecraft:vec2 can all use relative coordinate.
local coordinate
In addition to relative coordinates, the command system also has a more flexible coordinate, namely local coordinates (Local coordinates). Local coordinates are also used to represent relative offsets. Unlike relative coordinates, local coordinates use directions to represent offsets. Similarly, the local coordinate also has the command execution position as the anchor point, represented by the caret and relative offset format:
^[<dx>] ^[<dy>] ^[<dz>]
The local coordinate is divorced from the direction specified by the absolute coordinate system, and it uses the command execution orientation as the benchmark. As shown in the figure, using local coordinates is equivalent to establishing a coordinate system with arbitrary coordinate axis directions, but the orthogonal relationship between coordinate axes remains unchanged. If the executor is a player or other entity, as the perspective of these entities rotates, this coordinate system also rotates with their perspective. Regulation: command execution direction is the local coordinate system^-3 ^ ^. **Because local coordinate does not use the coordinate axis direction specified by the absolute coordinate system, local coordinate cannot be mixed with absolute coordinate and relative coordinate. ** If local coordinate is used in blockcoordinate, like relative coordinate, the coordinate value will also be rounded down (minus infinity) to make it fit the blockcoordinate. **But local coordinate cannot be used for the two-dimensional coordinate parameters minecraft:column_posandminecraft:vec2, but can only be used for the three-dimensional minecraft:block_posandminecraft:vec3. **
coordinate form in other parameters
coordinate in target selector
The target selector origin uses a set of double-precision floating point numbers as parameter values, including three parameters: x, y, and z:
<目标选择器变量>[x=<x>,y=<y>,z=<z>]The value of the parameter can be a decimal. The coordinate of the position origin does not apply to center calibration. All position origin coordinates use their actual coordinates. Usage examples:
@a[x=0,y=57,z=0]This selector parameter defines the precise origin
@a[x=0,z=0]Since the parameter yis not defined, the command execution position is usedy. If none of the three parameters have defined values, the command execution position will be used entirely. Generally speaking, the origin parameter needs to be used in conjunction with distance, volume, sorting or quantity parameters. However, a selector like @pwith its own sorting function can use the origin parameter alone. For example,@p[x=0,y=0,z=0] will select the origin parameter.
Round down the execution position
The alignsubcommand of/execute rounds down the actual coordinate of the command execution position. The syntax is:
align <axes> ‐> executeAmong them, <axes>uses a special parameter format - coordinate axis combinationminecraft:swizzle. Can be any unique combination of x, yandz, so a combination like xx is an error. All available combinations are: x, y, z, xy, xz, yx, yz, zx, zy, xyz, xzy, yxz, yzx, zxyandzyx, a total of 15 different combinations. The subcommand alignwill round the coordinates on all corresponding coordinate axes in the combination downward (that is, rounded to negative infinity). There is no requirement for the order of the coordinate axes, so combinations likexyandyx have exactly the same effect. There are seven situations in total for coordinate rounding. The following corresponds to all situations and 15 combinations:
- only for
coordinate rounding: x; - only for
coordinate rounding: y; - only for
coordinate rounding: z; - right
coordinate and coordinate rounding: xyandyx; - right
coordinate and coordinate rounding: xzandzx; - right
coordinate and coordinate rounding: yzandzy; - right
coordinate、 coordinate and coordinate rounding: xyz,xzy,yxz,yzx,zxyandzyx.
Example It is known that the command executor is located at
, after executing the following command: execute align xyz run tp ~ ~ ~What is the actual coordinate of the command executor? Solution It can be seen from the meaning of the question that the initial execution position of this command is (12.5,76,-41.3), and thexyzcombination makes thealignsubcommand change the execution position ofcoordinate、 coordinate and coordinate is rounded down to obtain the modified execution position. . It can be seen that if coordinate is positive, rounding down will remove the decimal point; if coordinate is an integer, it will remain unchanged; if coordinate is negative, after removing the decimal point, the number at the integer position will be subtracted by 1. When the runcommand is finally processed, command/tpwill send the command executor to the modified coordinate. In the same way, if the executed command isexecute align x run tp ~ ~ ~Then the modified execution position is,here coordinate and coordinate is not rounded down. One thing that readers need to pay attention to is that the alignsubcommand is not equivalent to the center calibration of coordinates, because all coordinates in the command are actual coordinates, so the representation of integer coordinates is the edge of the block. In this example,coordinate and The coordinates are all rounded down, so the command executor is sent to the intersection of the four blocks, as shown in the figure:
Although the alignsubcommand is not equivalent to the center calibration of coordinate, you can still use thealign subcommand to perform manual center calibration of an existing entity. Here is another example:
Example Calibrate the position of the command executor of any coordinate to the center of the block where it is located. Solution You can first use the
alignsubcommand to paircoordinate and coordinate is rounded down: No matter whether the command executor is located at any coordinate in the block where it is located, the execution position after rounding down is the same. Then use the /tpcommand to perform manual center calibration, that is, the command executor'scoordinate and The coordinate moves 0.5 blocks in the positive direction. At this time, the command executor is calibrated to the center point of the block. Valid commands are: execute align xz run tp ~0.5 ~ ~0.5
References
[1] https://zh.minecraft.wiki/w/坐标 [2] https://zh.minecraft.wiki/w/目标选择器 [3] https://zh.minecraft.wiki/w/命令/execute [4] https://zh.minecraft.wiki/w/参数类型
Solution blockcoordinate is calculated strictly based on the northwest lower corner vertex, while due west and due north are respectively