azalea/client_impl/
mining.rs

1use azalea_client::mining::{LeftClickMine, Mining, StartMiningBlockEvent};
2use azalea_core::position::BlockPos;
3
4use crate::Client;
5
6impl Client {
7    pub fn start_mining(&self, position: BlockPos) {
8        let mut ecs = self.ecs.write();
9
10        ecs.write_message(StartMiningBlockEvent {
11            entity: self.entity,
12            position,
13            force: true,
14        });
15    }
16
17    /// Returns true if the client is currently trying to mine a block.
18    pub fn is_mining(&self) -> bool {
19        self.get_component::<Mining>().is_some()
20    }
21
22    /// When enabled, the bot will mine any block that it is looking at if it is
23    /// reachable.
24    pub fn left_click_mine(&self, enabled: bool) {
25        let mut ecs = self.ecs.write();
26        let mut entity_mut = ecs.entity_mut(self.entity);
27
28        if enabled {
29            entity_mut.insert(LeftClickMine);
30        } else {
31            entity_mut.remove::<LeftClickMine>();
32        }
33    }
34}