steel_worldgen/structure/
utils.rs1use 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
13pub(crate) fn random_horizontal_direction(rng: &mut LegacyRandom) -> Direction {
14 VANILLA_HORIZONTAL_DIRECTIONS[rng.next_i32_bounded(4) as usize]
15}
16
17pub(crate) const fn make_oriented_piece_bounding_box(
20 chunk_min_x: i32,
21 y: i32,
22 chunk_min_z: i32,
23 orientation: Direction,
24 width: i32,
25 height: i32,
26 depth: i32,
27) -> BoundingBox {
28 let z_axis = matches!(orientation, Direction::North | Direction::South);
29 let (box_width, box_depth) = if z_axis {
30 (width, depth)
31 } else {
32 (depth, width)
33 };
34 BoundingBox::new(
35 IVec3::new(chunk_min_x, y, chunk_min_z),
36 IVec3::new(
37 chunk_min_x + box_width - 1,
38 y + height - 1,
39 chunk_min_z + box_depth - 1,
40 ),
41 )
42}