mc_vanilla/
ext.rs

1use mc_core::world::level::LevelEnv;
2use mc_core::entity::GlobalEntities;
3use mc_core::block::GlobalBlocks;
4use mc_core::biome::GlobalBiomes;
5use mc_core::heightmap::GlobalHeightmaps;
6use crate::entity::VANILLA_ENTITIES;
7use crate::block::VANILLA_BLOCKS;
8use crate::biome::VANILLA_BIOMES;
9use crate::heightmap::VANILLA_HEIGHTMAPS;
10
11
12/// A trait to implement on registers or group of registers to provide
13/// a default constructor for vanilla contents.
14pub trait WithVanilla {
15    fn with_vanilla() -> Self;
16}
17
18
19impl WithVanilla for GlobalBlocks {
20    fn with_vanilla() -> Self {
21        // SAFETY: It's safe to unwrap because the states count for vanilla
22        //         (around 20k states) can't overflow 32 bits save ID.
23        let mut blocks = Self::with_all(&VANILLA_BLOCKS).unwrap();
24        crate::block::material::register_tags(&mut blocks);
25        blocks
26    }
27}
28
29
30impl WithVanilla for GlobalBiomes {
31    fn with_vanilla() -> Self {
32        // SAFETY: Check safety comment for vanilla blocks.
33        Self::with_all(&VANILLA_BIOMES).unwrap()
34    }
35}
36
37
38impl WithVanilla for GlobalEntities {
39    fn with_vanilla() -> Self {
40        Self::with_all(&VANILLA_ENTITIES)
41    }
42}
43
44
45impl WithVanilla for GlobalHeightmaps {
46    fn with_vanilla() -> Self {
47        Self::with_all(&VANILLA_HEIGHTMAPS)
48    }
49}
50
51
52impl WithVanilla for LevelEnv {
53    fn with_vanilla() -> Self {
54        Self::new(
55            GlobalBlocks::with_vanilla(),
56            GlobalBiomes::with_vanilla(),
57            GlobalEntities::with_vanilla(),
58            GlobalHeightmaps::with_vanilla()
59        )
60    }
61}