Cleaned up chunk-relative block setting math

This commit is contained in:
Knightress Paladin 2021-07-15 12:35:29 -07:00
parent 9864344cfe
commit 0ded44d635

View File

@ -153,20 +153,15 @@ fn dispatch_action_set_block(
block_change: &mut Write<BlockChange>, block_change: &mut Write<BlockChange>,
pos: Option<&Pos>, pos: Option<&Pos>,
) { ) {
let chunk_origin = match pos { let chunk_origin = pos
Some(opos) => vek::Vec3::new( .map(|opos| {
(opos.0.x as i32 / TerrainChunkSize::RECT_SIZE.x as i32) opos.0
* TerrainChunkSize::RECT_SIZE.x as i32, .xy()
(opos.0.y as i32 / TerrainChunkSize::RECT_SIZE.y as i32) .as_::<i32>()
* TerrainChunkSize::RECT_SIZE.y as i32, .map2(TerrainChunkSize::RECT_SIZE.as_::<i32>(), |a, b| (a / b) * b)
0, .with_z(0)
), })
None => vek::Vec3::new(0, 0, 0), .unwrap_or_else(vek::Vec3::zero);
}; let offset_pos = chunk_origin + coord;
let offset_pos = chunk_origin
.iter()
.zip(coord.iter())
.map(|(p, c)| p + c)
.collect();
block_change.set(offset_pos, block); block_change.set(offset_pos, block);
} }