diff options
| author | mat <git@matdoes.dev> | 2025-02-22 23:01:54 +0000 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2025-02-22 23:01:54 +0000 |
| commit | 34f53baf85fb5c7163ec5d71a8ab9d45d3f271b6 (patch) | |
| tree | 7920fec1203e8e96463a142f5f6da6164e76e684 /azalea/src | |
| parent | bdd2fc91e11e2896d8e1c7046df247e1075bd40d (diff) | |
| download | azalea-drasl-34f53baf85fb5c7163ec5d71a8ab9d45d3f271b6.tar.xz | |
update to rust edition 2024
Diffstat (limited to 'azalea/src')
| -rw-r--r-- | azalea/src/auto_respawn.rs | 2 | ||||
| -rw-r--r-- | azalea/src/auto_tool.rs | 6 | ||||
| -rw-r--r-- | azalea/src/bot.rs | 9 | ||||
| -rw-r--r-- | azalea/src/container.rs | 4 | ||||
| -rw-r--r-- | azalea/src/lib.rs | 4 | ||||
| -rw-r--r-- | azalea/src/pathfinder/debug.rs | 22 | ||||
| -rw-r--r-- | azalea/src/pathfinder/mining.rs | 2 | ||||
| -rw-r--r-- | azalea/src/pathfinder/mod.rs | 91 | ||||
| -rw-r--r-- | azalea/src/pathfinder/moves/basic.rs | 2 | ||||
| -rw-r--r-- | azalea/src/pathfinder/moves/mod.rs | 8 | ||||
| -rw-r--r-- | azalea/src/pathfinder/simulation.rs | 6 | ||||
| -rw-r--r-- | azalea/src/prelude.rs | 4 | ||||
| -rw-r--r-- | azalea/src/swarm/mod.rs | 27 |
13 files changed, 98 insertions, 89 deletions
diff --git a/azalea/src/auto_respawn.rs b/azalea/src/auto_respawn.rs index 43ec4821..191e6df7 100644 --- a/azalea/src/auto_respawn.rs +++ b/azalea/src/auto_respawn.rs @@ -1,6 +1,6 @@ use azalea_client::{ packet_handling::{death_event_on_0_health, game::DeathEvent}, - respawn::{perform_respawn, PerformRespawnEvent}, + respawn::{PerformRespawnEvent, perform_respawn}, }; use bevy_app::Update; use bevy_ecs::prelude::*; diff --git a/azalea/src/auto_tool.rs b/azalea/src/auto_tool.rs index 9aea23d7..81fe3131 100644 --- a/azalea/src/auto_tool.rs +++ b/azalea/src/auto_tool.rs @@ -1,7 +1,7 @@ -use azalea_block::{fluid_state::FluidKind, Block, BlockState}; -use azalea_client::{inventory::Inventory, Client}; +use azalea_block::{Block, BlockState, fluid_state::FluidKind}; +use azalea_client::{Client, inventory::Inventory}; use azalea_entity::{FluidOnEyes, Physics}; -use azalea_inventory::{components, ItemStack, Menu}; +use azalea_inventory::{ItemStack, Menu, components}; #[derive(Debug)] pub struct BestToolResult { diff --git a/azalea/src/bot.rs b/azalea/src/bot.rs index 539a5281..aae8af05 100644 --- a/azalea/src/bot.rs +++ b/azalea/src/bot.rs @@ -1,13 +1,13 @@ use std::f64::consts::PI; +use azalea_client::TickBroadcast; use azalea_client::interact::SwingArmEvent; use azalea_client::mining::Mining; -use azalea_client::TickBroadcast; use azalea_core::position::{BlockPos, Vec3}; use azalea_core::tick::GameTick; use azalea_entity::{ - clamp_look_direction, metadata::Player, EyeHeight, Jumping, LocalEntity, LookDirection, - Position, + EyeHeight, Jumping, LocalEntity, LookDirection, Position, clamp_look_direction, + metadata::Player, }; use azalea_physics::PhysicsSet; use bevy_app::Update; @@ -185,8 +185,7 @@ fn look_at_listener( direction_looking_at(&position.up(eye_height.into()), &event.position); trace!( "look at {:?} (currently at {:?})", - event.position, - **position + event.position, **position ); *look_direction = new_look_direction; } diff --git a/azalea/src/container.rs b/azalea/src/container.rs index 38877616..e1a018b0 100644 --- a/azalea/src/container.rs +++ b/azalea/src/container.rs @@ -2,12 +2,12 @@ use std::fmt::Debug; use std::fmt::Formatter; use azalea_client::{ + Client, inventory::{CloseContainerEvent, ContainerClickEvent, Inventory}, packet_handling::game::PacketEvent, - Client, }; use azalea_core::position::BlockPos; -use azalea_inventory::{operations::ClickOperation, ItemStack, Menu}; +use azalea_inventory::{ItemStack, Menu, operations::ClickOperation}; use azalea_protocol::packets::game::ClientboundGamePacket; use bevy_app::{App, Plugin, Update}; use bevy_ecs::{component::Component, prelude::EventReader, system::Commands}; diff --git a/azalea/src/lib.rs b/azalea/src/lib.rs index e50fde0a..0a8300b1 100644 --- a/azalea/src/lib.rs +++ b/azalea/src/lib.rs @@ -37,9 +37,9 @@ pub use bevy_app as app; pub use bevy_ecs as ecs; pub use bot::*; use ecs::component::Component; -use futures::{future::BoxFuture, Future}; +use futures::{Future, future::BoxFuture}; use protocol::connect::Proxy; -use protocol::{resolver::ResolverError, ServerAddress}; +use protocol::{ServerAddress, resolver::ResolverError}; use swarm::SwarmBuilder; use thiserror::Error; diff --git a/azalea/src/pathfinder/debug.rs b/azalea/src/pathfinder/debug.rs index ca08cbc5..98778cad 100644 --- a/azalea/src/pathfinder/debug.rs +++ b/azalea/src/pathfinder/debug.rs @@ -1,4 +1,4 @@ -use azalea_client::{chat::SendChatEvent, InstanceHolder}; +use azalea_client::{InstanceHolder, chat::SendChatEvent}; use azalea_core::position::Vec3; use bevy_ecs::prelude::*; @@ -89,16 +89,16 @@ pub fn debug_render_path_with_particles( z: start_vec3.z + (end_vec3.z - start_vec3.z) * percent, }; let particle_command = format!( - "/particle dust{{color:[{r},{g},{b}],scale:{size}}} {start_x} {start_y} {start_z} {delta_x} {delta_y} {delta_z} 0 {count}", - size = 1, - start_x = pos.x, - start_y = pos.y, - start_z = pos.z, - delta_x = 0, - delta_y = 0, - delta_z = 0, - count = 1 - ); + "/particle dust{{color:[{r},{g},{b}],scale:{size}}} {start_x} {start_y} {start_z} {delta_x} {delta_y} {delta_z} 0 {count}", + size = 1, + start_x = pos.x, + start_y = pos.y, + start_z = pos.z, + delta_x = 0, + delta_y = 0, + delta_z = 0, + count = 1 + ); chat_events.send(SendChatEvent { entity, content: particle_command, diff --git a/azalea/src/pathfinder/mining.rs b/azalea/src/pathfinder/mining.rs index 8c1b2e1d..40cdf8a2 100644 --- a/azalea/src/pathfinder/mining.rs +++ b/azalea/src/pathfinder/mining.rs @@ -1,7 +1,7 @@ use std::{cell::UnsafeCell, ops::RangeInclusive}; use azalea_block::{ - block_state::BlockStateIntegerRepr, properties::Waterlogged, BlockState, BlockStates, + BlockState, BlockStates, block_state::BlockStateIntegerRepr, properties::Waterlogged, }; use azalea_inventory::Menu; use nohash_hasher::IntMap; diff --git a/azalea/src/pathfinder/mod.rs b/azalea/src/pathfinder/mod.rs index ae23788b..0db627ac 100644 --- a/azalea/src/pathfinder/mod.rs +++ b/azalea/src/pathfinder/mod.rs @@ -14,8 +14,8 @@ pub mod world; use std::collections::VecDeque; use std::ops::RangeInclusive; -use std::sync::atomic::{self, AtomicUsize}; use std::sync::Arc; +use std::sync::atomic::{self, AtomicUsize}; use std::time::{Duration, Instant}; use std::{cmp, thread}; @@ -26,8 +26,8 @@ use azalea_client::movement::MoveEventsSet; use azalea_client::{InstanceHolder, StartSprintEvent, StartWalkEvent}; use azalea_core::position::BlockPos; use azalea_core::tick::GameTick; -use azalea_entity::metadata::Player; use azalea_entity::LocalEntity; +use azalea_entity::metadata::Player; use azalea_entity::{Physics, Position}; use azalea_physics::PhysicsSet; use azalea_world::{InstanceContainer, InstanceName}; @@ -42,11 +42,12 @@ use parking_lot::RwLock; use rel_block_pos::RelBlockPos; use tracing::{debug, error, info, trace, warn}; -use self::debug::debug_render_path_with_particles; pub use self::debug::PathfinderDebugParticles; +use self::debug::debug_render_path_with_particles; use self::goals::Goal; use self::mining::MiningCache; use self::moves::{ExecuteCtx, IsReachedCtx, SuccessorsFn}; +use crate::WalkDirection; use crate::app::{App, Plugin}; use crate::bot::{JumpEvent, LookAtEvent}; use crate::ecs::{ @@ -57,7 +58,6 @@ use crate::ecs::{ system::{Commands, Query, Res}, }; use crate::pathfinder::{astar::a_star, moves::PathfinderCtx, world::CachedWorld}; -use crate::WalkDirection; #[derive(Clone, Default)] pub struct PathfinderPlugin; @@ -874,54 +874,62 @@ pub fn recalculate_near_end_of_path( && !pathfinder.is_calculating && executing_path.is_path_partial { - if let Some(goal) = pathfinder.goal.as_ref().cloned() { - debug!("Recalculating path because it's empty or ends soon"); - debug!( - "recalculate_near_end_of_path executing_path.is_path_partial: {}", - executing_path.is_path_partial - ); - goto_events.send(GotoEvent { - entity, - goal, - successors_fn, - allow_mining: pathfinder.allow_mining, - min_timeout: if executing_path.path.len() == 50 { - // we have quite some time until the node is reached, soooo we might as well - // burn some cpu cycles to get a good path - PathfinderTimeout::Time(Duration::from_secs(5)) - } else { - PathfinderTimeout::Time(Duration::from_secs(1)) - }, - max_timeout: pathfinder.max_timeout.expect("max_timeout should be set"), - }); - pathfinder.is_calculating = true; + match pathfinder.goal.as_ref().cloned() { + Some(goal) => { + debug!("Recalculating path because it's empty or ends soon"); + debug!( + "recalculate_near_end_of_path executing_path.is_path_partial: {}", + executing_path.is_path_partial + ); + goto_events.send(GotoEvent { + entity, + goal, + successors_fn, + allow_mining: pathfinder.allow_mining, + min_timeout: if executing_path.path.len() == 50 { + // we have quite some time until the node is reached, soooo we might as + // well burn some cpu cycles to get a good + // path + PathfinderTimeout::Time(Duration::from_secs(5)) + } else { + PathfinderTimeout::Time(Duration::from_secs(1)) + }, + max_timeout: pathfinder.max_timeout.expect("max_timeout should be set"), + }); + pathfinder.is_calculating = true; - if executing_path.path.is_empty() { - if let Some(new_path) = executing_path.queued_path.take() { - executing_path.path = new_path; - if executing_path.path.is_empty() { - info!("the path we just swapped to was empty, so reached end of path"); + if executing_path.path.is_empty() { + if let Some(new_path) = executing_path.queued_path.take() { + executing_path.path = new_path; + if executing_path.path.is_empty() { + info!( + "the path we just swapped to was empty, so reached end of path" + ); + walk_events.send(StartWalkEvent { + entity, + direction: WalkDirection::None, + }); + commands.entity(entity).remove::<ExecutingPath>(); + break; + } + } else { walk_events.send(StartWalkEvent { entity, direction: WalkDirection::None, }); commands.entity(entity).remove::<ExecutingPath>(); - break; } - } else { + } + } + _ => { + if executing_path.path.is_empty() { + // idk when this can happen but stop moving just in case walk_events.send(StartWalkEvent { entity, direction: WalkDirection::None, }); - commands.entity(entity).remove::<ExecutingPath>(); } } - } else if executing_path.path.is_empty() { - // idk when this can happen but stop moving just in case - walk_events.send(StartWalkEvent { - entity, - direction: WalkDirection::None, - }); } } } @@ -968,8 +976,7 @@ pub fn tick_execute_path( }; trace!( "executing move, position: {}, last_reached_node: {}", - **position, - executing_path.last_reached_node + **position, executing_path.last_reached_node ); (movement.data.execute)(ctx); } @@ -1117,11 +1124,11 @@ mod tests { use azalea_world::{Chunk, ChunkStorage, PartialChunkStorage}; use super::{ + GotoEvent, astar::PathfinderTimeout, goals::BlockPosGoal, moves, simulation::{SimulatedPlayerBundle, Simulation}, - GotoEvent, }; fn setup_blockposgoal_simulation( diff --git a/azalea/src/pathfinder/moves/basic.rs b/azalea/src/pathfinder/moves/basic.rs index 8a679376..4955ed08 100644 --- a/azalea/src/pathfinder/moves/basic.rs +++ b/azalea/src/pathfinder/moves/basic.rs @@ -6,7 +6,7 @@ use azalea_core::{ position::{BlockPos, Vec3}, }; -use super::{default_is_reached, Edge, ExecuteCtx, IsReachedCtx, MoveData, PathfinderCtx}; +use super::{Edge, ExecuteCtx, IsReachedCtx, MoveData, PathfinderCtx, default_is_reached}; use crate::pathfinder::{astar, costs::*, rel_block_pos::RelBlockPos}; pub fn basic_move(ctx: &mut PathfinderCtx, node: RelBlockPos) { diff --git a/azalea/src/pathfinder/moves/mod.rs b/azalea/src/pathfinder/moves/mod.rs index 68c65d5d..83e6369f 100644 --- a/azalea/src/pathfinder/moves/mod.rs +++ b/azalea/src/pathfinder/moves/mod.rs @@ -4,8 +4,8 @@ pub mod parkour; use std::{fmt::Debug, sync::Arc}; use azalea_client::{ - inventory::SetSelectedHotbarSlotEvent, mining::StartMiningBlockEvent, SprintDirection, - StartSprintEvent, StartWalkEvent, WalkDirection, + SprintDirection, StartSprintEvent, StartWalkEvent, WalkDirection, + inventory::SetSelectedHotbarSlotEvent, mining::StartMiningBlockEvent, }; use azalea_core::position::{BlockPos, Vec3}; use azalea_inventory::Menu; @@ -17,9 +17,9 @@ use super::{ astar, mining::MiningCache, rel_block_pos::RelBlockPos, - world::{is_block_state_passable, CachedWorld}, + world::{CachedWorld, is_block_state_passable}, }; -use crate::{auto_tool::best_tool_in_hotbar_for_block, JumpEvent, LookAtEvent}; +use crate::{JumpEvent, LookAtEvent, auto_tool::best_tool_in_hotbar_for_block}; type Edge = astar::Edge<RelBlockPos, MoveData>; diff --git a/azalea/src/pathfinder/simulation.rs b/azalea/src/pathfinder/simulation.rs index 0067c19f..ab0e540a 100644 --- a/azalea/src/pathfinder/simulation.rs +++ b/azalea/src/pathfinder/simulation.rs @@ -2,10 +2,10 @@ use std::sync::Arc; -use azalea_client::{inventory::Inventory, packet_handling::game::SendPacketEvent, PhysicsState}; +use azalea_client::{PhysicsState, inventory::Inventory, packet_handling::game::SendPacketEvent}; use azalea_core::{position::Vec3, resource_location::ResourceLocation, tick::GameTick}; use azalea_entity::{ - attributes::AttributeInstance, Attributes, EntityDimensions, LookDirection, Physics, Position, + Attributes, EntityDimensions, LookDirection, Physics, Position, attributes::AttributeInstance, }; use azalea_registry::EntityKind; use azalea_world::{ChunkStorage, Instance, InstanceContainer, MinecraftEntityId, PartialInstance}; @@ -87,7 +87,7 @@ fn create_simulation_instance(chunks: ChunkStorage) -> (App, Arc<RwLock<Instance fn create_simulation_player_complete_bundle( instance: Arc<RwLock<Instance>>, player: &SimulatedPlayerBundle, -) -> impl Bundle { +) -> impl Bundle + use<> { let instance_name = simulation_instance_name(); ( diff --git a/azalea/src/prelude.rs b/azalea/src/prelude.rs index d1442b10..4f68f1ea 100644 --- a/azalea/src/prelude.rs +++ b/azalea/src/prelude.rs @@ -8,6 +8,6 @@ pub use azalea_core::tick::GameTick; pub use crate::ecs as bevy_ecs; pub use crate::ecs::{component::Component, system::Resource}; pub use crate::{ - bot::BotClientExt, container::ContainerClientExt, pathfinder::PathfinderClientExt, - ClientBuilder, + ClientBuilder, bot::BotClientExt, container::ContainerClientExt, + pathfinder::PathfinderClientExt, }; diff --git a/azalea/src/swarm/mod.rs b/azalea/src/swarm/mod.rs index 696f751b..cc0d7eb1 100644 --- a/azalea/src/swarm/mod.rs +++ b/azalea/src/swarm/mod.rs @@ -9,14 +9,14 @@ pub mod prelude; use std::{collections::HashMap, future::Future, net::SocketAddr, sync::Arc, time::Duration}; use azalea_client::{ - chat::ChatPacket, start_ecs_runner, Account, Client, DefaultPlugins, Event, JoinError, - StartClientOpts, + Account, Client, DefaultPlugins, Event, JoinError, StartClientOpts, chat::ChatPacket, + start_ecs_runner, }; -use azalea_protocol::{resolver, ServerAddress}; +use azalea_protocol::{ServerAddress, resolver}; use azalea_world::InstanceContainer; use bevy_app::{App, PluginGroup, PluginGroupBuilder, Plugins}; use bevy_ecs::{component::Component, entity::Entity, system::Resource, world::World}; -use futures::future::{join_all, BoxFuture}; +use futures::future::{BoxFuture, join_all}; use parking_lot::{Mutex, RwLock}; use tokio::sync::mpsc; use tracing::{debug, error}; @@ -692,14 +692,17 @@ impl Swarm { .min(Duration::from_secs(15)); let username = account.username.clone(); - if let JoinError::Disconnect { reason } = &e { - error!( - "Error joining as {username}, server says: \"{reason}\". Waiting {delay:?} and trying again." - ); - } else { - error!( - "Error joining as {username}: {e}. Waiting {delay:?} and trying again." - ); + match &e { + JoinError::Disconnect { reason } => { + error!( + "Error joining as {username}, server says: \"{reason}\". Waiting {delay:?} and trying again." + ); + } + _ => { + error!( + "Error joining as {username}: {e}. Waiting {delay:?} and trying again." + ); + } } tokio::time::sleep(delay).await; |
