@@ -4,8 +4,8 @@ use rand_pcg::Pcg64Mcg;
4
4
use std:: mem;
5
5
6
6
const MIN_SPIRIT_LIGHT : f32 = 50. ;
7
+ const NOISE : f32 = 0.25 ;
7
8
8
- // TODO the last couple spirit light placements are weird
9
9
pub struct SpiritLightProvider {
10
10
rng : Pcg64Mcg ,
11
11
pub amount : f32 ,
@@ -18,11 +18,10 @@ impl SpiritLightProvider {
18
18
rng : Pcg64Mcg :: from_rng ( rng) . expect ( SEED_FAILED_MESSAGE ) ,
19
19
amount : amount as f32 ,
20
20
next_amount : MIN_SPIRIT_LIGHT ,
21
- noise : Uniform :: new_inclusive ( 0.75 , 1.25 ) ,
21
+ noise : Uniform :: new_inclusive ( 1. - NOISE , 1. + NOISE ) ,
22
22
}
23
23
}
24
24
25
- // TODO in a single world seed, the reported spirit_light_placements_remaining have some jumps, not sure that should be the case
26
25
pub fn take ( & mut self , spirit_light_placements_remaining : usize ) -> usize {
27
26
// For brevity, spirit_light_placements_remaining is referred to as remaining in this comment
28
27
//
@@ -46,9 +45,12 @@ impl SpiritLightProvider {
46
45
let a = ( 2. * self . amount / ( remaining - 1. ) - 2. * self . next_amount )
47
46
/ ( remaining + 1. - 2. * remaining) ;
48
47
let b = self . next_amount - a * remaining;
49
- let mut next = a * ( remaining - 1. ) + b;
50
- self . amount -= self . next_amount ;
51
- next *= self . rng . sample ( self . noise ) ;
52
- mem:: replace ( & mut self . next_amount , next) . round ( ) as usize
48
+ let next = a * ( remaining - 1. ) + b;
49
+ let mut amount = mem:: replace ( & mut self . next_amount , next) ;
50
+
51
+ // Apply random noise after setting the next amount to prevent snowballing
52
+ amount = ( amount * self . rng . sample ( self . noise ) ) . round ( ) ;
53
+ self . amount -= amount;
54
+ amount as usize
53
55
}
54
56
}
0 commit comments