fix: loaded-chunk guard in calculate_visibility, reset dig timer while airborne

- calculate_visibility: None from floor_tiles.get() now checks tilemap.chunks
  to confirm the neighbour's chunk is loaded before treating it as air.
  Without this, unloaded world borders and pending chunks were incorrectly
  seen as open space, causing underground tiles to render as black.
- rabbit_dig_system: skip and reset timer when entity is not on standable
  ground, preventing rapid-dig cascade as rabbit falls through multiple levels.
This commit is contained in:
2026-03-21 14:25:28 +00:00
parent 36f068bf0c
commit ec5287ca86
3 changed files with 15 additions and 4 deletions
+4
View File
@@ -117,6 +117,10 @@ pub fn rabbit_dig_system(
time: Res<Time>,
) {
for (transform, mut dig_timer) in query.iter_mut() {
if !tilemap.is_standable(transform.translation.as_ivec3()) {
dig_timer.secs_remaining = DIG_INTERVAL_SECS;
continue;
}
dig_timer.secs_remaining -= time.delta_secs();
if dig_timer.secs_remaining > 0.0 {
continue;
+10 -3
View File
@@ -3,7 +3,7 @@ use crate::{
entities::item::ItemRotationState,
game,
world::{
chunks::{Z_BELOW, Z_TOTAL},
chunks::{world_to_chunk, Z_BELOW, Z_TOTAL},
tiles::{ChunkLayerKey, TileMap, TilemapChunkRegistry, LAYER_FLOOR},
},
};
@@ -144,8 +144,15 @@ pub fn calculate_visibility(pos: IVec3, tilemap: &TileMap) -> [u32; 8] {
);
match tilemap.floor_tiles.get(&neighbor_pos) {
Some(tile) if tile.id == 0 => break 'neighbor_check true,
// Absent tile means open space — treat as air for visibility.
None => break 'neighbor_check true,
// Absent tile: only treat as air if the chunk is loaded.
// Unloaded chunks are unknown — treat as opaque to avoid
// spurious visibility at world borders and during generation.
None => {
let neighbor_chunk = world_to_chunk(neighbor_pos);
if tilemap.chunks.contains_key(&neighbor_chunk) {
break 'neighbor_check true;
}
}
_ => {}
}
}