fix: rabbit dig occlusion refresh, bounds guard panic, world floor clamp
- Fire TileOcclusionEvent for 27-tile neighbourhood (3x3x3) so tiles above the dug tile recalculate visibility and stop rendering black - Clamp gravity in movement to world minimum z — rabbits digging the floor below them now stop at world floor instead of falling past it - Assert bounds in remove_floor/remove_fixture before pos_to_index to panic with z/coords info instead of silently overflowing - Hoist ITILE_SIZE, CHUNK_SIZE, Z_BELOW, Z_ABOVE to module-level imports in tilemap.rs
This commit is contained in:
@@ -128,9 +128,19 @@ pub fn rabbit_dig_system(
|
||||
|
||||
if tilemap.remove_floor(&below_pos).is_some() {
|
||||
tile_changed.write(TileChangedEvent { pos: below_pos });
|
||||
occlusion.write(TileOcclusionEvent {
|
||||
tile_position: below_pos,
|
||||
});
|
||||
|
||||
// Refresh visibility for the dug tile and all 26 neighbours.
|
||||
// Removing a tile changes what is visible from every adjacent position.
|
||||
for dz in -1..=1i32 {
|
||||
for dy in -1..=1i32 {
|
||||
for dx in -1..=1i32 {
|
||||
occlusion.write(TileOcclusionEvent {
|
||||
tile_position: below_pos
|
||||
+ IVec3::new(dx * ITILE_SIZE, dy * ITILE_SIZE, dz * ITILE_SIZE),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -609,7 +609,12 @@ pub fn movement(
|
||||
.for_each(|(mut ambulatory, mut transform)| {
|
||||
let current_pos = transform.translation;
|
||||
if !is_standable_tile(&tilemap, current_pos.as_ivec3()) {
|
||||
transform.translation.z -= TILE_SIZE;
|
||||
// Don't fall below world minimum z — rabbits digging can leave no floor
|
||||
// to stand on, but they should stop at the world floor rather than
|
||||
// falling into oblivion and panicking pos_to_index overflow.
|
||||
if transform.translation.z > -(crate::world::chunks::Z_BELOW as f32) * TILE_SIZE {
|
||||
transform.translation.z -= TILE_SIZE;
|
||||
}
|
||||
ambulatory.current_path = None;
|
||||
ambulatory.target = None;
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user