aboutsummaryrefslogtreecommitdiff
path: root/azalea/src
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2026-01-06 06:34:19 -0500
committermat <git@matdoes.dev>2026-01-06 06:34:19 -0500
commitfdbcfaab4813da928f9f27e119d4951088c3a853 (patch)
tree19f33692f882ada386f8b6aea1e1a195a905e286 /azalea/src
parent9c2c7c3497a74e80d7186fdcd97ce2518520faa6 (diff)
downloadazalea-drasl-fdbcfaab4813da928f9f27e119d4951088c3a853.tar.xz
add a few more convenience functions and update some docs
Diffstat (limited to 'azalea/src')
-rw-r--r--azalea/src/client_impl/mining.rs7
-rw-r--r--azalea/src/client_impl/mod.rs11
-rw-r--r--azalea/src/entity_ref/mod.rs11
-rw-r--r--azalea/src/entity_ref/shared_impls.rs4
-rw-r--r--azalea/src/pathfinder/astar.rs4
5 files changed, 32 insertions, 5 deletions
diff --git a/azalea/src/client_impl/mining.rs b/azalea/src/client_impl/mining.rs
index 980fc47f..11c74480 100644
--- a/azalea/src/client_impl/mining.rs
+++ b/azalea/src/client_impl/mining.rs
@@ -1,4 +1,4 @@
-use azalea_client::mining::{LeftClickMine, StartMiningBlockEvent};
+use azalea_client::mining::{LeftClickMine, Mining, StartMiningBlockEvent};
use azalea_core::position::BlockPos;
use crate::Client;
@@ -14,6 +14,11 @@ impl Client {
});
}
+ /// Returns true if the client is currently trying to mine a block.
+ pub fn is_mining(&self) -> bool {
+ self.get_component::<Mining>().is_some()
+ }
+
/// When enabled, the bot will mine any block that it is looking at if it is
/// reachable.
pub fn left_click_mine(&self, enabled: bool) {
diff --git a/azalea/src/client_impl/mod.rs b/azalea/src/client_impl/mod.rs
index db9ecf91..dc4ab90f 100644
--- a/azalea/src/client_impl/mod.rs
+++ b/azalea/src/client_impl/mod.rs
@@ -11,6 +11,7 @@ use azalea_client::{
packet::game::SendGamePacketEvent,
player::{GameProfileComponent, PlayerInfo},
start_ecs_runner,
+ tick_counter::TicksConnected,
};
use azalea_core::data_registry::{DataRegistryWithKey, ResolvableDataRegistry};
use azalea_entity::indexing::{EntityIdIndex, EntityUuidIndex};
@@ -450,4 +451,14 @@ impl Client {
.map(|(name, data)| f(name, data))
})
}
+
+ /// Returns the number of ticks since the `login` packet was received, or 0
+ /// if the client isn't in the world.
+ ///
+ /// This is a shortcut for getting the [`TicksConnected`] component.
+ pub fn ticks_connected(&self) -> u64 {
+ self.get_component::<TicksConnected>()
+ .map(|c| c.0)
+ .unwrap_or(0)
+ }
}
diff --git a/azalea/src/entity_ref/mod.rs b/azalea/src/entity_ref/mod.rs
index 2f49d975..d604fe00 100644
--- a/azalea/src/entity_ref/mod.rs
+++ b/azalea/src/entity_ref/mod.rs
@@ -132,4 +132,15 @@ impl EntityRef {
pub fn interact(&self) {
self.client.entity_interact(self.entity);
}
+
+ /// Look at this entity from the client that created the `EntityRef`.
+ pub fn look_at(&self) {
+ self.client.look_at(self.eye_position());
+ }
+
+ /// Returns the distance between the client's feet position and this
+ /// entity's feet position.
+ pub fn distance_to_client(&self) -> f64 {
+ self.position().distance_to(self.client.position())
+ }
}
diff --git a/azalea/src/entity_ref/shared_impls.rs b/azalea/src/entity_ref/shared_impls.rs
index 9ef396a0..5e2255c5 100644
--- a/azalea/src/entity_ref/shared_impls.rs
+++ b/azalea/src/entity_ref/shared_impls.rs
@@ -87,11 +87,11 @@ impl_entity_functions! {
}
Client:
- /// Get the health of this client.
+ /// Get the health of this client, typically in the range `0..=20`.
///
/// This is a shortcut for `*bot.component::<Health>()`.
EntityRef:
- /// Get the health of this entity.
+ /// Get the health of this entity, typically in the range `0..=20`.
///
/// Also see [`Client::health`].
pub fn health(&self) -> f32 {
diff --git a/azalea/src/pathfinder/astar.rs b/azalea/src/pathfinder/astar.rs
index 69151991..ea2d45e2 100644
--- a/azalea/src/pathfinder/astar.rs
+++ b/azalea/src/pathfinder/astar.rs
@@ -303,8 +303,8 @@ impl PathfinderHeap {
pub fn push(&mut self, item: WeightedNode) {
if let Some(top) = self.radix_heap.top() {
- // this can happen when the heuristic isn't optimal, so just fall back to a
- // binary heap in those cases
+ // this can happen when the heuristic wasn't an underestimate, so just fall back
+ // to a binary heap in those cases
if item.f_score < f32::from_bits(top.0) {
self.binary_heap.push(item);
return;