demo 1
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user