aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md2
-rw-r--r--azalea/src/container.rs38
2 files changed, 30 insertions, 10 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a17fda99..cfc4f3a4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -22,7 +22,7 @@ is breaking anyways, semantic versioning is not followed.
- `Client::query`, `map_component`, and `map_get_component` were replaced by `Client::query_self`.
- Rename `SendPacketEvent` to `SendGamePacketEvent` and `PingEvent` to `GamePingEvent`.
- Swap the order of the type parameters in entity filtering functions so query is first, then filter.
-- Add optional `timeout_ticks` field to `Client::open_container_at`.
+- Add `Client::open_container_at_with_timeout_ticks`, and `Client::open_container_at` now times out after 5 seconds.
- Rename `ResourceLocation` to `Identifier` to match Minecraft's new internal naming.
- Rename `azalea_protocol::resolver` to `resolve` and `ResolverError` to `ResolveError`.
diff --git a/azalea/src/container.rs b/azalea/src/container.rs
index 57d0b369..dc85ba96 100644
--- a/azalea/src/container.rs
+++ b/azalea/src/container.rs
@@ -31,35 +31,50 @@ pub trait ContainerClientExt {
///
/// Use [`Client::open_inventory`] to open your own inventory.
///
- /// `timeout_ticks` indicates how long the client will wait before giving
- /// up and returning `None`. You may need to adjust it based on latency.
- /// Setting the timeout to `None` will result in waiting potentially
- /// forever.
+ /// This function times out after 5 seconds (100 ticks). Use
+ /// [`Self::open_container_at_with_timeout_ticks`] if you would like to
+ /// configure this.
///
/// ```
- /// # use azalea::prelude::*;
+ /// # use azalea::{prelude::*, azalea::registry::Block};
/// # async fn example(mut bot: azalea::Client) {
/// let target_pos = bot
/// .world()
/// .read()
- /// .find_block(bot.position(), &azalea::registry::Block::Chest.into());
+ /// .find_block(bot.position(), &Block::Chest.into());
/// let Some(target_pos) = target_pos else {
/// bot.chat("no chest found");
/// return;
/// };
- /// let container = bot.open_container_at(target_pos, None).await;
+ /// let container = bot.open_container_at(target_pos).await;
/// # }
/// ```
fn open_container_at(
&self,
pos: BlockPos,
+ ) -> impl Future<Output = Option<ContainerHandle>> + Send;
+
+ /// Open a container in the world, or time out after a specified amount of
+ /// ticks.
+ ///
+ /// See [`Self::open_container_at`] for more information. That function
+ /// defaults to a timeout of 5 seconds (100 ticks), which is usually good
+ /// enough. However to detect failures faster or to account for server
+ /// lag, you may find it useful to adjust the timeout to a different
+ /// value.
+ ///
+ /// The timeout is measured in game ticks (on the client, not the server),
+ /// i.e. 1/20th of a second.
+ fn open_container_at_with_timeout_ticks(
+ &self,
+ pos: BlockPos,
timeout_ticks: Option<usize>,
) -> impl Future<Output = Option<ContainerHandle>> + Send;
/// Wait until a container is open, up to the specified number of ticks.
///
/// Returns `None` if the container was immediately opened and closed, or if
- /// the timeout expires.
+ /// the timeout expired.
///
/// If `timeout_ticks` is None, there will be no timeout.
fn wait_for_container_open(
@@ -97,7 +112,12 @@ pub trait ContainerClientExt {
}
impl ContainerClientExt for Client {
- async fn open_container_at(
+ async fn open_container_at(&self, pos: BlockPos) -> Option<ContainerHandle> {
+ self.open_container_at_with_timeout_ticks(pos, Some(20 * 5))
+ .await
+ }
+
+ async fn open_container_at_with_timeout_ticks(
&self,
pos: BlockPos,
timeout_ticks: Option<usize>,