refactor: extract generic digging system, drop tables, remove debug code

- New src/entities/item/drop_table.rs: DropEntry (chance, min/max count,
  pseudo-RNG roll) + DropTable wrapper. grass=5% coin 1-2, rock=10% coin 1,
  dirt/air=none.
- New src/entities/shared_systems/digging.rs: Digger component + dig_system.
  Any entity with Digger digs the tile below on its interval. Replaces
  rabbit_dig_system/rabbit_fall_debug_system/RabbitDigTimer/RabbitFallDebug.
- New TileMap::dig_floor: remove_floor + insert air. Used by dig_system.
- FloorTileData: added drop_table field. Lost Copy derive (Vec field).
  Updated all 6 terrain.rs call sites with per-tile drop tables.
- Pig: removed PigDropTimer + pig_drop_system. Drops were debug placeholder.
  TODO added for future loot-on-death/butcher system.
- Rabbit: removed all debug components/systems. Now uses Digger::new(5.0).
- main.rs: removed rabbit_dig_system/rabbit_fall_debug_system/pig_drop_system,
  added shared_systems::digging::dig_system.
This commit is contained in:
2026-03-21 15:40:34 +00:00
parent 1a170ea9a9
commit ce3746366c
9 changed files with 238 additions and 301 deletions
+26 -1
View File
@@ -33,16 +33,18 @@ use rustc_hash::FxHashMap;
use super::chunk_data::ChunkData;
use crate::constants::ITILE_SIZE;
use crate::entities::item::drop_table::DropTable;
use crate::world::chunks::{world_to_chunk, CHUNK_SIZE, Z_ABOVE, Z_BELOW};
/// Packed floor tile data for efficient storage. ~35 bytes vs 76 bytes tuple.
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Debug)]
pub struct FloorTileData {
pub id: u8,
/// bit0=can_stand_in, bit1=can_stand_on, bit2=visibly_transparent
pub flags: u8,
pub astar_weight: u8,
pub visible_range: [u32; 8],
pub drop_table: DropTable,
}
impl Default for FloorTileData {
@@ -52,6 +54,7 @@ impl Default for FloorTileData {
flags: 0b001,
astar_weight: 0,
visible_range: [0; 8],
drop_table: DropTable::default(),
}
}
}
@@ -64,6 +67,7 @@ impl FloorTileData {
visibly_transparent: bool,
astar_weight: u8,
visible_range: [u32; 8],
drop_table: DropTable,
) -> Self {
let mut flags = 0u8;
if can_stand_in {
@@ -80,6 +84,7 @@ impl FloorTileData {
flags,
astar_weight,
visible_range,
drop_table,
}
}
@@ -214,6 +219,26 @@ impl TileMap {
self.floor_tiles.insert(pos, tile);
}
pub fn dig_floor(&mut self, pos: &IVec3) -> Option<FloorTileData> {
let removed = self.remove_floor(pos);
if removed.is_some() {
let air = crate::config::TileRegistry::global().floor("air");
self.insert_floor(
*pos,
FloorTileData::new(
air.id,
air.can_stand_in,
air.can_stand_on,
air.transparent,
air.astar_weight,
[0; 8],
DropTable::default(),
),
);
}
removed
}
#[inline]
pub fn insert_fixture(&mut self, pos: IVec3, tile: FixtureTileData) {
let chunk_pos = world_to_chunk(pos);