Skip to main content

basalt_api/components/
spatial.rs

1//! Spatial components: position, rotation, velocity, bounding box.
2
3use crate::components::Component;
4
5/// World position of an entity.
6#[derive(Debug, Clone, Copy, PartialEq)]
7pub struct Position {
8    /// X coordinate.
9    pub x: f64,
10    /// Y coordinate.
11    pub y: f64,
12    /// Z coordinate.
13    pub z: f64,
14}
15impl Component for Position {}
16
17/// Facing direction of an entity.
18#[derive(Debug, Clone, Copy, PartialEq)]
19pub struct Rotation {
20    /// Horizontal angle in degrees.
21    pub yaw: f32,
22    /// Vertical angle in degrees.
23    pub pitch: f32,
24}
25impl Component for Rotation {}
26
27/// Movement vector per tick.
28#[derive(Debug, Clone, Copy, PartialEq)]
29pub struct Velocity {
30    /// X movement per tick.
31    pub dx: f64,
32    /// Y movement per tick.
33    pub dy: f64,
34    /// Z movement per tick.
35    pub dz: f64,
36}
37impl Component for Velocity {}
38
39/// AABB hitbox dimensions.
40///
41/// The bounding box is axis-aligned and centered on the entity's
42/// position. Used for collision detection and entity interactions.
43#[derive(Debug, Clone, Copy, PartialEq)]
44pub struct BoundingBox {
45    /// Width (X and Z extent).
46    pub width: f32,
47    /// Height (Y extent).
48    pub height: f32,
49}
50impl Component for BoundingBox {}
51
52/// Absolute block coordinates (integers).
53///
54/// Used in events for block interactions (break, place, interact).
55#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
56pub struct BlockPosition {
57    /// Block X coordinate.
58    pub x: i32,
59    /// Block Y coordinate.
60    pub y: i32,
61    /// Block Z coordinate.
62    pub z: i32,
63}
64
65/// Chunk coordinates (X and Z only, no Y).
66///
67/// Chunks are 16x16 block columns. Chunk coordinates are
68/// block coordinates divided by 16 (right-shifted by 4).
69#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
70pub struct ChunkPosition {
71    /// Chunk X coordinate.
72    pub x: i32,
73    /// Chunk Z coordinate.
74    pub z: i32,
75}