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:
+1
-1
@@ -6,4 +6,4 @@ vsync = "mailbox"
|
|||||||
[spawn_counts]
|
[spawn_counts]
|
||||||
dorfs = 50
|
dorfs = 50
|
||||||
pigs = 5
|
pigs = 5
|
||||||
rabbits = 5
|
rabbits = 15
|
||||||
@@ -117,6 +117,10 @@ pub fn rabbit_dig_system(
|
|||||||
time: Res<Time>,
|
time: Res<Time>,
|
||||||
) {
|
) {
|
||||||
for (transform, mut dig_timer) in query.iter_mut() {
|
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();
|
dig_timer.secs_remaining -= time.delta_secs();
|
||||||
if dig_timer.secs_remaining > 0.0 {
|
if dig_timer.secs_remaining > 0.0 {
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use crate::{
|
|||||||
entities::item::ItemRotationState,
|
entities::item::ItemRotationState,
|
||||||
game,
|
game,
|
||||||
world::{
|
world::{
|
||||||
chunks::{Z_BELOW, Z_TOTAL},
|
chunks::{world_to_chunk, Z_BELOW, Z_TOTAL},
|
||||||
tiles::{ChunkLayerKey, TileMap, TilemapChunkRegistry, LAYER_FLOOR},
|
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) {
|
match tilemap.floor_tiles.get(&neighbor_pos) {
|
||||||
Some(tile) if tile.id == 0 => break 'neighbor_check true,
|
Some(tile) if tile.id == 0 => break 'neighbor_check true,
|
||||||
// Absent tile means open space — treat as air for visibility.
|
// Absent tile: only treat as air if the chunk is loaded.
|
||||||
None => break 'neighbor_check true,
|
// 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user