This commit is contained in:
2026-03-22 12:56:52 +00:00
parent 360ffc7526
commit 2eaf0196a5
7 changed files with 420 additions and 23 deletions
+17 -1
View File
@@ -292,7 +292,7 @@ pub fn fell_tree(
tilemap: &mut TileMap,
tile_changed: &mut MessageWriter<TileChangedEvent>,
occlusion: &mut MessageWriter<TileOcclusionEvent>,
) {
) -> SmallVec<[IVec3; 8]> {
let target_chunk = world_to_chunk(trunk_pos);
let trunk_x = trunk_pos.x;
let trunk_y = trunk_pos.y;
@@ -315,7 +315,22 @@ pub fn fell_tree(
// calculate_visibility traces up arbitrarily deep, so refresh the full column.
// z_total is constant per call — hoist above the loop.
let z_total = crate::world::chunks::Z_BELOW as i32 + crate::world::chunks::Z_ABOVE as i32 + 1;
// Collect trunk positions before despawning — we need is_trunk from TreePart
// while the entity still exists. This is why we DON'T immediately despawn
// in the to_remove mapping step.
let mut trunk_positions: SmallVec<[IVec3; 8]> = SmallVec::new();
for (entity, tile_pos) in to_remove.iter() {
// Check if this was a trunk (is_trunk stored on TreePart).
// We need to look up is_trunk before the entity is despawned.
// to_remove was collected from tree_parts query, so find it again:
if let Ok((_, part)) = tree_parts.get(*entity) {
if part.is_trunk {
trunk_positions.push(*tile_pos);
}
}
tilemap.remove_fixture(tile_pos);
tile_changed.write(TileChangedEvent { pos: *tile_pos });
commands.entity(*entity).despawn();
@@ -333,4 +348,5 @@ pub fn fell_tree(
for pos in dirty_columns {
occlusion.write(TileOcclusionEvent { tile_position: pos });
}
trunk_positions
}