Skip to main content

steel_worldgen/structure/
utils.rs

1use glam::IVec3;
2use steel_utils::random::Random;
3use steel_utils::random::legacy_random::LegacyRandom;
4use steel_utils::{BoundingBox, Direction};
5
6const VANILLA_HORIZONTAL_DIRECTIONS: [Direction; 4] = [
7    Direction::North,
8    Direction::East,
9    Direction::South,
10    Direction::West,
11];
12
13/// Matches vanilla's `Direction.Plane.HORIZONTAL.getRandomDirection`.
14pub(crate) fn random_horizontal_direction(rng: &mut LegacyRandom) -> Direction {
15    VANILLA_HORIZONTAL_DIRECTIONS[rng.next_i32_bounded(4) as usize]
16}
17
18/// Vanilla's `StructurePiece.makeBoundingBox`: north/south keep width/depth,
19/// east/west swap them.
20pub(crate) const fn make_oriented_piece_bounding_box(
21    chunk_min_x: i32,
22    y: i32,
23    chunk_min_z: i32,
24    orientation: Direction,
25    width: i32,
26    height: i32,
27    depth: i32,
28) -> BoundingBox {
29    let z_axis = matches!(orientation, Direction::North | Direction::South);
30    let (box_width, box_depth) = if z_axis {
31        (width, depth)
32    } else {
33        (depth, width)
34    };
35    BoundingBox::new(
36        IVec3::new(chunk_min_x, y, chunk_min_z),
37        IVec3::new(
38            chunk_min_x + box_width - 1,
39            y + height - 1,
40            chunk_min_z + box_depth - 1,
41        ),
42    )
43}