Skip to main content

steel_core/worldgen/feature/
predicates.rs

1use super::prelude::*;
2use super::runner::FeatureDecorationRunner;
3
4impl FeatureDecorationRunner {
5    pub(super) fn test_optional_block_predicate(
6        level: &impl LevelReader,
7        registry: &Registry,
8        predicate: Option<&BlockPredicate>,
9        origin: BlockPos,
10    ) -> bool {
11        predicate.is_none_or(|predicate| {
12            BlockStateProviderEvaluator::test_block_predicate(level, registry, predicate, origin)
13        })
14    }
15
16    pub(super) fn biome_allows_feature(
17        region: &WorldGenRegion<'_>,
18        registry: &Registry,
19        biome_zoom_seed: i64,
20        origin: BlockPos,
21        biome_filter_feature_key: Option<&Identifier>,
22    ) -> bool {
23        let biome_id = fuzzed_biome_at_block(biome_zoom_seed, origin, |quart| {
24            region.noise_biome_id(quart.x, quart.y, quart.z)
25        });
26        let Some(biome) = registry.biomes.by_id(usize::from(biome_id)) else {
27            panic!("biome filter resolved unknown biome id {biome_id}");
28        };
29        let Some(target_feature_key) = biome_filter_feature_key else {
30            panic!(
31                "Tried to biome check an unregistered feature, or a feature that should not restrict the biome"
32            );
33        };
34
35        biome
36            .features
37            .iter()
38            .flatten()
39            .any(|feature_key| feature_key == target_feature_key)
40    }
41}