🧭 位置(Position)#
#bs.position:help
使用分数管理实体位置和旋转。
探索周围世界的过程中蕴含着兴奋。
—吉姆·皮布尔斯(Jim Peebles)
🔧 函数#
你可以在下方找到此模块中的所有可用函数。
添加位置和旋转#
- #bs.position:add_pos {scale:<scaling>}
将位置分数添加到实体的坐标。
- 输入:
执行
as <实体>:要传送的实体。分数
@s bs.pos.[x,y,z]:要添加的坐标。函数宏:
参数
scale: 输出的缩放值。
- 输出:
状态:实体根据位置分数被传送。
示例:传送到 ~48.85 ~ ~2.29:
# Once
scoreboard players set @s bs.pos.x 4885
scoreboard players set @s bs.pos.y 0
scoreboard players set @s bs.pos.z 229
function #bs.position:add_pos {scale:0.001}
- #bs.position:add_pos_x {scale:<scaling>}
将x轴位置分数添加到实体的坐标。
- 输入:
执行
as <实体>:要传送的实体。分数
@s bs.pos.x:要添加的x坐标。函数宏:
参数
scale: 输出的缩放值。
- 输出:
状态:实体根据x轴位置分数被传送。
示例:传送到 ~70 ~ ~:
# Once
scoreboard players set @s bs.pos.x 70
function #bs.position:add_pos_x {scale:1}
- #bs.position:add_pos_y {scale:<scaling>}
将y轴位置分数添加到实体的坐标。
- 输入:
执行
as <实体>:要传送的实体。分数
@s bs.pos.y:要添加的y坐标。函数宏:
参数
scale: 输出的缩放值。
- 输出:
状态:实体根据y轴位置分数被传送。
示例:传送到 ~ ~82 ~:
# Once
scoreboard players set @s bs.pos.y 82
function #bs.position:add_pos_y {scale:1}
- #bs.position:add_pos_z {scale:<scaling>}
将z轴位置分数添加到实体的坐标。
- 输入:
执行
as <实体>:要传送的实体。分数
@s bs.pos.z:要添加的z坐标。函数宏:
参数
scale: 输出的缩放值。
- 输出:
状态:实体根据z轴位置分数被传送。
示例:传送到 ~ ~ ~65:
# Once
scoreboard players set @s bs.pos.z 65
function #bs.position:add_pos_z {scale:1}
- #bs.position:add_rot {scale:<scaling>}
根据实体的分数旋转实体。
- 输入:
执行
as <实体>:要传送的实体。分数
@s bs.rot.[h,v]:要添加的旋转。函数宏:
参数
scale: 输出的缩放值。
- 输出:
状态:实体根据分数指示的旋转被传送。
- #bs.position:add_rot_h {scale:<scaling>}
根据实体的水平旋转分数旋转实体。
- 输入:
执行
as <实体>:要传送的实体。分数
@s bs.rot.h:要添加的旋转。函数宏:
参数
scale: 输出的缩放值。
- 输出:
状态:实体根据水平分数指示的旋转被传送。
- #bs.position:add_rot_v {scale:<scaling>}
根据实体的垂直旋转分数旋转实体。
- 输入:
执行
as <实体>:要传送的实体。分数
@s bs.rot.v:要添加的旋转。函数宏:
参数
scale: 输出的缩放值。
- 输出:
状态:实体根据垂直分数指示的旋转被传送。
- #bs.position:add_pos_and_rot {scale:<scaling>}
将位置分数添加到实体的坐标,并根据其旋转分数旋转实体。
- 输入:
执行
as <实体>:要传送和旋转的实体。分数
@s bs.pos.[x,y,z]:要添加的坐标。分数
@s bs.rot.[h,v]:要添加的旋转。函数宏:
参数
scale: 输出的缩放值。
- 输出:
状态:实体被传送到位置分数指示的位置,并根据旋转分数进行旋转。
制作人员:Aksiome、Leirof
标准转局部#
- #bs.position:canonical_to_local
将标准位置(使用相对参考系)转换为局部位置(使用局部参考系)。
- 输入:
执行
rotated as <entity>或rotated <h> <v>:用于转换的旋转。分数
@s bs.pos.[x,y,z]:要转换的位置。- 输出:
分数
@s bs.pos.[x,y,z]:转换后的位置。
What is a Local Position?
与相对位置(标准)不同,此参考系考虑实体的旋转。因此,当父实体旋转时,子实体围绕它旋转。对熟悉 Minecraft 命令的人来说,局部坐标可通过 ^ 符号使用。
制作人员:Aksiome
获取距离#
- #bs.position:get_distance_ata {scale:<scaling>}
计算源实体与函数执行位置之间的距离。
- 输入:
执行
as <实体>:位于参考点的实体。执行
at <实体>或positioned <x> <y> <z>:要获取距离的位置。函数宏:
参数
scale: 函数输出的缩放系数。
- 输出:
返回值 | 分数
$position.get_distance_ata bs.out:两个位置之间的距离。
计算你与最近的羊之间的距离(以方块为单位,无缩放):
# Once
execute at @e[type=sheep,limit=1,sort=nearest] run function #bs.position:get_distance_ata {scale:1}
# See the result
tellraw @a [{"text": "Distance: ", "color": "dark_gray"},{"score":{"name":"$position.get_distance_ata", "objective": "bs.out"}, "color": "gold"}]
性能提示
对于某些应用(如比较距离),使用平方距离而不是“正常”距离计算更有效率。
- #bs.position:get_distance_squared_ata {scale:<scaling>}
计算源实体与函数执行位置之间的平方距离。
- 输入:
执行
as <实体>:位于参考点的实体。执行
at <实体>或positioned <x> <y> <z>:要获取距离的位置。函数宏:
参数
scale: 函数输出的缩放系数。
- 输出:
返回值 | 分数
$position.get_distance_squared_ata bs.out:两个位置之间的平方距离。
示例:计算你与最近的羊之间的平方距离(以方块为单位,无缩放):
# Once
execute at @e[type=sheep,limit=1,sort=nearest] run function #bs.position:get_distance_squared_ata {scale:1}
# See the result
tellraw @a [{"text": "Distance^2: ", "color": "dark_gray"},{"score":{"name":"$position.get_distance_squared_ata", "objective": "bs.out"}, "color": "gold"}]
分数限制
Minecraft中的分数大小有限,类似于有符号整数变量。虽然这个限制很大,但并非无限,可能会溢出。由于此函数使用2的幂来计算结果,在处理大距离时最好使用"正常"版本(不依赖幂运算)。
制作人员:Aksiome、Leirof
获取位置和旋转#
- #bs.position:get_pos {scale:<scaling>}
获取函数的执行位置并将坐标存储在3个分数中。
- 输入:
执行
as <实体>:要存储分数的实体。执行
at <实体>或positioned <x> <y> <z>:要获取的位置。函数宏:
参数
scale: 函数输出的缩放系数。
- 输出:
分数
@s bs.pos.[x,y,z]:位置的坐标。
示例:检测并显示最近蜘蛛的位置(无缩放):
# Once
execute as @e[type=spider,limit=1,sort=nearest] run function #bs.position:get_pos {scale:1}
# See the results
tellraw @a [{"text": "X = ", "color": "dark_gray"},{"score":{"name":"@e[type=spider,limit=1,sort=nearest]", "objective": "bs.pos.x"}, "color": "gold"},{"text":", Y = ", "color": "dark_gray"},{"score":{"name":"@e[type=spider,limit=1,sort=nearest]", "objective": "bs.pos.y"}, "color": "gold"},{"text":", Z = ", "color": "dark_gray"},{"score":{"name":"@e[type=spider,limit=1,sort=nearest]", "objective": "bs.pos.z"}, "color": "gold"}]
- #bs.position:get_pos_x {scale:<scaling>}
获取函数的执行x位置并将坐标存储在分数中。
- 输入:
执行
as <实体>:要存储分数的实体。执行
at <实体>或positioned <x> <y> <z>:要获取的位置。函数宏:
参数
scale: 函数输出的缩放系数。
- 输出:
分数
@s bs.pos.x:位置的坐标。
示例:检测并显示最近蜘蛛的x位置(无缩放):
# Once
execute as @e[type=spider,limit=1,sort=nearest] run function #bs.position:get_pos_x {scale:1}
# See the resluts
tellraw @a [{"text": "X = ", "color": "dark_gray"},{"score":{"name":"@e[type=spider,limit=1,sort=nearest]", "objective": "bs.pos.x"}, "color": "gold"}]
- #bs.position:get_pos_y {scale:<scaling>}
获取函数的执行y位置并将坐标存储在分数中。
- 输入:
执行
as <实体>:要存储分数的实体。执行
at <实体>或positioned <x> <y> <z>:要获取的位置。函数宏:
参数
scale: 函数输出的缩放系数。
- 输出:
分数
@s bs.pos.y:位置的坐标。
示例:检测并显示最近蜘蛛的y位置(无缩放):
# Once
execute as @e[type=spider,limit=1,sort=nearest] run function #bs.position:get_pos_y {scale:1}
# See the resluts
tellraw @a [{"text": "Y = ", "color": "dark_gray"},{"score":{"name":"@e[type=spider,limit=1,sort=nearest]", "objective": "bs.pos.y"}, "color": "gold"}]
- #bs.position:get_pos_z {scale:<scaling>}
获取函数的执行z位置并将坐标存储在分数中。
- 输入:
执行
as <实体>:要存储分数的实体。执行
at <实体>或positioned <x> <y> <z>:要获取的位置。函数宏:
参数
scale: 函数输出的缩放系数。
- 输出:
分数
@s bs.pos.z:位置的坐标。
示例:检测并显示最近蜘蛛的z位置(无缩放):
# Once
execute as @e[type=spider,limit=1,sort=nearest] run function #bs.position:get_pos_z {scale:1}
# See the resluts
tellraw @a [{"text": "Z = ", "color": "dark_gray"},{"score":{"name":"@e[type=spider,limit=1,sort=nearest]", "objective": "bs.pos.z"}, "color": "gold"}]
- #bs.position:get_rot {scale:<scaling>}
获取函数的执行旋转并将其存储在2个分数中。
- 输入:
执行
as <实体>:要存储分数的实体。执行
at <实体>或rotated <h> <v>:要获取的旋转。函数宏:
参数
scale: 函数输出的缩放系数。
- 输出:
分数
@s bs.rot.[h,v]:位置的旋转。
- #bs.position:get_rot_h {scale:<scaling>}
获取函数的执行水平旋转。
- 输入:
执行
as <实体>:要存储分数的实体。执行
at <实体>或rotated <h> <v>:要获取的旋转。函数宏:
参数
scale: 函数输出的缩放系数。
- 输出:
分数
@s bs.rot.h:位置的水平旋转。
- #bs.position:get_rot_v {scale:<scaling>}
获取函数的执行垂直旋转。
- 输入:
执行
as <实体>:要存储分数的实体。执行
at <实体>或rotated <h> <v>:要获取的旋转。函数宏:
参数
scale: 函数输出的缩放系数。
- 输出:
分数
@s bs.rot.v:位置的垂直旋转。
- #bs.position:get_pos_and_rot {scale:<scaling>}
获取函数的执行位置和旋转,并将坐标和旋转存储在5个分数中。
- 输入:
执行
as <实体>:要存储分数的实体。执行
at <实体>或positioned <x> <y> <z> rotated <h> <v>:要获取的位置和旋转。函数宏:
参数
scale: 函数输出的缩放系数。
- 输出:
分数
@s bs.pos.[x,y,z]:位置的坐标。分数
@s bs.rot.[h,v]:位置的旋转。
制作人员:Aksiome、Leirof、theogiraudet
获取相对位置#
- #bs.position:get_relative_ata {scale:<scaling>}
获取相对于执行实体位置的函数执行位置。
- 输入:
执行
as <实体>:视为在参考点的实体。执行
at <实体>或positioned <x> <y> <z>:要获取相对位置的位置。函数宏:
参数
scale: 函数输出的缩放系数。
- 输出:
分数
@s bs.pos.[x,y,z]:相对坐标。
示例:获取你相对于最近苦力怕的位置(无缩放):
# Once
execute as @s at @e[type=creeper,limit=1,sort=nearest] run function #bs.position:get_relative_ata {scale:1}
# See the result
tellraw @a [{"text": "Relative position : X=", "color": "dark_gray"},{"score":{"name":"@s", "objective": "bs.pos.x"}, "color": "gold"},{"text":", Y=", "color": "dark_gray"},{"score":{"name":"@s", "objective": "bs.pos.y"},"color":"gold"},{"text":", Z=","color":"dark_gray"},{"score":{"name":"@s","objective":"bs.pos.z"},"color":"gold"}]
- #bs.position:get_relative_from_dir {scale:<scaling>}
基于执行位置和旋转获取方向向量。缩放用作标准/长度。
- 输入:
执行
as <实体>:要存储分数的实体。执行
at <实体>或positioned <x> <y> <z> rotated <h> <v>:要获取相对位置的位置和旋转。函数宏:
参数
scale: 函数输出的缩放系数。
- 输出:
分数
@s bs.pos.[x,y,z]:相对坐标。
示例:获取你相对于你前方2个方块位置的位置(缩放1000):
# Once
execute at @s run function #bs.position:get_relative_from_dir {scale:2000}
# See the result
tellraw @a [{"text": "Relative position : X=", "color": "dark_gray"},{"score":{"name":"@s", "objective": "bs.pos.x"}, "color": "gold"},{"text":", Y=", "color": "dark_gray"},{"score":{"name":"@s", "objective": "bs.pos.y"},"color":"gold"},{"text":", Z=","color":"dark_gray"},{"score":{"name":"@s","objective":"bs.pos.z"},"color":"gold"}]
制作人员:Aksiome、Leirof
局部转标准#
- #bs.position:local_to_canonical
将局部位置(使用局部参考系)转换为标准位置(使用相对参考系)。
- 输入:
执行
rotated as <entity>或rotated <h> <v>:用于转换的旋转。分数
@s bs.pos.[x,y,z]:要转换的位置。- 输出:
分数
@s bs.pos.[x,y,z]:转换后的位置。
What is a Local Position?
与相对位置(标准)不同,此参考系考虑实体的旋转。因此,当父实体旋转时,子实体围绕它旋转。对熟悉 Minecraft 命令的人来说,局部坐标可通过 ^ 符号使用。
制作人员:Aksiome
设置位置和旋转#
- #bs.position:set_pos {scale:<scaling>}
将实体放置在由分数给定的坐标处。
- 输入:
执行
as <实体>:要传送的实体。分数
@s bs.pos.[x,y,z]:要传送到的坐标。函数宏:
参数
scale: 输出的缩放值。
- 输出:
状态:实体被传送到分数指示的坐标。
示例:传送到48.85 0 2.29:
# Once
scoreboard players set @s bs.pos.x 4885
scoreboard players set @s bs.pos.y 0
scoreboard players set @s bs.pos.z 229
function #bs.position:set_pos {scale:0.001}
- #bs.position:set_pos_x {scale:<scaling>}
将实体放置在由分数给定的精确x坐标处。
- 输入:
执行
as <实体>:要传送的实体。分数
@s bs.pos.x:要传送到的x坐标。函数宏:
参数
scale: 输出的缩放值。
- 输出:
状态:实体被传送到分数指示的x坐标。
示例:传送到70 ~ ~:
# Once
scoreboard players set @s bs.pos.x 70
function #bs.position:set_pos_x {scale:1}
- #bs.position:set_pos_y {scale:<scaling>}
将实体放置在由分数给定的精确y坐标处。
- 输入:
执行
as <实体>:要传送的实体。分数
@s bs.pos.y:要传送到的y坐标。函数宏:
参数
scale: 输出的缩放值。
- 输出:
状态:实体被传送到分数指示的y坐标。
示例:传送到 ~ 82 ~:
# Once
scoreboard players set @s bs.pos.y 82
function #bs.position:set_pos_y {scale:1}
- #bs.position:set_pos_z {scale:<scaling>}
将实体放置在由分数给定的精确z坐标处。
- 输入:
执行
as <实体>:要传送的实体。分数
@s bs.pos.z:要传送到的z坐标。函数宏:
参数
scale: 输出的缩放值。
- 输出:
状态:实体被传送到分数指示的z坐标。
示例:传送到 ~ ~ 65:
# Once
scoreboard players set @s bs.pos.z 65
function #bs.position:set_pos_z {scale:1}
- #bs.position:set_rot {scale:<scaling>}
根据实体的分数旋转实体。
- 输入:
执行
as <实体>:要传送的实体。分数
@s bs.rot.[h,v]:要传送到的旋转。函数宏:
参数
scale: 输出的缩放值。
- 输出:
状态:实体被传送到分数指示的旋转。
- #bs.position:set_rot_h {scale:<scaling>}
根据实体的水平旋转分数旋转实体。
- 输入:
执行
as <实体>:要传送的实体。分数
@s bs.rot.h:要传送到的旋转。函数宏:
参数
scale: 输出的缩放值。
- 输出:
状态:实体被传送到水平分数指示的旋转。
- #bs.position:set_rot_v {scale:<scaling>}
根据实体的垂直旋转分数旋转实体。
- 输入:
执行
as <实体>:要传送的实体。分数
@s bs.rot.v:要传送到的旋转。函数宏:
参数
scale: 输出的缩放值。
- 输出:
状态:实体被传送到垂直分数指示的旋转。
- #bs.position:set_pos_and_rot {scale:<scaling>}
根据实体的位置和旋转分数放置和旋转实体。
- 输入:
执行
as <实体>:要传送的实体。分数@s bs.pos.[x,y,z]:要传送到的坐标。分数@s bs.rot.[h,v]:要传送到的旋转。函数宏:
参数
scale: 输出的缩放值。
- 输出:
状态:实体被传送到位置分数指示的位置,并根据旋转分数进行旋转。
制作人员:Aksiome、Leirof、theogiraudet
💬 这对你有帮助吗?
欢迎在下方留下你的问题和反馈!