Simplify logic and reduce nesting in chunk simulation system

This commit is contained in:
Jarrod Doyle 2024-01-29 15:34:17 +00:00
parent 9e3dc5b3d4
commit b1ea38febe
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
1 changed files with 20 additions and 20 deletions

View File

@ -136,28 +136,28 @@ pub fn simulate_chunk_system(mut chunk: Query<&mut Chunk>) {
match element { match element {
Element::Air => {} Element::Air => {}
Element::Sand => { Element::Sand => {
if y != 0 { if y == 0 {
let bottom = chunk.get_cell(x, y - 1).unwrap(); continue;
if *bottom == Element::Air { }
chunk.swap_cells(x, y, x, y - 1);
continue;
}
if x != 0 { // Bottom
let bottom_left = chunk.get_cell(x - 1, y - 1).unwrap(); if *chunk.get_cell(x, y - 1).unwrap() == Element::Air {
if *bottom_left == Element::Air { chunk.swap_cells(x, y, x, y - 1);
chunk.swap_cells(x, y, x - 1, y - 1); continue;
continue; }
}
}
if x != chunk.width - 1 { // Bottom left
let bottom_right = chunk.get_cell(x + 1, y - 1).unwrap(); if x != 0 && *chunk.get_cell(x - 1, y - 1).unwrap() == Element::Air {
if *bottom_right == Element::Air { chunk.swap_cells(x, y, x - 1, y - 1);
chunk.swap_cells(x, y, x + 1, y - 1); continue;
continue; }
}
} // Bottom right
if x != chunk.width - 1
&& *chunk.get_cell(x + 1, y - 1).unwrap() == Element::Air
{
chunk.swap_cells(x, y, x + 1, y - 1);
continue;
} }
} }
} }