steel_core/worldgen/feature/features/
block_blob.rs1use super::super::prelude::*;
2use super::super::runner::FeatureDecorationRunner;
3
4impl FeatureDecorationRunner {
5 pub(in crate::worldgen::feature) fn place_block_blob_feature(
6 region: &mut WorldGenRegion<'_>,
7 registry: &Registry,
8 random: &mut WorldgenRandom,
9 config: &BlockBlobConfiguration,
10 mut origin: BlockPos,
11 ) -> bool {
12 while origin.y() > region.min_y() + 3
13 && !Self::test_block_predicate(region, registry, &config.can_place_on, origin.below())
14 {
15 origin = origin.below();
16 }
17
18 if origin.y() <= region.min_y() + 3 {
19 return false;
20 }
21
22 let state = Self::block_state_from_data(registry, &config.state);
23 for _ in 0..3 {
24 let x_radius = random.next_i32_bounded(2);
25 let y_radius = random.next_i32_bounded(2);
26 let z_radius = random.next_i32_bounded(2);
27 let threshold = (x_radius + y_radius + z_radius) as f32 * 0.333 + 0.5;
28 let threshold_squared = threshold * threshold;
29
30 for x in origin.x() - x_radius..=origin.x() + x_radius {
31 for y in origin.y() - y_radius..=origin.y() + y_radius {
32 for z in origin.z() - z_radius..=origin.z() + z_radius {
33 let dx = x - origin.x();
34 let dy = y - origin.y();
35 let dz = z - origin.z();
36 if (dx * dx + dy * dy + dz * dz) as f32 <= threshold_squared {
37 let _ = region.set_block_state(
38 BlockPos::new(x, y, z),
39 state,
40 UpdateFlags::UPDATE_ALL,
41 );
42 }
43 }
44 }
45 }
46
47 origin = origin.offset(
48 -1 + random.next_i32_bounded(2),
49 -random.next_i32_bounded(2),
50 -1 + random.next_i32_bounded(2),
51 );
52 }
53
54 true
55 }
56}