aboutsummaryrefslogtreecommitdiff
path: root/azalea
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2025-10-12 23:01:54 +0300
committermat <git@matdoes.dev>2025-10-12 23:01:54 +0300
commitee2575794e91b9457a74a95daf1dcc707058cd58 (patch)
treedf725850ef18ded5ce3f6552e17095d0f704ae84 /azalea
parent1a1402954b07cd77615d0afc026c73b008787f51 (diff)
downloadazalea-drasl-ee2575794e91b9457a74a95daf1dcc707058cd58.tar.xz
upgrade deps and clean up lots of doc comments
Diffstat (limited to 'azalea')
-rw-r--r--azalea/README.md8
-rw-r--r--azalea/examples/testbot/commands/debug.rs2
-rw-r--r--azalea/examples/testbot/main.rs3
-rw-r--r--azalea/src/bot.rs12
-rw-r--r--azalea/src/container.rs43
-rw-r--r--azalea/src/lib.rs13
-rw-r--r--azalea/src/nearest_entity.rs19
-rw-r--r--azalea/src/pathfinder/astar.rs7
-rw-r--r--azalea/src/pathfinder/goto_event.rs6
-rw-r--r--azalea/src/pathfinder/mod.rs14
-rw-r--r--azalea/src/pathfinder/moves/mod.rs5
-rw-r--r--azalea/src/pathfinder/world.rs21
-rw-r--r--azalea/src/swarm/mod.rs72
13 files changed, 139 insertions, 86 deletions
diff --git a/azalea/README.md b/azalea/README.md
index 5d0b6d5f..7860741a 100644
--- a/azalea/README.md
+++ b/azalea/README.md
@@ -57,9 +57,11 @@ async fn main() {
#[derive(Default, Clone, Component)]
pub struct State {
/// An example field that stores the number of messages that've been
- /// received by the client so far. The state gets cloned whenever the
- /// handler is called, so to have all the clones point to the same data and
- /// have it be mutable, we use an Arc<Mutex<T>>.
+ /// received by the client so far.
+ ///
+ /// The state gets cloned whenever the handler is called, so to have all
+ /// the clones point to the same data and have it be mutable, we use an
+ /// Arc<Mutex<T>>.
pub messages_received: Arc<Mutex<usize>>
}
diff --git a/azalea/examples/testbot/commands/debug.rs b/azalea/examples/testbot/commands/debug.rs
index b98d737f..d80ee3be 100644
--- a/azalea/examples/testbot/commands/debug.rs
+++ b/azalea/examples/testbot/commands/debug.rs
@@ -58,7 +58,7 @@ pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) {
};
let entity_id = source.bot.entity_component::<MinecraftEntityId>(entity);
source.reply(format!(
- "Your Minecraft ID is {} and your ECS id is {entity:?}",
+ "Your Minecraft ID is {} and your ECS ID is {entity:?}",
*entity_id
));
1
diff --git a/azalea/examples/testbot/main.rs b/azalea/examples/testbot/main.rs
index 249f7b92..b4ef20ba 100644
--- a/azalea/examples/testbot/main.rs
+++ b/azalea/examples/testbot/main.rs
@@ -127,8 +127,7 @@ async fn handle(bot: Client, event: azalea::Event, state: State) -> anyhow::Resu
bot.set_client_information(ClientInformation {
view_distance: 32,
..Default::default()
- })
- .await;
+ });
if swarm.args.pathfinder_debug_particles {
bot.ecs
.lock()
diff --git a/azalea/src/bot.rs b/azalea/src/bot.rs
index 1897f510..6d7dc774 100644
--- a/azalea/src/bot.rs
+++ b/azalea/src/bot.rs
@@ -57,8 +57,10 @@ impl Plugin for BotPlugin {
}
}
-/// A component that clients with [`BotPlugin`] will have. If you just want to
-/// check if an entity is one of our bots, you should use [`LocalEntity`].
+/// A component that clients with [`BotPlugin`] will have.
+///
+/// If you just want to check if an entity is one of our bots, you should use
+/// [`LocalEntity`].
#[derive(Default, Component)]
pub struct Bot {
jumping_once: bool,
@@ -97,8 +99,10 @@ pub trait BotClientExt {
fn wait_ticks(&self, n: usize) -> impl Future<Output = ()> + Send;
/// Wait for the specified number of ECS `Update`s.
fn wait_updates(&self, n: usize) -> impl Future<Output = ()> + Send;
- /// Mine a block. This won't turn the bot's head towards the block, so if
- /// that's necessary you'll have to do that yourself with [`look_at`].
+ /// Mine a block.
+ ///
+ /// This won't turn the bot's head towards the block, so if that's necessary
+ /// you'll have to do that yourself with [`look_at`].
///
/// [`look_at`]: crate::prelude::BotClientExt::look_at
fn mine(&self, position: BlockPos) -> impl Future<Output = ()> + Send;
diff --git a/azalea/src/container.rs b/azalea/src/container.rs
index cd11b7c2..57753cc3 100644
--- a/azalea/src/container.rs
+++ b/azalea/src/container.rs
@@ -27,8 +27,9 @@ impl Plugin for ContainerPlugin {
}
pub trait ContainerClientExt {
- /// Open a container in the world, like a chest. Use
- /// [`Client::open_inventory`] to open your own inventory.
+ /// Open a container in the world, like a chest.
+ ///
+ /// Use [`Client::open_inventory`] to open your own inventory.
///
/// ```
/// # use azalea::prelude::*;
@@ -48,8 +49,9 @@ pub trait ContainerClientExt {
&self,
pos: BlockPos,
) -> impl Future<Output = Option<ContainerHandle>> + Send;
- /// Open the player's inventory. This will return None if another
- /// container is open.
+ /// Open the player's inventory.
+ ///
+ /// This will return None if another container is open.
///
/// Note that this will send a packet to the server once it's dropped. Also,
/// due to how it's implemented, you could call this function multiple times
@@ -134,8 +136,10 @@ impl ContainerClientExt for Client {
}
}
-/// A handle to a container that may be open. This does not close the container
-/// when it's dropped. See [`ContainerHandle`] if that behavior is desired.
+/// A handle to a container that may be open.
+///
+/// This does not close the container when it's dropped. See [`ContainerHandle`]
+/// if that behavior is desired.
pub struct ContainerHandleRef {
id: i32,
client: Client,
@@ -159,15 +163,18 @@ impl ContainerHandleRef {
});
}
- /// Get the id of the container. If this is 0, that means it's the player's
- /// inventory. Otherwise, the number isn't really meaningful since only one
- /// container can be open at a time.
+ /// Get the ID of the container.
+ ///
+ /// If this is 0, that means it's the player's inventory. Otherwise, the
+ /// number isn't really meaningful since only one container can be open
+ /// at a time.
pub fn id(&self) -> i32 {
self.id
}
- /// Returns the menu of the container. If the container is closed, this
- /// will return `None`.
+ /// Returns the menu of the container.
+ ///
+ /// If the container is closed, this will return `None`.
///
/// Note that any modifications you make to the `Menu` you're given will not
/// actually cause any packets to be sent. If you're trying to modify your
@@ -191,13 +198,16 @@ impl ContainerHandleRef {
}
/// Returns the item slots in the container, not including the player's
- /// inventory. If the container is closed, this will return `None`.
+ /// inventory.
+ ///
+ /// If the container is closed, this will return `None`.
pub fn contents(&self) -> Option<Vec<ItemStack>> {
self.menu().map(|menu| menu.contents())
}
- /// Return the contents of the menu, including the player's inventory. If
- /// the container is closed, this will return `None`.
+ /// Return the contents of the menu, including the player's inventory.
+ ///
+ /// If the container is closed, this will return `None`.
pub fn slots(&self) -> Option<Vec<ItemStack>> {
self.menu().map(|menu| menu.slots())
}
@@ -233,8 +243,9 @@ impl ContainerHandleRef {
}
}
-/// A handle to the open container. The container will be closed once this is
-/// dropped.
+/// A handle to the open container.
+///
+/// The container will be closed once this is dropped.
#[derive(Deref)]
pub struct ContainerHandle(ContainerHandleRef);
diff --git a/azalea/src/lib.rs b/azalea/src/lib.rs
index e3e92170..069837b3 100644
--- a/azalea/src/lib.rs
+++ b/azalea/src/lib.rs
@@ -56,7 +56,7 @@ pub enum StartError {
}
/// A builder for creating new [`Client`]s. This is the recommended way of
-/// making Azalea bots.
+/// making a bot.
///
/// ```no_run
/// # use azalea::prelude::*;
@@ -201,8 +201,9 @@ where
}
/// Build this `ClientBuilder` into an actual [`Client`] and join the given
- /// server. If the client can't join, it'll keep retrying forever until it
- /// can.
+ /// server.
+ ///
+ /// If the client can't join, it'll keep retrying forever until it can.
///
/// The `address` argument can be a `&str`, [`ServerAddress`], or anything
/// that implements `TryInto<ServerAddress>`.
@@ -247,8 +248,10 @@ impl Default for ClientBuilder<NoState, ()> {
}
/// A marker that can be used in place of a State in [`ClientBuilder`] or
-/// [`SwarmBuilder`]. You probably don't need to use this manually since the
-/// compiler will infer it for you.
+/// [`SwarmBuilder`].
+///
+/// You probably don't need to use this manually since the compiler will infer
+/// it for you.
///
/// [`SwarmBuilder`]: swarm::SwarmBuilder
#[derive(Component, Clone, Default)]
diff --git a/azalea/src/nearest_entity.rs b/azalea/src/nearest_entity.rs
index 2c01e5df..6e94e331 100644
--- a/azalea/src/nearest_entity.rs
+++ b/azalea/src/nearest_entity.rs
@@ -65,6 +65,7 @@ where
F: QueryFilter + 'static,
{
/// Gets the nearest entity to the given position and world instance name.
+ ///
/// This method will return `None` if there are no entities within range. If
/// multiple entities are within range, only the closest one is returned.
pub fn nearest_to_position(
@@ -91,9 +92,11 @@ where
nearest_entity
}
- /// Gets the nearest entity to the given entity. This method will return
- /// `None` if there are no entities within range. If multiple entities are
- /// within range, only the closest one is returned.
+ /// Gets the nearest entity to the given entity.
+ ///
+ /// This method will return `None` if there are no entities within range. If
+ /// multiple entities are within range, only the closest one is
+ /// returned.
pub fn nearest_to_entity(&'a self, entity: Entity, max_distance: f64) -> Option<Entity> {
let Ok((position, instance_name)) = self.all_entities.get(entity) else {
return None;
@@ -122,8 +125,9 @@ where
}
/// This function get an iterator over all nearby entities to the given
- /// position within the given maximum distance. The entities in this
- /// iterator are not returned in any specific order.
+ /// position within the given maximum distance.
+ ///
+ /// The entities in this iterator are not returned in any specific order.
///
/// This function returns the Entity ID of nearby entities and their
/// distance away.
@@ -150,8 +154,9 @@ where
}
/// This function get an iterator over all nearby entities to the given
- /// entity within the given maximum distance. The entities in this iterator
- /// are not returned in any specific order.
+ /// entity within the given maximum distance.
+ ///
+ /// The entities in this iterator are not returned in any specific order.
///
/// This function returns the Entity ID of nearby entities and their
/// distance away.
diff --git a/azalea/src/pathfinder/astar.rs b/azalea/src/pathfinder/astar.rs
index b2559c1f..d2a57b38 100644
--- a/azalea/src/pathfinder/astar.rs
+++ b/azalea/src/pathfinder/astar.rs
@@ -312,9 +312,10 @@ impl PartialOrd for WeightedNode {
/// [`PathfinderOpts::max_timeout`]: super::goto_event::PathfinderOpts::max_timeout
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum PathfinderTimeout {
- /// Time out after a certain duration has passed. This is a good default so
- /// you don't waste too much time calculating a path if you're on a slow
- /// computer.
+ /// Time out after a certain duration has passed.
+ ///
+ /// This is a good default so you don't waste too much time calculating a
+ /// path if you're on a slow computer.
Time(Duration),
/// Time out after this many nodes have been considered.
///
diff --git a/azalea/src/pathfinder/goto_event.rs b/azalea/src/pathfinder/goto_event.rs
index 379c61d0..e4f934f2 100644
--- a/azalea/src/pathfinder/goto_event.rs
+++ b/azalea/src/pathfinder/goto_event.rs
@@ -106,8 +106,10 @@ impl PathfinderOpts {
self
}
/// The absolute maximum amount of time that the pathfinder function can
- /// take to find a path. If it takes this long, it means no usable path was
- /// found (so it might be impossible).
+ /// take to find a path.
+ ///
+ /// If it takes this long, it means no usable path was found (so it might be
+ /// impossible).
///
/// Defaults to `PathfinderTimeout::Time(Duration::from_secs(5))`.
pub fn max_timeout(mut self, max_timeout: PathfinderTimeout) -> Self {
diff --git a/azalea/src/pathfinder/mod.rs b/azalea/src/pathfinder/mod.rs
index 6d78b043..c001f838 100644
--- a/azalea/src/pathfinder/mod.rs
+++ b/azalea/src/pathfinder/mod.rs
@@ -917,7 +917,7 @@ pub fn check_for_path_obstruction(
}
}
-/// update the given [`ExecutingPath`] to recalculate the path of the nodes in
+/// Update the given [`ExecutingPath`] to recalculate the path of the nodes in
/// the given index range.
///
/// You should avoid making the range too large, since the timeout for the A*
@@ -1153,9 +1153,11 @@ pub fn recalculate_if_has_goal_but_no_path(
#[derive(Message)]
pub struct StopPathfindingEvent {
pub entity: Entity,
- /// If false, then let the current movement finish before stopping. If true,
- /// then stop moving immediately. This might cause the bot to fall if it was
- /// in the middle of parkouring.
+ /// Whether we should stop moving immediately without waiting for the
+ /// current movement to finish.
+ ///
+ /// This is usually set to false, since it might cause the bot to fall if it
+ /// was in the middle of parkouring.
pub force: bool,
}
@@ -1210,7 +1212,9 @@ pub fn stop_pathfinding_on_instance_change(
}
/// Checks whether the path has been obstructed, and returns Some(index) if it
-/// has been. The index is of the first obstructed node.
+/// has been.
+///
+/// The index is of the first obstructed node.
pub fn check_path_obstructed<SuccessorsFn>(
origin: BlockPos,
mut current_position: RelBlockPos,
diff --git a/azalea/src/pathfinder/moves/mod.rs b/azalea/src/pathfinder/moves/mod.rs
index 39ef786b..bb2354bf 100644
--- a/azalea/src/pathfinder/moves/mod.rs
+++ b/azalea/src/pathfinder/moves/mod.rs
@@ -137,8 +137,9 @@ impl ExecuteCtx<'_, '_, '_, '_, '_, '_, '_, '_> {
true
}
- /// Mine the block at the given position. Returns whether the block is being
- /// mined.
+ /// Mine the block at the given position.
+ ///
+ /// Returns whether the block is being mined.
pub fn mine(&mut self, block: BlockPos) -> bool {
let block_state = self
.instance
diff --git a/azalea/src/pathfinder/world.rs b/azalea/src/pathfinder/world.rs
index 318ed55e..0f1a8305 100644
--- a/azalea/src/pathfinder/world.rs
+++ b/azalea/src/pathfinder/world.rs
@@ -17,8 +17,9 @@ use super::{mining::MiningCache, rel_block_pos::RelBlockPos};
/// An efficient representation of the world used for the pathfinder.
pub struct CachedWorld {
- /// The origin that the [`RelBlockPos`] types will be relative to. This is
- /// for an optimization that reduces the size of the block positions
+ /// The origin that the [`RelBlockPos`] types will be relative to.
+ ///
+ /// This is for an optimization that reduces the size of the block positions
/// that are used by the pathfinder.
origin: BlockPos,
@@ -247,8 +248,9 @@ impl CachedWorld {
passable
}
- /// Get the block state at the given position. This is relatively slow, so
- /// you should avoid it whenever possible.
+ /// Get the block state at the given position.
+ ///
+ /// This is relatively slow, so you should avoid it whenever possible.
pub fn get_block_state(&self, pos: RelBlockPos) -> BlockState {
self.get_block_state_at_pos(pos.apply(self.origin))
}
@@ -304,8 +306,9 @@ impl CachedWorld {
solid
}
- /// Returns how much it costs to break this block. Returns 0 if the block is
- /// already passable.
+ /// Returns how much it costs to break this block.
+ ///
+ /// Returns 0 if the block is already passable.
pub fn cost_for_breaking_block(&self, pos: RelBlockPos, mining_cache: &MiningCache) -> f32 {
// SAFETY: pathfinding is single-threaded
let cached_mining_costs = unsafe { &mut *self.cached_mining_costs.get() };
@@ -478,8 +481,10 @@ impl CachedWorld {
+ self.cost_for_breaking_block(pos.up(1), mining_cache)
}
- /// Whether we can stand in this position. Checks if the block below is
- /// solid, and that the two blocks above that are passable.
+ /// Whether we can stand in this position.
+ ///
+ /// Checks if the block below is solid, and that the two blocks above that
+ /// are passable.
pub fn is_standable(&self, pos: RelBlockPos) -> bool {
self.is_standable_at_block_pos(pos.apply(self.origin))
}
diff --git a/azalea/src/swarm/mod.rs b/azalea/src/swarm/mod.rs
index f2e65715..59bad419 100644
--- a/azalea/src/swarm/mod.rs
+++ b/azalea/src/swarm/mod.rs
@@ -81,8 +81,10 @@ where
pub(crate) app: SubApp,
/// The accounts and proxies that are going to join the server.
pub(crate) accounts: Vec<(Account, JoinOpts)>,
- /// The individual bot states. This must be the same length as `accounts`,
- /// since each bot gets one state.
+ /// The individual bot states.
+ ///
+ /// This must be the same length as `accounts`, since each bot gets one
+ /// state.
pub(crate) states: Vec<S>,
/// The state for the overall swarm.
pub(crate) swarm_state: SS,
@@ -92,14 +94,16 @@ where
/// [`SwarmEvent`].
pub(crate) swarm_handler: Option<BoxSwarmHandleFn<SS, SR>>,
- /// How long we should wait between each bot joining the server. Set to
- /// None to have every bot connect at the same time. None is different than
- /// a duration of 0, since if a duration is present the bots will wait for
- /// the previous one to be ready.
+ /// How long we should wait between each bot joining the server.
+ ///
+ /// If this is None, every bot will connect at the same time. None is
+ /// different than a duration of 0, since if a duration is present the
+ /// bots will wait for the previous one to be ready.
pub(crate) join_delay: Option<Duration>,
- /// The default reconnection delay for our bots. This will change the value
- /// of the `AutoReconnectDelay` resource.
+ /// The default reconnection delay for our bots.
+ ///
+ /// This will change the value of the [`AutoReconnectDelay`] resource.
pub(crate) reconnect_after: Option<Duration>,
}
impl SwarmBuilder<NoState, NoSwarmState, (), ()> {
@@ -165,7 +169,8 @@ where
SS: Default + Send + Sync + Clone + Resource + 'static,
{
/// Set the function that's called every time a bot receives an
- /// [`enum@Event`]. This is the way to handle normal per-bot events.
+ /// [`enum@Event`]. This is the intended way to handle normal per-bot
+ /// events.
///
/// Currently you can have up to one handler.
///
@@ -221,7 +226,7 @@ where
S: Send + Sync + Clone + Component + 'static,
{
/// Set the function that's called every time the swarm receives a
- /// [`SwarmEvent`]. This is the way to handle global swarm events.
+ /// [`SwarmEvent`]. This is the intended way to handle global swarm events.
///
/// Currently you can have up to one swarm handler.
///
@@ -306,8 +311,9 @@ where
self
}
- /// Add a single new [`Account`] to the swarm. Use [`Self::add_accounts`] to
- /// add multiple accounts at a time.
+ /// Add a single new [`Account`] to the swarm.
+ ///
+ /// Use [`Self::add_accounts`] to add multiple accounts at a time.
///
/// This will make the state for this client be the default, use
/// [`Self::add_account_with_state`] to avoid that.
@@ -319,15 +325,19 @@ where
self.add_account_with_state_and_opts(account, S::default(), JoinOpts::default())
}
- /// Add an account with a custom initial state. Use just
- /// [`Self::add_account`] to use the Default implementation for the state.
+ /// Add an account with a custom initial state.
+ ///
+ /// Use just [`Self::add_account`] to use the `Default` implementation for
+ /// the state.
#[must_use]
pub fn add_account_with_state(self, account: Account, state: S) -> Self {
self.add_account_with_state_and_opts(account, state, JoinOpts::default())
}
- /// Add an account with a custom initial state. Use just
- /// [`Self::add_account`] to use the Default implementation for the state.
+ /// Add an account with a custom initial state.
+ ///
+ /// Use just [`Self::add_account`] to use the `Default` implementation for
+ /// the state.
#[must_use]
pub fn add_account_with_opts(self, account: Account, opts: JoinOpts) -> Self
where
@@ -612,8 +622,10 @@ impl Default for SwarmBuilder<NoState, NoSwarmState, (), ()> {
pub enum SwarmEvent {
/// All the bots in the swarm have successfully joined the server.
Login,
- /// The swarm was created. This is only fired once, and it's guaranteed to
- /// be the first event to fire.
+ /// The swarm was created.
+ ///
+ /// This is only fired once, and it's guaranteed to be the first event to
+ /// fire.
Init,
/// A bot got disconnected from the server.
///
@@ -688,8 +700,9 @@ pub type BoxSwarmHandleFn<SS, R> =
/// Ok(())
/// }
impl Swarm {
- /// Add a new account to the swarm. You can remove it later by calling
- /// [`Client::disconnect`].
+ /// Add a new account to the swarm.
+ ///
+ /// You can remove it later by calling [`Client::disconnect`].
///
/// # Errors
///
@@ -702,9 +715,10 @@ impl Swarm {
self.add_with_opts(account, state, &JoinOpts::default())
.await
}
- /// Add a new account to the swarm, using custom options. This is useful if
- /// you want bots in the same swarm to connect to different addresses.
- /// Usually you'll just want [`Self::add`] though.
+ /// Add a new account to the swarm, using custom options.
+ ///
+ /// This is useful if you want bots in the same swarm to connect to
+ /// different addresses. Usually you'll just want [`Self::add`] though.
///
/// # Errors
///
@@ -831,8 +845,9 @@ impl Swarm {
);
}
- /// Add a new account to the swarm, retrying if it couldn't join. This will
- /// run forever until the bot joins or the task is aborted.
+ /// Add a new account to the swarm, retrying if it couldn't join.
+ ///
+ /// This will run forever until the bot joins or the task is aborted.
///
/// This does exponential backoff (though very limited), starting at 5
/// seconds and doubling up to 15 seconds.
@@ -928,8 +943,9 @@ impl PluginGroup for DefaultSwarmPlugins {
}
}
-/// A marker that can be used in place of a SwarmState in [`SwarmBuilder`]. You
-/// probably don't need to use this manually since the compiler will infer it
-/// for you.
+/// A marker that can be used in place of a SwarmState in [`SwarmBuilder`].
+///
+/// You probably don't need to use this manually since the compiler will infer
+/// it for you.
#[derive(Resource, Clone, Default)]
pub struct NoSwarmState;