From 631ed63dbdc7167df4de02a55b5c2ef1cea909e9 Mon Sep 17 00:00:00 2001 From: mat <27899617+mat-1@users.noreply.github.com> Date: Sun, 27 Nov 2022 16:25:07 -0600 Subject: Swarm (#36) * make azalea-pathfinder dir * start writing d* lite impl * more work on d* lite * work more on implementing d* lite * full d* lite impl * updated edges * add next() function * add NoPathError * why does dstar lite not work * fix d* lite implementation * make the test actually check the coords * replace while loop with if statement * fix clippy complaints * make W only have to be PartialOrd * fix PartialOrd issues * implement mtd* lite * add a test to mtd* lite * remove normal d* lite * make heuristic only take in one arg * add `success` function * Update README.md * evil black magic to make .entity not need dimension * start adding moves * slightly improve the vec3/position situation new macro that implements all the useful functions * moves stuff * make it compile * update deps in az-pathfinder * make it compile again * more pathfinding stuff * add Bot::look_at * replace EntityMut and EntityRef with just Entity * block pos pathfinding stuff * rename movedirection to walkdirection * execute path every tick * advance path * change az-pf version * make azalea_client keep plugin state * fix Plugins::get * why does it think there is air * start debugging incorrect air * update some From methods to use rem_euclid * start adding swarm * fix deadlock i still don't understand why it was happening but the solution was to keep the Client::player lock for shorter so it didn't overlap with the Client::dimension lock * make lookat actually work probably * fix going too fast * Update main.rs * make a thing immutable * direction_looking_at * fix rotations * import swarm in an example * fix stuff from merge * remove azalea_pathfinder import * delete azalea-pathfinder crate already in azalea::pathfinder module * swarms * start working on shared dimensions * Shared worlds work * start adding Swarm::add_account * add_account works * change "client" to "bot" in some places * Fix issues from merge * Update world.rs * add SwarmEvent::Disconnect(Account) * almost add SwarmEvent::Chat and new plugin system it panics rn * make plugins have to provide the State associated type * improve comments * make fn build slightly cleaner * fix SwarmEvent::Chat * change a println in bot/main.rs * Client::shutdown -> disconnect * polish fix clippy warnings + improve some docs a bit * fix shared worlds* *there's a bug that entities and bots will have their positions exaggerated because the relative movement packet is applied for every entity once per bot * i am being trolled by rust for some reason some stuff is really slow for literally no reason and it makes no sense i am going insane * make world an RwLock again * remove debug messages * fix skipping event ticks unfortunately now sending events is `.send().await?` instead of just `.send()` * fix deadlock + warnings * turns out my floor_mod impl was wrong and i32::rem_euclid has the correct behavior LOL * still errors with lots of bots * make swarm iter & fix new chunks not loading * improve docs * start fixing tests * fix all the tests except the examples i don't know how to exclude them from the tests * improve docs some more --- azalea-client/src/movement.rs | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) mode change 100755 => 100644 azalea-client/src/movement.rs (limited to 'azalea-client/src/movement.rs') diff --git a/azalea-client/src/movement.rs b/azalea-client/src/movement.rs old mode 100755 new mode 100644 index 87ac8d85..5fca924b --- a/azalea-client/src/movement.rs +++ b/azalea-client/src/movement.rs @@ -1,3 +1,5 @@ +use std::backtrace::Backtrace; + use crate::Client; use azalea_core::Vec3; use azalea_physics::collision::{MovableEntity, MoverType}; @@ -15,7 +17,7 @@ use thiserror::Error; #[derive(Error, Debug)] pub enum MovePlayerError { #[error("Player is not in world")] - PlayerNotInWorld, + PlayerNotInWorld(Backtrace), #[error("{0}")] Io(#[from] std::io::Error), } @@ -23,7 +25,9 @@ pub enum MovePlayerError { impl From for MovePlayerError { fn from(err: MoveEntityError) -> Self { match err { - MoveEntityError::EntityDoesNotExist => MovePlayerError::PlayerNotInWorld, + MoveEntityError::EntityDoesNotExist(backtrace) => { + MovePlayerError::PlayerNotInWorld(backtrace) + } } } } @@ -152,7 +156,7 @@ impl Client { } // Set our current position to the provided Vec3, potentially clipping through blocks. - pub async fn set_pos(&mut self, new_pos: Vec3) -> Result<(), MovePlayerError> { + pub async fn set_position(&mut self, new_pos: Vec3) -> Result<(), MovePlayerError> { let player_entity_id = *self.entity_id.read(); let mut world_lock = self.world.write(); @@ -167,7 +171,7 @@ impl Client { let mut entity = world_lock .entity_mut(player_entity_id) - .ok_or(MovePlayerError::PlayerNotInWorld)?; + .ok_or(MovePlayerError::PlayerNotInWorld(Backtrace::capture()))?; log::trace!( "move entity bounding box: {} {:?}", entity.id, @@ -258,6 +262,19 @@ impl Client { /// Start walking in the given direction. To sprint, use /// [`Client::sprint`]. To stop walking, call walk with /// `WalkDirection::None`. + /// + /// # Examples + /// + /// Walk for 1 second + /// ```rust,no_run + /// # use azalea_client::{Client, WalkDirection}; + /// # use std::time::Duration; + /// # async fn example(mut bot: Client) { + /// bot.walk(WalkDirection::Forward); + /// tokio::time::sleep(Duration::from_secs(1)).await; + /// bot.walk(WalkDirection::None); + /// # } + /// ``` pub fn walk(&mut self, direction: WalkDirection) { { let mut physics_state = self.physics_state.lock(); @@ -269,6 +286,19 @@ impl Client { /// Start sprinting in the given direction. To stop moving, call /// [`Client::walk(WalkDirection::None)`] + /// + /// # Examples + /// + /// Sprint for 1 second + /// ```rust,no_run + /// # use azalea_client::{Client, WalkDirection, SprintDirection}; + /// # use std::time::Duration; + /// # async fn example(mut bot: Client) { + /// bot.sprint(SprintDirection::Forward); + /// tokio::time::sleep(Duration::from_secs(1)).await; + /// bot.walk(WalkDirection::None); + /// # } + /// ``` pub fn sprint(&mut self, direction: SprintDirection) { let mut physics_state = self.physics_state.lock(); physics_state.move_direction = WalkDirection::from(direction); @@ -321,6 +351,7 @@ impl Client { /// Sets your rotation. `y_rot` is yaw (looking to the side), `x_rot` is /// pitch (looking up and down). You can get these numbers from the vanilla /// f3 screen. + /// `y_rot` goes from -180 to 180, and `x_rot` goes from -90 to 90. pub fn set_rotation(&mut self, y_rot: f32, x_rot: f32) { let mut player_entity = self.entity_mut(); player_entity.set_rotation(y_rot, x_rot); -- cgit v1.2.3