steel_worldgen/structure/
single_piece.rs1use glam::IVec3;
4use steel_registry::structure::StructureData;
5use steel_utils::random::legacy_random::LegacyRandom;
6use steel_utils::{BoundingBox, Identifier};
7
8use crate::structure::{
9 GenerationStub, ProceduralPieceData, Structure, StructureGenerationContext, StructurePiece,
10 StructurePiecePayload,
11};
12
13pub struct BuriedTreasureStructure;
15
16const fn buried_treasure_piece(x: i32, z: i32) -> StructurePiece {
17 StructurePiece {
18 piece_type: Identifier::new_static("minecraft", "btp"),
19 bounding_box: BoundingBox::new(IVec3::new(x, 90, z), IVec3::new(x, 90, z)),
20 gen_depth: 0,
21 orientation: None,
22 payload: StructurePiecePayload::Procedural(ProceduralPieceData::BuriedTreasure),
23 ground_level_delta: 0,
24 junctions: Vec::new(),
25 projection: None,
26 }
27}
28
29impl Structure for BuriedTreasureStructure {
30 fn find_generation_point(
31 &self,
32 ctx: &mut dyn StructureGenerationContext,
33 structure: &StructureData,
34 _rng: &mut LegacyRandom,
35 ) -> Option<GenerationStub> {
36 let ocean_floor_y = ctx.base_height(ctx.center_block_x(), ctx.center_block_z(), true) - 1;
37 let biome = ctx.biome_at(ctx.center_block_x(), ocean_floor_y, ctx.center_block_z());
38 if !structure.allowed_biomes.contains(&biome.key) {
39 return None;
40 }
41
42 let (x, z) = (ctx.chunk_min_x() + 9, ctx.chunk_min_z() + 9);
43 Some(GenerationStub {
44 position: (x, 90, z),
45 pieces: vec![buried_treasure_piece(x, z)],
46 })
47 }
48}
49
50#[cfg(test)]
51mod tests {
52 use super::*;
53
54 #[test]
55 fn buried_treasure_piece_uses_procedural_payload() {
56 let piece = buried_treasure_piece(25, -39);
57
58 assert_eq!(piece.piece_type, Identifier::new_static("minecraft", "btp"));
59 assert_eq!(
60 piece.bounding_box,
61 BoundingBox::new(IVec3::new(25, 90, -39), IVec3::new(25, 90, -39))
62 );
63 assert_eq!(piece.gen_depth, 0);
64 assert_eq!(piece.orientation, None);
65 assert!(matches!(
66 piece.payload,
67 StructurePiecePayload::Procedural(ProceduralPieceData::BuriedTreasure)
68 ));
69 }
70}