Skip to main content

steel_core/worldgen/structure/piece_placer/ocean_monument/
helpers.rs

1use super::*;
2
3pub(super) fn generate_water_box(
4    placer: &mut ScatteredFeaturePlacer<'_, '_>,
5    x0: i32,
6    y0: i32,
7    z0: i32,
8    x1: i32,
9    y1: i32,
10    z1: i32,
11) {
12    let water = vanilla_blocks::WATER.default_state();
13    let air = vanilla_blocks::AIR.default_state();
14    for y in y0..=y1 {
15        for x in x0..=x1 {
16            for z in z0..=z1 {
17                let block = placer.block_at(x, y, z);
18                if fill_keeps(block) {
19                    continue;
20                }
21
22                let pos = placer.world_pos(x, y, z);
23                if pos.y() >= placer.sea_level() && block != water {
24                    placer.place_block(air, x, y, z);
25                } else {
26                    placer.place_block(water, x, y, z);
27                }
28            }
29        }
30    }
31}
32
33#[expect(
34    clippy::too_many_arguments,
35    reason = "matches vanilla OceanMonumentPiece.generateBoxOnFillOnly bounds"
36)]
37pub(super) fn generate_box_on_fill_only(
38    placer: &mut ScatteredFeaturePlacer<'_, '_>,
39    x0: i32,
40    y0: i32,
41    z0: i32,
42    x1: i32,
43    y1: i32,
44    z1: i32,
45    state: BlockStateId,
46) {
47    let water = vanilla_blocks::WATER.default_state();
48    for y in y0..=y1 {
49        for x in x0..=x1 {
50            for z in z0..=z1 {
51                if placer.block_at(x, y, z) == water {
52                    placer.place_block(state, x, y, z);
53                }
54            }
55        }
56    }
57}
58
59#[expect(
60    clippy::too_many_lines,
61    reason = "direct port of vanilla OceanMonumentPiece.generateDefaultFloor"
62)]
63pub(super) fn generate_default_floor(
64    placer: &mut ScatteredFeaturePlacer<'_, '_>,
65    xoff: i32,
66    zoff: i32,
67    down_opening: bool,
68) {
69    if down_opening {
70        placer.generate_box(
71            xoff,
72            0,
73            zoff,
74            xoff + 2,
75            0,
76            zoff + 7,
77            base_gray(),
78            base_gray(),
79            false,
80        );
81        placer.generate_box(
82            xoff + 5,
83            0,
84            zoff,
85            xoff + 7,
86            0,
87            zoff + 7,
88            base_gray(),
89            base_gray(),
90            false,
91        );
92        placer.generate_box(
93            xoff + 3,
94            0,
95            zoff,
96            xoff + 4,
97            0,
98            zoff + 2,
99            base_gray(),
100            base_gray(),
101            false,
102        );
103        placer.generate_box(
104            xoff + 3,
105            0,
106            zoff + 5,
107            xoff + 4,
108            0,
109            zoff + 7,
110            base_gray(),
111            base_gray(),
112            false,
113        );
114        placer.generate_box(
115            xoff + 3,
116            0,
117            zoff + 2,
118            xoff + 4,
119            0,
120            zoff + 2,
121            base_light(),
122            base_light(),
123            false,
124        );
125        placer.generate_box(
126            xoff + 3,
127            0,
128            zoff + 5,
129            xoff + 4,
130            0,
131            zoff + 5,
132            base_light(),
133            base_light(),
134            false,
135        );
136        placer.generate_box(
137            xoff + 2,
138            0,
139            zoff + 3,
140            xoff + 2,
141            0,
142            zoff + 4,
143            base_light(),
144            base_light(),
145            false,
146        );
147        placer.generate_box(
148            xoff + 5,
149            0,
150            zoff + 3,
151            xoff + 5,
152            0,
153            zoff + 4,
154            base_light(),
155            base_light(),
156            false,
157        );
158    } else {
159        placer.generate_box(
160            xoff,
161            0,
162            zoff,
163            xoff + 7,
164            0,
165            zoff + 7,
166            base_gray(),
167            base_gray(),
168            false,
169        );
170    }
171}
172
173pub(super) fn spawn_elder(placer: &mut ScatteredFeaturePlacer<'_, '_>, x: i32, y: i32, z: i32) {
174    let pos = placer.world_pos(x, y, z);
175    if !placer.clip().contains_blockpos(pos) {
176        return;
177    }
178
179    let entity = Arc::new(RawEntity::new(
180        next_entity_id(),
181        DVec3::new(
182            f64::from(pos.x()) + 0.5,
183            f64::from(pos.y()),
184            f64::from(pos.z()) + 0.5,
185        ),
186        placer.weak_world(),
187        &vanilla_entities::ELDER_GUARDIAN,
188    ));
189    entity.set_persistence_required();
190    entity.snap_to(
191        DVec3::new(
192            f64::from(pos.x()) + 0.5,
193            f64::from(pos.y()),
194            f64::from(pos.z()) + 0.5,
195        ),
196        0.0,
197        0.0,
198    );
199    let _ = placer.add_fresh_entity(entity);
200}
201
202fn fill_keeps(state: BlockStateId) -> bool {
203    let block = state.get_block();
204    block == &vanilla_blocks::ICE
205        || block == &vanilla_blocks::PACKED_ICE
206        || block == &vanilla_blocks::BLUE_ICE
207        || block == &vanilla_blocks::WATER
208}
209
210pub(super) const fn open(room: OceanMonumentRoomData, direction: Direction) -> bool {
211    room.has_opening[direction_index(direction)]
212}
213
214const fn direction_index(direction: Direction) -> usize {
215    match direction {
216        Direction::Down => 0,
217        Direction::Up => 1,
218        Direction::North => 2,
219        Direction::South => 3,
220        Direction::West => 4,
221        Direction::East => 5,
222    }
223}
224
225pub(super) fn base_gray() -> BlockStateId {
226    vanilla_blocks::PRISMARINE.default_state()
227}
228
229pub(super) fn base_light() -> BlockStateId {
230    vanilla_blocks::PRISMARINE_BRICKS.default_state()
231}
232
233pub(super) fn base_black() -> BlockStateId {
234    vanilla_blocks::DARK_PRISMARINE.default_state()
235}
236
237pub(super) fn dot_deco() -> BlockStateId {
238    base_light()
239}
240
241pub(super) fn lamp() -> BlockStateId {
242    vanilla_blocks::SEA_LANTERN.default_state()
243}