fix: snap-to-top for above-world spawn, guard rabbit dig at world floor

- Entities spawn at z=35*TILE=560 but Z_ABOVE max is 15*TILE=240. Snap to
  Z_ABOVE*TILE instead of falling one tile per tick through unloaded space.
- Skip rabbit dig when below_pos would be outside ChunkData z-bounds,
  preventing remove_floor assert panic.
This commit is contained in:
2026-03-21 12:16:58 +00:00
parent 4d702bc8f5
commit 0ebc48ff40
2 changed files with 12 additions and 5 deletions
+7 -5
View File
@@ -68,7 +68,7 @@ use crate::world::tiles::tile_changed::{PathfindingDirtyChunks, TileChangedEvent
use crate::world::tiles::TileMap;
use crate::world::{
chunks::CHUNK_SIZE,
chunks::{world_to_chunk, ChunkMap},
chunks::{world_to_chunk, ChunkMap, Z_ABOVE, Z_BELOW},
};
use crate::{constants::*, entities::shared_components::Ambulatory};
use bevy::math::ivec3;
@@ -609,10 +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()) {
// 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 {
// Entities can spawn above the loaded world range (z > Z_ABOVE*TILE_SIZE).
// Snap them to the top instead of falling through unloaded z-space one
// tile per tick.
if transform.translation.z > Z_ABOVE as f32 * TILE_SIZE {
transform.translation.z = Z_ABOVE as f32 * TILE_SIZE;
} else if transform.translation.z > -(Z_BELOW as f32) * TILE_SIZE {
transform.translation.z -= TILE_SIZE;
}
ambulatory.current_path = None;