Prevented terrain scatter spawning in the air

This commit is contained in:
Joshua Barretto 2020-08-23 14:29:57 +01:00
parent 89a6a06a7b
commit 6e7620dbe1

View File

@ -312,20 +312,30 @@ pub fn apply_scatter_to<'a>(
}); });
if let Some(bk) = bk { if let Some(bk) = bk {
let mut z = col_sample.alt as i32 - 4; let alt = col_sample.alt as i32;
for _ in 0..8 {
if vol // Find the intersection between ground and air, if there is one near the
.get(Vec3::new(offs.x, offs.y, z)) // surface
.map(|b| !b.is_solid()) if let Some(solid_end) = (-4..8)
.unwrap_or(true) .find(|z| {
{ vol.get(Vec3::new(offs.x, offs.y, alt + z))
let _ = vol.set( .map(|b| b.is_solid())
Vec3::new(offs.x, offs.y, z), .unwrap_or(false)
Block::new(bk, Rgb::broadcast(0)), })
); .and_then(|solid_start| {
break; (1..8)
} .map(|z| solid_start + z)
z += 1; .find(|z| {
vol.get(Vec3::new(offs.x, offs.y, alt + z))
.map(|b| !b.is_solid())
.unwrap_or(true)
})
})
{
let _ = vol.set(
Vec3::new(offs.x, offs.y, alt + solid_end),
Block::new(bk, Rgb::broadcast(0)),
);
} }
} }
} }