From ebf0d803b647bfdca642c0958fa41246ea433818 Mon Sep 17 00:00:00 2001 From: alemidev Date: Sun, 3 Jul 2022 00:48:23 +0200 Subject: [PATCH] fix: negative offset for multi block change too --- src/chunk.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/chunk.rs b/src/chunk.rs index b27d3e0..3268509 100644 --- a/src/chunk.rs +++ b/src/chunk.rs @@ -318,8 +318,12 @@ impl World { } pub fn put_block(&mut self, x: i32, y:i32, z:i32, id:u16) -> Option { - let x_off = (x % 16) as usize; let z_off = (z % 16) as usize; - let c = self.chunks.get_mut(&(x as i32 / 16, z as i32 / 16))?; + let mut chunk_x = x / 16; + let mut chunk_z = z / 16; + if chunk_x < 0 && chunk_x % 16 != 0 { chunk_x-=1; } + if chunk_z < 0 && chunk_z % 16 != 0 { chunk_z-=1; } + let x_off = abs(x, 16) as usize; let z_off = abs(z, 16) as usize; + let c = self.chunks.get_mut(&(chunk_x, chunk_z))?; let old_block = c.block_states[x_off][y as usize][z_off]; c.block_states[x_off][y as usize][z_off] = id; return Some(old_block);