@@ -4,7 +4,7 @@ use ferrumc_macros::block;
44use ferrumc_world:: block_state_id:: BlockStateId ;
55use ferrumc_world:: chunk_format:: Chunk ;
66use ferrumc_world:: edit_batch:: EditBatch ;
7- use ferrumc_world:: pos:: { BlockPos , ChunkHeight } ;
7+ use ferrumc_world:: pos:: { BlockPos , ChunkColumnPos , ChunkHeight , ChunkPos } ;
88
99pub ( crate ) struct PlainsBiome ;
1010
@@ -19,8 +19,7 @@ impl BiomeGenerator for PlainsBiome {
1919
2020 fn generate_chunk (
2121 & self ,
22- x : i32 ,
23- z : i32 ,
22+ pos : ChunkPos ,
2423 noise : & NoiseGenerator ,
2524 ) -> Result < Chunk , WorldGenError > {
2625 let mut chunk = Chunk :: new ( ChunkHeight :: new ( -64 , 384 ) ) ;
@@ -33,11 +32,12 @@ impl BiomeGenerator for PlainsBiome {
3332 }
3433
3534 // Then generate some heights
36- for chunk_x in 0 ..16i64 {
37- for chunk_z in 0 ..16i64 {
38- let global_x = i64:: from ( x) * 16 + chunk_x;
39- let global_z = i64:: from ( z) * 16 + chunk_z;
40- let height = noise. get_noise ( global_x as f64 , global_z as f64 ) ;
35+ for chunk_x in 0 ..16 {
36+ for chunk_z in 0 ..16 {
37+ let curr_pos = pos. column_pos ( ChunkColumnPos :: new ( chunk_x, chunk_z) ) ;
38+ let global_x = curr_pos. x ( ) ;
39+ let global_z = curr_pos. z ( ) ;
40+ let height = noise. get_noise ( f64:: from ( global_x) , f64:: from ( global_z) ) ;
4141 let height = ( height * 64.0 ) as i32 + 64 ;
4242 heights. push ( ( global_x, global_z, height) ) ;
4343 }
@@ -58,22 +58,14 @@ impl BiomeGenerator for PlainsBiome {
5858 for y in 0 ..height {
5959 if y + above_filled_sections <= 64 {
6060 batch. set_block (
61- BlockPos :: of (
62- global_x as i32 ,
63- y + above_filled_sections,
64- global_z as i32 ,
65- )
66- . chunk_block_pos ( ) ,
61+ BlockPos :: of ( global_x, y + above_filled_sections, global_z)
62+ . chunk_block_pos ( ) ,
6763 block ! ( "sand" ) ,
6864 ) ;
6965 } else {
7066 batch. set_block (
71- BlockPos :: of (
72- global_x as i32 ,
73- y + above_filled_sections,
74- global_z as i32 ,
75- )
76- . chunk_block_pos ( ) ,
67+ BlockPos :: of ( global_x, y + above_filled_sections, global_z)
68+ . chunk_block_pos ( ) ,
7769 block ! ( "grass_block" , { snowy: false } ) ,
7870 ) ;
7971 }
@@ -95,17 +87,25 @@ mod test {
9587 fn test_is_ok ( ) {
9688 let generator = PlainsBiome { } ;
9789 let noise = NoiseGenerator :: new ( 0 ) ;
98- assert ! ( generator. generate_chunk( 0 , 0 , & noise) . is_ok( ) ) ;
90+ assert ! (
91+ generator
92+ . generate_chunk( ChunkPos :: new( 0 , 0 ) , & noise)
93+ . is_ok( )
94+ ) ;
9995 }
10096
10197 #[ test]
10298 fn test_random_chunk_generation ( ) {
10399 let generator = PlainsBiome { } ;
104100 let noise = NoiseGenerator :: new ( 0 ) ;
105101 for _ in 0 ..100 {
106- let x = rand:: random :: < i32 > ( ) ;
107- let z = rand:: random :: < i32 > ( ) ;
108- assert ! ( generator. generate_chunk( x, z, & noise) . is_ok( ) ) ;
102+ let x = rand:: random :: < i32 > ( ) & ( ( 1 << 22 ) - 1 ) ;
103+ let z = rand:: random :: < i32 > ( ) & ( ( 1 << 22 ) - 1 ) ;
104+ assert ! (
105+ generator
106+ . generate_chunk( ChunkPos :: new( x, z) , & noise)
107+ . is_ok( )
108+ ) ;
109109 }
110110 }
111111
@@ -115,12 +115,12 @@ mod test {
115115 let noise = NoiseGenerator :: new ( 0 ) ;
116116 assert ! (
117117 generator
118- . generate_chunk( 1610612735 , 1610612735 , & noise)
118+ . generate_chunk( ChunkPos :: new ( ( 1 << 22 ) - 1 , ( 1 << 22 ) - 1 ) , & noise)
119119 . is_ok( )
120120 ) ;
121121 assert ! (
122122 generator
123- . generate_chunk( - 1610612735 , -1610612735 , & noise)
123+ . generate_chunk( ChunkPos :: new ( - ( ( 1 << 22 ) - 1 ) , -( ( 1 << 22 ) - 1 ) ) , & noise)
124124 . is_ok( )
125125 ) ;
126126 }
@@ -131,7 +131,11 @@ mod test {
131131 let generator = PlainsBiome { } ;
132132 let seed = rand:: random :: < u64 > ( ) ;
133133 let noise = NoiseGenerator :: new ( seed) ;
134- assert ! ( generator. generate_chunk( 0 , 0 , & noise) . is_ok( ) ) ;
134+ assert ! (
135+ generator
136+ . generate_chunk( ChunkPos :: new( 0 , 0 ) , & noise)
137+ . is_ok( )
138+ ) ;
135139 }
136140 }
137141}
0 commit comments