@@ -201,31 +201,26 @@ impl WorldAquiferSampler {
201201 // y values are contiguous in packed array:
202202 // ($local_x * $dim_z + $local_z) * $dim_y + $local_y
203203
204- // (x, y - 1, z)
205- let x_0_z_0 = self . packed_position_index ( x, y - 1 , z) ;
206-
207- // (x, y - 1, z + 1)
208- let x_0_z_1 = x_0_z_0 + self . size_y ;
209-
210- // (x + 1, y - 1, z)
211- let x_1_z_0 = x_0_z_0 + self . size_y * self . size_z ;
212-
213- // (x + 1, y - 1, z + 1)
214- let x_1_z_1 = x_1_z_0 + self . size_y ;
204+ let x0z0_index = self . packed_position_index ( x, y - 1 , z) ;
205+ let x0z1_index = x0z0_index + self . size_y ;
206+ let x1z0_index = x0z0_index + self . size_y * self . size_z ;
207+ let x1z1_index = x1z0_index + self . size_y ;
208+ // Remove bounds checks on subsequent indexs
209+ assert ! ( x1z1_index + 2 < self . packed_positions. len( ) ) ;
215210
216211 [
217- self . packed_positions [ x_0_z_0 ] ,
218- self . packed_positions [ x_0_z_1 ] ,
219- self . packed_positions [ x_1_z_0 ] ,
220- self . packed_positions [ x_1_z_1 ] ,
221- self . packed_positions [ x_0_z_0 + 1 ] ,
222- self . packed_positions [ x_0_z_1 + 1 ] ,
223- self . packed_positions [ x_1_z_0 + 1 ] ,
224- self . packed_positions [ x_1_z_1 + 1 ] ,
225- self . packed_positions [ x_0_z_0 + 2 ] ,
226- self . packed_positions [ x_0_z_1 + 2 ] ,
227- self . packed_positions [ x_1_z_0 + 2 ] ,
228- self . packed_positions [ x_1_z_1 + 2 ] ,
212+ self . packed_positions [ x1z1_index + 2 ] ,
213+ self . packed_positions [ x1z0_index + 2 ] ,
214+ self . packed_positions [ x0z1_index + 2 ] ,
215+ self . packed_positions [ x0z0_index + 2 ] ,
216+ self . packed_positions [ x1z1_index + 1 ] ,
217+ self . packed_positions [ x1z0_index + 1 ] ,
218+ self . packed_positions [ x0z1_index + 1 ] ,
219+ self . packed_positions [ x0z0_index + 1 ] ,
220+ self . packed_positions [ x1z1_index ] ,
221+ self . packed_positions [ x1z0_index ] ,
222+ self . packed_positions [ x0z1_index ] ,
223+ self . packed_positions [ x0z0_index ] ,
229224 ]
230225 }
231226
@@ -500,8 +495,7 @@ impl WorldAquiferSampler {
500495 let scaled_y = local_y ! ( sample_y + 1 ) ;
501496 let scaled_z = local_xz ! ( sample_z - 5 ) ;
502497
503- // The 3 closest positions, closest to furthest
504- let mut packed_block_and_hypots = [ ( 0 , i32:: MAX ) ; 3 ] ;
498+ let mut random_positions_and_hypot = [ ( 0 , i32:: MAX ) ; 3 ] ;
505499 for packed_random in self . random_positions_for_pos ( scaled_x, scaled_y, scaled_z) {
506500 let unpacked_x = block_pos:: unpack_x ( packed_random) ;
507501 let unpacked_y = block_pos:: unpack_y ( packed_random) ;
@@ -513,29 +507,31 @@ impl WorldAquiferSampler {
513507
514508 let hypot_squared = local_x * local_x + local_y * local_y + local_z * local_z;
515509
516- if packed_block_and_hypots [ 2 ] . 1 >= hypot_squared {
517- packed_block_and_hypots [ 2 ] = ( packed_random, hypot_squared) ;
510+ if random_positions_and_hypot [ 2 ] . 1 > hypot_squared {
511+ random_positions_and_hypot [ 2 ] = ( packed_random, hypot_squared) ;
518512 }
519513
520- if packed_block_and_hypots [ 1 ] . 1 >= hypot_squared {
521- packed_block_and_hypots [ 2 ] = packed_block_and_hypots [ 1 ] ;
522- packed_block_and_hypots [ 1 ] = ( packed_random, hypot_squared) ;
514+ if random_positions_and_hypot [ 1 ] . 1 > hypot_squared {
515+ random_positions_and_hypot [ 2 ] = random_positions_and_hypot [ 1 ] ;
516+ random_positions_and_hypot [ 1 ] = ( packed_random, hypot_squared) ;
523517 }
524518
525- if packed_block_and_hypots [ 0 ] . 1 >= hypot_squared {
526- packed_block_and_hypots [ 1 ] = packed_block_and_hypots [ 0 ] ;
527- packed_block_and_hypots [ 0 ] = ( packed_random, hypot_squared) ;
519+ if random_positions_and_hypot [ 0 ] . 1 > hypot_squared {
520+ random_positions_and_hypot [ 1 ] = random_positions_and_hypot [ 0 ] ;
521+ random_positions_and_hypot [ 0 ] = ( packed_random, hypot_squared) ;
528522 }
529523 }
530524
531525 let fluid_level2 = self . get_water_level (
532- packed_block_and_hypots [ 0 ] . 0 ,
526+ random_positions_and_hypot [ 0 ] . 0 ,
533527 router,
534528 height_estimator,
535529 sample_options,
536530 ) ;
537- let d =
538- Self :: max_distance ( packed_block_and_hypots[ 0 ] . 1 , packed_block_and_hypots[ 1 ] . 1 ) ;
531+ let d = Self :: max_distance (
532+ random_positions_and_hypot[ 0 ] . 1 ,
533+ random_positions_and_hypot[ 1 ] . 1 ,
534+ ) ;
539535 let block_state = fluid_level2. get_block ( sample_y) ;
540536
541537 if d <= 0f64 {
@@ -553,7 +549,7 @@ impl WorldAquiferSampler {
553549 } else {
554550 let mut barrier_sample = None ;
555551 let fluid_level3 = self . get_water_level (
556- packed_block_and_hypots [ 1 ] . 0 ,
552+ random_positions_and_hypot [ 1 ] . 0 ,
557553 router,
558554 height_estimator,
559555 sample_options,
@@ -571,14 +567,14 @@ impl WorldAquiferSampler {
571567 None
572568 } else {
573569 let fluid_level4 = self . get_water_level (
574- packed_block_and_hypots [ 2 ] . 0 ,
570+ random_positions_and_hypot [ 2 ] . 0 ,
575571 router,
576572 height_estimator,
577573 sample_options,
578574 ) ;
579575 let f = Self :: max_distance (
580- packed_block_and_hypots [ 0 ] . 1 ,
581- packed_block_and_hypots [ 2 ] . 1 ,
576+ random_positions_and_hypot [ 0 ] . 1 ,
577+ random_positions_and_hypot [ 2 ] . 1 ,
582578 ) ;
583579 if f > 0f64 {
584580 let g = d
@@ -597,8 +593,8 @@ impl WorldAquiferSampler {
597593 }
598594
599595 let g = Self :: max_distance (
600- packed_block_and_hypots [ 1 ] . 1 ,
601- packed_block_and_hypots [ 2 ] . 1 ,
596+ random_positions_and_hypot [ 1 ] . 1 ,
597+ random_positions_and_hypot [ 2 ] . 1 ,
602598 ) ;
603599 if g > 0f64 {
604600 let h = d
@@ -685,7 +681,7 @@ pub trait AquiferSamplerImpl {
685681}
686682
687683#[ cfg( test) ]
688- mod test {
684+ mod random_positions_and_hypot {
689685 use std:: { mem, sync:: LazyLock } ;
690686
691687 use pumpkin_data:: noise_router:: OVERWORLD_BASE_NOISE_ROUTER ;
0 commit comments