diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2023-07-14 22:20:40 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-14 22:20:40 -0500 |
| commit | 7405427199e5a994d4a6a706f84434a69cb7a7d9 (patch) | |
| tree | ca537e5d761bc053187d952fced0915c850b92aa /azalea/src | |
| parent | d1afd02aa84e7b4450c1607277f078eb2a0f1bf3 (diff) | |
| download | azalea-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')
| -rw-r--r-- | azalea/src/bot.rs | 5 | ||||
| -rw-r--r-- | azalea/src/lib.rs | 4 | ||||
| -rw-r--r-- | azalea/src/mining.rs | 40 | ||||
| -rw-r--r-- | azalea/src/pathfinder/mod.rs | 12 | ||||
| -rw-r--r-- | azalea/src/prelude.rs | 4 | ||||
| -rw-r--r-- | azalea/src/swarm/events.rs | 2 |
6 files changed, 54 insertions, 13 deletions
diff --git a/azalea/src/bot.rs b/azalea/src/bot.rs index 47c825ca..7940e7b0 100644 --- a/azalea/src/bot.rs +++ b/azalea/src/bot.rs @@ -9,9 +9,10 @@ use crate::ecs::{ system::{Commands, Query}, }; use azalea_core::Vec3; +use azalea_entity::{ + clamp_look_direction, metadata::Player, EyeHeight, Jumping, Local, LookDirection, Position, +}; use azalea_physics::{force_jump_listener, PhysicsSet}; -use azalea_world::entity::{clamp_look_direction, EyeHeight, LookDirection}; -use azalea_world::entity::{metadata::Player, Jumping, Local, Position}; use bevy_app::{FixedUpdate, Update}; use bevy_ecs::prelude::Event; use bevy_ecs::schedule::IntoSystemConfigs; diff --git a/azalea/src/lib.rs b/azalea/src/lib.rs index 1c6966c5..297199a0 100644 --- a/azalea/src/lib.rs +++ b/azalea/src/lib.rs @@ -6,6 +6,7 @@ mod auto_respawn; mod bot; mod container; +pub mod mining; pub mod pathfinder; pub mod prelude; pub mod swarm; @@ -17,9 +18,10 @@ pub use azalea_brigadier as brigadier; pub use azalea_chat::FormattedText; pub use azalea_client::*; pub use azalea_core::{BlockPos, Vec3}; +pub use azalea_entity as entity; pub use azalea_protocol as protocol; pub use azalea_registry::{Block, EntityKind, Item}; -pub use azalea_world::{entity, Instance}; +pub use azalea_world::Instance; pub use bot::DefaultBotPlugins; use ecs::component::Component; use futures::Future; 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; + } + } + } +} diff --git a/azalea/src/pathfinder/mod.rs b/azalea/src/pathfinder/mod.rs index 9547d263..f4e4d599 100644 --- a/azalea/src/pathfinder/mod.rs +++ b/azalea/src/pathfinder/mod.rs @@ -16,13 +16,11 @@ use crate::ecs::{ use astar::Edge; use azalea_client::{StartSprintEvent, StartWalkEvent}; use azalea_core::{BlockPos, CardinalDirection}; +use azalea_entity::metadata::Player; +use azalea_entity::Local; +use azalea_entity::{Physics, Position}; use azalea_physics::PhysicsSet; -use azalea_world::entity::metadata::Player; -use azalea_world::entity::Local; -use azalea_world::{ - entity::{Physics, Position, WorldName}, - InstanceContainer, -}; +use azalea_world::{InstanceContainer, InstanceName}; use bevy_app::{FixedUpdate, Update}; use bevy_ecs::prelude::Event; use bevy_ecs::schedule::IntoSystemConfigs; @@ -106,7 +104,7 @@ pub struct ComputePath(Task<Option<PathFoundEvent>>); fn goto_listener( mut commands: Commands, mut events: EventReader<GotoEvent>, - mut query: Query<(&Position, &WorldName)>, + mut query: Query<(&Position, &InstanceName)>, instance_container: Res<InstanceContainer>, ) { let thread_pool = AsyncComputeTaskPool::get(); diff --git a/azalea/src/prelude.rs b/azalea/src/prelude.rs index 87cb0b53..ff3c11de 100644 --- a/azalea/src/prelude.rs +++ b/azalea/src/prelude.rs @@ -2,8 +2,8 @@ //! re-exported here. pub use crate::{ - bot::BotClientExt, container::ContainerClientExt, pathfinder::PathfinderClientExt, - ClientBuilder, + bot::BotClientExt, container::ContainerClientExt, mining::MiningExt, + pathfinder::PathfinderClientExt, ClientBuilder, }; pub use azalea_client::{Account, Client, Event}; // this is necessary to make the macros that reference bevy_ecs work diff --git a/azalea/src/swarm/events.rs b/azalea/src/swarm/events.rs index b4752abf..3b290608 100644 --- a/azalea/src/swarm/events.rs +++ b/azalea/src/swarm/events.rs @@ -1,5 +1,5 @@ use azalea_client::LocalPlayer; -use azalea_world::entity::MinecraftEntityId; +use azalea_world::MinecraftEntityId; use bevy_app::{App, Plugin, Update}; use bevy_ecs::prelude::*; use derive_more::{Deref, DerefMut}; |
