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
+5
View File
@@ -126,6 +126,11 @@ pub fn rabbit_dig_system(
let entity_pos = transform.translation.as_ivec3(); let entity_pos = transform.translation.as_ivec3();
let below_pos = IVec3::new(entity_pos.x, entity_pos.y, entity_pos.z - ITILE_SIZE); let below_pos = IVec3::new(entity_pos.x, entity_pos.y, entity_pos.z - ITILE_SIZE);
// Don't dig below world floor — would panic in remove_floor bounds check.
if below_pos.z < -(crate::world::chunks::Z_BELOW as i32 - 1) * ITILE_SIZE {
continue;
}
if tilemap.remove_floor(&below_pos).is_some() { if tilemap.remove_floor(&below_pos).is_some() {
tile_changed.write(TileChangedEvent { pos: below_pos }); tile_changed.write(TileChangedEvent { pos: below_pos });
+7 -5
View File
@@ -68,7 +68,7 @@ use crate::world::tiles::tile_changed::{PathfindingDirtyChunks, TileChangedEvent
use crate::world::tiles::TileMap; use crate::world::tiles::TileMap;
use crate::world::{ use crate::world::{
chunks::CHUNK_SIZE, 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 crate::{constants::*, entities::shared_components::Ambulatory};
use bevy::math::ivec3; use bevy::math::ivec3;
@@ -609,10 +609,12 @@ pub fn movement(
.for_each(|(mut ambulatory, mut transform)| { .for_each(|(mut ambulatory, mut transform)| {
let current_pos = transform.translation; let current_pos = transform.translation;
if !is_standable_tile(&tilemap, current_pos.as_ivec3()) { if !is_standable_tile(&tilemap, current_pos.as_ivec3()) {
// Don't fall below world minimum z — rabbits digging can leave no floor // Entities can spawn above the loaded world range (z > Z_ABOVE*TILE_SIZE).
// to stand on, but they should stop at the world floor rather than // Snap them to the top instead of falling through unloaded z-space one
// falling into oblivion and panicking pos_to_index overflow. // tile per tick.
if transform.translation.z > -(crate::world::chunks::Z_BELOW as f32) * TILE_SIZE { 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; transform.translation.z -= TILE_SIZE;
} }
ambulatory.current_path = None; ambulatory.current_path = None;