steel_core/command/builtins/
position.rs1use glam::DVec3;
4use steel_math::wrap_degrees;
5use steel_utils::{BlockPos, translations};
6use text_components::TextComponent;
7
8use super::super::brigadier::CommandSyntaxError;
9use crate::world::World;
10
11pub(super) fn ensure_spawnable_position(position: DVec3) -> Result<(), CommandSyntaxError> {
12 if World::is_in_spawnable_bounds(BlockPos::from(position)) {
13 return Ok(());
14 }
15 Err(CommandSyntaxError::dynamic(TextComponent::from(
16 &translations::COMMANDS_TELEPORT_INVALID_POSITION,
17 )))
18}
19
20pub(super) const fn finite_rotation(
22 (yaw, pitch): (f32, f32),
23 (own_yaw, own_pitch): (f32, f32),
24) -> (f32, f32) {
25 (
26 if yaw.is_finite() { yaw } else { own_yaw },
27 if pitch.is_finite() { pitch } else { own_pitch },
28 )
29}
30
31pub fn wrap_rotation((yaw, pitch): (f32, f32)) -> (f32, f32) {
32 (wrap_degrees(yaw), wrap_degrees(pitch))
33}