From 0ded44d635610383c55e04f9bd21f9eaea46b1ff Mon Sep 17 00:00:00 2001 From: Knightress Paladin Date: Thu, 15 Jul 2021 12:35:29 -0700 Subject: [PATCH] Cleaned up chunk-relative block setting math --- server/src/sys/wiring/dispatch_actions.rs | 25 +++++++++-------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/server/src/sys/wiring/dispatch_actions.rs b/server/src/sys/wiring/dispatch_actions.rs index 782b7bba62..d5ae4dc6ad 100644 --- a/server/src/sys/wiring/dispatch_actions.rs +++ b/server/src/sys/wiring/dispatch_actions.rs @@ -153,20 +153,15 @@ fn dispatch_action_set_block( block_change: &mut Write, pos: Option<&Pos>, ) { - let chunk_origin = match pos { - Some(opos) => vek::Vec3::new( - (opos.0.x as i32 / TerrainChunkSize::RECT_SIZE.x as i32) - * TerrainChunkSize::RECT_SIZE.x as i32, - (opos.0.y as i32 / TerrainChunkSize::RECT_SIZE.y as i32) - * TerrainChunkSize::RECT_SIZE.y as i32, - 0, - ), - None => vek::Vec3::new(0, 0, 0), - }; - let offset_pos = chunk_origin - .iter() - .zip(coord.iter()) - .map(|(p, c)| p + c) - .collect(); + let chunk_origin = pos + .map(|opos| { + opos.0 + .xy() + .as_::() + .map2(TerrainChunkSize::RECT_SIZE.as_::(), |a, b| (a / b) * b) + .with_z(0) + }) + .unwrap_or_else(vek::Vec3::zero); + let offset_pos = chunk_origin + coord; block_change.set(offset_pos, block); }