From 776d3caefc943893c8fd3bde145c6666cb95102f Mon Sep 17 00:00:00 2001 From: popertots Date: Sat, 21 Mar 2026 17:10:52 +0000 Subject: [PATCH] fix: dig_rng sequential multiply-add mixing Switch from add-then-XOR pattern to proper sequential multiply-add avalanche. Each coordinate feeds into the next multiply, preventing correlation between adjacent tiles when rare drops are introduced. --- src/entities/item/drop_table.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/entities/item/drop_table.rs b/src/entities/item/drop_table.rs index 36b5882..f9e48e6 100644 --- a/src/entities/item/drop_table.rs +++ b/src/entities/item/drop_table.rs @@ -54,12 +54,16 @@ impl DropTable { pub fn dig_rng(pos: IVec3) -> u32 { let mut h = (SEED as u64) - .wrapping_add(pos.x as u64) .wrapping_mul(0x9e3779b97f4a7c15) - ^ (pos.y as u64).wrapping_mul(0x6c62272e07bb0142) - ^ (pos.z as u64).wrapping_mul(0x94d049bb133111eb); - let h32 = (h ^ (h >> 32)) as u32; - h32 ^ (h32 >> 16) + .wrapping_add(pos.x as u64) + .wrapping_mul(0x6c62272e07bb0142) + .wrapping_add(pos.y as u64) + .wrapping_mul(0x94d049bb133111eb) + .wrapping_add(pos.z as u64); + h ^= h >> 32; + h = h.wrapping_mul(0xbf58476d1ce4e5b9); + h ^= h >> 32; + h as u32 } #[derive(Deserialize)]