Skip to main content

steel_core/worldgen/feature/features/
nether_forest_vegetation.rs

1use steel_registry::vanilla_block_tags::BlockTag;
2
3use super::super::prelude::*;
4use super::super::runner::FeatureDecorationRunner;
5
6impl FeatureDecorationRunner {
7    pub(in crate::worldgen::feature) fn place_nether_forest_vegetation_feature(
8        region: &mut WorldGenRegion<'_>,
9        registry: &Registry,
10        random: &mut WorldgenRandom,
11        config: &NetherForestVegetationConfiguration,
12        origin: BlockPos,
13    ) -> bool {
14        let below_state = region.block_state(origin.below());
15        if !below_state.get_block().has_tag(&BlockTag::NYLIUM) {
16            return false;
17        }
18
19        if origin.y() < region.min_y() + 1 || origin.y() + 1 > region.max_y_exclusive() - 1 {
20            return false;
21        }
22
23        let mut placed = 0;
24        for _ in 0..config.spread_width * config.spread_width {
25            let final_pos = origin.offset(
26                random.next_i32_bounded(config.spread_width)
27                    - random.next_i32_bounded(config.spread_width),
28                random.next_i32_bounded(config.spread_height)
29                    - random.next_i32_bounded(config.spread_height),
30                random.next_i32_bounded(config.spread_width)
31                    - random.next_i32_bounded(config.spread_width),
32            );
33            let state = Self::sample_block_state_provider(
34                region,
35                registry,
36                random,
37                &config.state_provider,
38                final_pos,
39            );
40            let behavior = BLOCK_BEHAVIORS.get_behavior(state.get_block());
41            if region.block_state(final_pos).is_air()
42                && final_pos.y() > region.min_y()
43                && behavior.can_survive(state, region, final_pos)
44            {
45                let _ = region.set_block_state(final_pos, state, UpdateFlags::UPDATE_CLIENTS);
46                placed += 1;
47            }
48        }
49
50        placed > 0
51    }
52}