Skip to main content

steel_core/entity/
spawn_placements.rs

1//! Entity-type spawn placement dispatch.
2
3use rand::Rng;
4use steel_registry::entity_type::EntityTypeRef;
5use steel_utils::{BlockPos, types::Difficulty};
6
7use crate::entity::{ENTITIES, EntitySpawnReason};
8use crate::world::World;
9
10/// Vanilla `SpawnPlacements`.
11///
12/// Predicates are each entity's `SPAWN_RULE`, registered by `#[entity_behavior(spawn_rule)]`.
13/// Placement type and heightmap are not modeled yet because only the spawner path consumes this.
14pub(crate) struct SpawnPlacements;
15
16impl SpawnPlacements {
17    /// Checks the vanilla placement predicate used by normal mob spawners.
18    pub(crate) fn check_spawner_spawn_rules(
19        entity_type: EntityTypeRef,
20        world: &World,
21        pos: BlockPos,
22        random: &mut dyn Rng,
23    ) -> bool {
24        if !entity_type.allowed_in_peaceful && world.difficulty() == Difficulty::Peaceful {
25            return false;
26        }
27
28        ENTITIES
29            .spawn_rule(entity_type)
30            .is_none_or(|rule| rule(entity_type, world, EntitySpawnReason::Spawner, pos, random))
31    }
32}