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,24 +136,26 @@ pub fn simulate_chunk_system(mut chunk: Query<&mut Chunk>) {
match element {
Element::Air => {}
Element::Sand => {
if y != 0 {
let bottom = chunk.get_cell(x, y - 1).unwrap();
if *bottom == Element::Air {
if y == 0 {
continue;
}
// Bottom
if *chunk.get_cell(x, y - 1).unwrap() == Element::Air {
chunk.swap_cells(x, y, x, y - 1);
continue;
}
if x != 0 {
let bottom_left = chunk.get_cell(x - 1, y - 1).unwrap();
if *bottom_left == Element::Air {
// Bottom left
if x != 0 && *chunk.get_cell(x - 1, y - 1).unwrap() == Element::Air {
chunk.swap_cells(x, y, x - 1, y - 1);
continue;
}
}
if x != chunk.width - 1 {
let bottom_right = chunk.get_cell(x + 1, y - 1).unwrap();
if *bottom_right == Element::Air {
// 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;
}
@ -161,8 +163,6 @@ pub fn simulate_chunk_system(mut chunk: Query<&mut Chunk>) {
}
}
}
}
}
}
pub fn update_chunk_texture_system(