steel_core/worldgen/feature/features/
projected_random_patchy_square.rs1use super::super::prelude::*;
2use super::super::runner::FeatureDecorationRunner;
3
4impl FeatureDecorationRunner {
5 pub(in crate::worldgen::feature) fn place_projected_random_patchy_square_feature(
6 region: &mut WorldGenRegion<'_>,
7 registry: &Registry,
8 random: &mut WorldgenRandom,
9 config: &ProjectedRandomPatchySquareConfiguration,
10 origin: BlockPos,
11 ) -> bool {
12 let size = config.size.sample(random);
13 let bound = size * size + 1;
14
15 for dx in -size..=size {
16 for dz in -size..=size {
17 let probability = dx.abs() * dz.abs();
18 if random.next_i32_bounded(bound) >= bound - probability {
19 continue;
20 }
21
22 let mut base = origin.offset(dx, 0, dz);
23 let mut drop = config.max_projection_height;
24 while BlockStateProviderEvaluator::test_block_predicate(
25 region,
26 registry,
27 &config.project_through,
28 base.below(),
29 ) {
30 base = base.below();
31 drop -= 1;
32 if drop <= 0 {
33 break;
34 }
35 }
36
37 let Some(state) = BlockStateProviderEvaluator::sample_block_state_provider_optional(
38 region,
39 registry,
40 random,
41 &config.block,
42 base,
43 ) else {
44 continue;
45 };
46 let _ = region.set_block_state(base, state, UpdateFlags::UPDATE_CLIENTS);
47 }
48 }
49
50 true
51 }
52}