first pass at tree interaction
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
use crate::constants::ITILE_SIZE;
|
||||
use crate::entities::item::drop_table::dig_rng;
|
||||
use crate::entities::item::prefabs::misc::misc_prefabs::spawn_prefab;
|
||||
use crate::world::chunks::{Z_ABOVE, Z_BELOW};
|
||||
use crate::world::chunks::Z_BELOW;
|
||||
use crate::world::generation::forestry::{fell_tree, TreePart};
|
||||
use crate::world::tiles::tile_changed::TileChangedEvent;
|
||||
use crate::world::tiles::visibility::TileOcclusionEvent;
|
||||
use crate::world::tiles::TileMap;
|
||||
@@ -27,6 +28,7 @@ pub fn dig_system(
|
||||
asset_server: Res<AssetServer>,
|
||||
time: Res<Time>,
|
||||
mut query: Query<(&Transform, &mut Digger)>,
|
||||
tree_parts: Query<(Entity, &TreePart)>,
|
||||
mut tilemap: ResMut<TileMap>,
|
||||
mut tile_changed: MessageWriter<TileChangedEvent>,
|
||||
mut occlusion: MessageWriter<TileOcclusionEvent>,
|
||||
@@ -90,6 +92,27 @@ pub fn dig_system(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If there's a blocking fixture directly above the dug tile, it's a tree trunk —
|
||||
// fell the whole tree. Temporary wiring until a designation + task system
|
||||
// triggers fell_tree explicitly.
|
||||
let above_pos = IVec3::new(below_pos.x, below_pos.y, below_pos.z + ITILE_SIZE);
|
||||
let has_trunk_above = tilemap
|
||||
.fixture_tiles
|
||||
.get(&above_pos)
|
||||
.map(|f| !f.can_stand_in())
|
||||
.unwrap_or(false);
|
||||
|
||||
if has_trunk_above {
|
||||
fell_tree(
|
||||
above_pos,
|
||||
&tree_parts,
|
||||
&mut commands,
|
||||
&mut tilemap,
|
||||
&mut tile_changed,
|
||||
&mut occlusion,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user