🏃 移动(Move)#
#bs.move:help
让你的实体按照你想要的方式移动!
唯有变化才是永恒。
—赫拉克利特(Heraclitus)
观看演示
🔧 函数#
你可以在下方找到此模块中的所有可用函数。
应用速度#
- #bs.move:apply_vel {scale:<scaling>,with:{}}
Teleport an entity by its velocity scores while handling collisions. Lambda scores are only available during callback execution (
on_*).- 输入:
执行
as <实体>:要移动的实体。分数
@s bs.vel.[x,y,z]:标准速度向量。函数宏:
参数
scale: 输出的缩放系数。
with: 碰撞设置。
blocks: Whether the entity should collide with blocks (default: true).
Can be a hitbox provider (e.g.function #bs.hitbox:callback/get_block_collision).entities: Whether the entity should collide with entities (default: false).
Can be a selector tag (typically assigned via/tag), which is preferred for performance.ignored_blocks: 要忽略的方块(默认:
#bs.hitbox:can_pass_through)。ignored_entities: Entity type to ignore (default:
#bs.hitbox:intangible).
Does not apply to entities with custom hitboxes.on_collision: Command to run when a collision occurs.
Used to resolve the collision (default:function #bs.move:callback/bounce).
- Lambdas:
Score
$move.hit_face bs.lambda: The face of the bounding box that was hit: 5 is east, 4 is west, 3 is south, 2 is north, 1 is top, and 0 is bottom.Score
$move.hit_flag bs.lambda: The flag of the intersected bounding box,-1for entities.Scores
$move.vel.[x,y,z] bs.lambda: The remaining velocity in canonical coordinates after collision adjustments.- 输出:
状态:实体根据其速度分数被传送。
- #bs.move:apply_local_vel {scale:<scaling>,with:{}}
实验性
始终优先使用标准版本。基数之间的持续转换可能导致精度损失,有时会造成不可预测的行为。
If you need to “shoot” an entity in a direction, you can still set velocity as a local vector and run
#bs.move:local_to_canonicalbefore using#bs.move:apply_vel.Teleport an entity by its velocity scores, using the local reference frame, while handling collisions. Lambda scores are only available during callback execution (
on_*).- 输入:
执行
as <实体>:要移动的实体。分数
@s bs.vel.[x,y,z]:局部速度向量。函数宏:
参数
scale: 输出的缩放系数。
with: 碰撞设置。
blocks: Whether the entity should collide with blocks (default: true).
Can be a hitbox provider (e.g.function #bs.hitbox:callback/get_block_collision).entities: Whether the entity should collide with entities (default: false).
Can be a selector tag (typically assigned via/tag), which is preferred for performance.ignored_blocks: 要忽略的方块(默认:
#bs.hitbox:can_pass_through)。ignored_entities: Entity type to ignore (default:
#bs.hitbox:intangible).
Does not apply to entities with custom hitboxes.on_collision: 当碰撞时运行的命令,用来解决碰撞问题(默认:
function #bs.move:callback/bounce)。
- Lambdas:
Score
$move.hit_face bs.lambda: The face of the bounding box that was hit.Score
$move.hit_flag bs.lambda: The flag of the intersected bounding box,-1for entities.Scores
$move.vel.[x,y,z] bs.lambda: The remaining velocity in canonical coordinates after collision adjustments.- 输出:
状态:实体根据其局部速度分数被传送。
What is a Bounding Box?
A bounding box is a simple rectangular box that surrounds an object—or part of it—to help the game figure out where it is and what it touches. For example, a set of stairs in Minecraft uses two bounding boxes: one for the lower step and one for the upper step.
Custom Hitboxes
Bookshelf supports multiple hitbox types for precise control. Blocks can use custom hitbox providers. Entities support three types: dynamic, baked, and custom.
示例:根据速度分数移动立方体(block_display)(使用交互实体作为碰撞箱):
# Once
summon minecraft:block_display ~ ~ ~ {block_state:{Name:"stone"},teleport_duration:3,transformation:[1f,0f,0f,-0.5f,0f,1f,0f,0f,0f,0f,1f,-0.5f,0f,0f,0f,1f],Passengers:[{id:"minecraft:interaction",width:1f,height:1f}]}
scoreboard players set @e[type=minecraft:block_display] bs.vel.x 100
scoreboard players set @e[type=minecraft:block_display] bs.vel.y 20
scoreboard players set @e[type=minecraft:block_display] bs.vel.z 50
# In a loop
execute as @e[type=minecraft:block_display] run function #bs.move:apply_vel {scale:0.001,with:{}}
# Choose between multiple collision behaviors
execute as @e[type=minecraft:block_display] run function #bs.move:apply_vel {scale:0.001,with:{on_collision:"function #bs.move:callback/bounce"}}
execute as @e[type=minecraft:block_display] run function #bs.move:apply_vel {scale:0.001,with:{on_collision:"function #bs.move:callback/damped_bounce"}}
execute as @e[type=minecraft:block_display] run function #bs.move:apply_vel {scale:0.001,with:{on_collision:"function #bs.move:callback/slide"}}
execute as @e[type=minecraft:block_display] run function #bs.move:apply_vel {scale:0.001,with:{on_collision:"function #bs.move:callback/stick"}}
性能提示
虽然此系统没有设置具体限制,但需要注意性能受实体的速度和大小的影响。
制作人员:Aksiome
标准转局部#
- #bs.move:canonical_to_local
将标准速度(使用相对参考系)转换为局部速度(使用局部参考系)。
- 输入:
执行
rotated as <entity>或rotated <h> <v>:用于转换的旋转。分数
@s bs.vel.[x,y,z]:要转换的速度。- 输出:
分数
@s bs.vel.[x,y,z]:转换后的速度。
What is a Local Velocity?
与相对速度(标准)不同,此参考系考虑实体的旋转。因此,当父实体旋转时,子实体围绕它旋转。对熟悉 Minecraft 命令的人来说,局部坐标可通过 ^ 符号使用。
制作人员:Aksiome
局部转标准#
- #bs.move:local_to_canonical
将局部速度(使用局部参考系)转换为标准速度(使用相对参考系)。
- 输入:
执行
rotated as <entity>或rotated <h> <v>:用于转换的旋转。分数
@s bs.vel.[x,y,z]:要转换的速度。- 输出:
分数
@s bs.vel.[x,y,z]:转换后的速度。
What is a Local Velocity?
与相对速度(标准)不同,此参考系考虑实体的旋转。因此,当父实体旋转时,子实体围绕它旋转。对熟悉 Minecraft 命令的人来说,局部坐标可通过 ^ 符号使用。
制作人员:Aksiome
设置运动#
- #bs.move:set_motion {scale:<scaling>}
使用速度分数设置实体的运动(Motion)NBT。
- 输入:
执行
as <实体>:要移动的实体。分数
@s bs.vel.[x,y,z]:速度向量。函数宏:
参数
scale: 输出的缩放系数。
- 输出:
状态:运动被应用到给定实体。
示例:根据速度分数移动猪:
# Once
summon minecraft:pig ~ ~ ~
scoreboard players set @e[type=minecraft:pig] bs.vel.x 50
scoreboard players set @e[type=minecraft:pig] bs.vel.y 25
scoreboard players set @e[type=minecraft:pig] bs.vel.z 0
# In a loop
execute as @e[type=minecraft:pig] run function #bs.move:set_motion {scale:0.001}
制作人员:Aksiome
👁️ 谓词#
你可以在下方找到此模块中的所有可用谓词。
有速度?#
bs.move:has_vel
确定实体是否有非零速度分数。
制作人员:Aksiome
🎓 自定义碰撞#
此模块允许你根据特定需求自定义碰撞行为。
By modifying the on_collision input argument, you have the freedom to specify the function that triggers upon collision. However, managing the resolution yourself can be quite challenging. This is why Bookshelf provides several predefined functions:
|
实体将在碰撞表面反弹。 |
|
实体速度在每次反弹时减少2。 |
|
实体将粘附并沿碰撞表面滑动。 |
|
实体将停止并粘附在碰撞表面上。 |
How It Works#
When a collision occurs, the system tracks which bounding box was hit using the velocity and the flag of that bounding box. You can modify:
@s bs.vel.[x,y,z]: the velocity that will be applied on the next tick.$move.vel.[x,y,z] bs.lambda: the remaining velocity after rolling back to the time of impact.
To simplify the creation of custom behaviors, there’s no need to handle a local velocity directly. The vector is automatically converted before and after the collision resolution.
速度缩放
剩余速度值以缩放整数的形式存储,但缩放系数可随时变更,并且这不破坏兼容性。
为了确保稳定性,请保持计算操作和缩放系数无关。
最简单的碰撞处理是停止移动。
#bs.move:callback/stick
# set all components to 0 to cancel the movement
execute store result score $move.vel.x bs.lambda run scoreboard players set @s bs.vel.x 0
execute store result score $move.vel.y bs.lambda run scoreboard players set @s bs.vel.y 0
execute store result score $move.vel.z bs.lambda run scoreboard players set @s bs.vel.z 0
对于滑动,我们需要取消被阻挡的轴上的速度,并继续行进剩余距离。
#bs.move:callback/slide
# set a component to 0 depending on the surface that was hit.
execute if score $move.hit_face bs.lambda matches 4..5 store result score $move.vel.x bs.lambda run scoreboard players set @s bs.vel.x 0
execute if score $move.hit_face bs.lambda matches 0..1 store result score $move.vel.y bs.lambda run scoreboard players set @s bs.vel.y 0
execute if score $move.hit_face bs.lambda matches 2..3 store result score $move.vel.z bs.lambda run scoreboard players set @s bs.vel.z 0