aboutsummaryrefslogtreecommitdiff
path: root/azalea/src/mining.rs
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2023-07-14 22:20:40 -0500
committerGitHub <noreply@github.com>2023-07-14 22:20:40 -0500
commit7405427199e5a994d4a6a706f84434a69cb7a7d9 (patch)
treeca537e5d761bc053187d952fced0915c850b92aa /azalea/src/mining.rs
parentd1afd02aa84e7b4450c1607277f078eb2a0f1bf3 (diff)
downloadazalea-drasl-7405427199e5a994d4a6a706f84434a69cb7a7d9.tar.xz
Mining (#95)
* more mining stuff * initialize azalea-tags crate * more mining stuff 2 * mining in ecs * well technically mining works but no codegen for how long it takes to mine each block yet * rename downloads to __cache__ it was bothering me since it's not *just* downloads * codegen block behavior * fix not sending packet to finish breaking block * mining animation 🎉 * clippy * cleanup, move Client::mine into a client extension * add azalea/src/mining.rs --------- Co-authored-by: mat <git@matdoes.dev>
Diffstat (limited to 'azalea/src/mining.rs')
-rw-r--r--azalea/src/mining.rs40
1 files changed, 40 insertions, 0 deletions
diff --git a/azalea/src/mining.rs b/azalea/src/mining.rs
new file mode 100644
index 00000000..8ba16436
--- /dev/null
+++ b/azalea/src/mining.rs
@@ -0,0 +1,40 @@
+use azalea_client::{
+ interact::SwingArmEvent,
+ mining::{Mining, StartMiningBlockEvent},
+ Client, TickBroadcast,
+};
+use azalea_core::BlockPos;
+
+pub trait MiningExt {
+ /// Start mining a block.
+ async fn mine(&mut self, position: BlockPos);
+}
+
+impl MiningExt for Client {
+ /// Start mining a block. This won't turn the bot's head towards the block,
+ /// so you'll have to do that yourself with [`look_at`].
+ ///
+ /// [`look_at`]: crate::prelude::BotClientExt::look_at
+ async fn mine(&mut self, position: BlockPos) {
+ self.ecs.lock().send_event(StartMiningBlockEvent {
+ entity: self.entity,
+ position,
+ });
+ // vanilla sends an extra swing arm packet when we start mining
+ self.ecs.lock().send_event(SwingArmEvent {
+ entity: self.entity,
+ });
+
+ let mut receiver = {
+ let ecs = self.ecs.lock();
+ let tick_broadcast = ecs.resource::<TickBroadcast>();
+ tick_broadcast.subscribe()
+ };
+ while receiver.recv().await.is_ok() {
+ let ecs = self.ecs.lock();
+ if ecs.get::<Mining>(self.entity).is_none() {
+ break;
+ }
+ }
+ }
+}