diff --git a/src/entities/livestock/rabbit.rs b/src/entities/livestock/rabbit.rs index 29bf26e..f6d4cbc 100644 --- a/src/entities/livestock/rabbit.rs +++ b/src/entities/livestock/rabbit.rs @@ -1,11 +1,11 @@ -use crate::config::GameConfig; +use crate::config::{GameConfig, TileRegistry}; use crate::constants::ITILE_SIZE; use crate::constants::TILE_SIZE; use crate::constants::*; use crate::entities::shared_components::Ambulatory; use crate::game::SpawnDelay; use crate::world::tiles::visibility::TileOcclusionEvent; -use crate::world::tiles::{TileChangedEvent, TileMap}; +use crate::world::tiles::{FloorTileData, TileChangedEvent, TileMap}; use crate::world::VisibleGameEntity; use bevy::prelude::*; use bevy_rand::prelude::*; @@ -169,6 +169,24 @@ pub fn rabbit_dig_system( ); let removed = tilemap.remove_floor(&below_pos); + + // Replace the dug tile with air. The slot must become passable — if the entry + // is simply absent, ChunkData bits remain 0 (impassable), and is_standable + // returns false. Air has can_stand_in=true so entities can fall through it. + if removed.is_some() { + let air = TileRegistry::global().floor("air"); + tilemap.insert_floor( + below_pos, + FloorTileData::new( + air.id, + air.can_stand_in, + air.can_stand_on, + air.transparent, + air.astar_weight, + [0; 8], + ), + ); + } println!( "[DIG] remove_floor({:?}) => {}", below_pos, diff --git a/src/world/tiles/tilemap.rs b/src/world/tiles/tilemap.rs index 092ceff..7a456c5 100644 --- a/src/world/tiles/tilemap.rs +++ b/src/world/tiles/tilemap.rs @@ -190,6 +190,27 @@ impl TileMap { #[inline] pub fn insert_floor(&mut self, pos: IVec3, tile: FloorTileData) { + let chunk_pos = world_to_chunk(pos); + if let Some(chunk) = self.chunks.get_mut(&chunk_pos) { + let (lx, ly, z) = ChunkData::world_to_local(pos); + if z >= -(Z_BELOW as i32) + && z <= Z_ABOVE as i32 + && lx >= 0 + && lx < CHUNK_SIZE + && ly >= 0 + && ly < CHUNK_SIZE + { + chunk.set_floor_tile( + lx, + ly, + z, + tile.id, + tile.can_stand_in(), + tile.can_stand_on(), + tile.astar_weight, + ); + } + } self.floor_tiles.insert(pos, tile); }