aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2025-06-05 00:59:14 -0400
committermat <git@matdoes.dev>2025-06-05 00:59:14 -0400
commit338f931c51ab3665c7c18124ca3e35bfd2ff5ca0 (patch)
tree5109e8df092fcea99ee4282882cdd9614b2beb05
parent874f05181028af233b81b1d7d3322a39a0421f33 (diff)
downloadazalea-drasl-338f931c51ab3665c7c18124ca3e35bfd2ff5ca0.tar.xz
wait for block to exist when calling open_container_at
-rw-r--r--azalea/src/container.rs19
-rw-r--r--azalea/src/pathfinder/goals.rs6
2 files changed, 23 insertions, 2 deletions
diff --git a/azalea/src/container.rs b/azalea/src/container.rs
index 3521c06d..6c4e86cc 100644
--- a/azalea/src/container.rs
+++ b/azalea/src/container.rs
@@ -10,6 +10,7 @@ use azalea_inventory::{
ItemStack, Menu,
operations::{ClickOperation, PickupClick, QuickMoveClick},
};
+use azalea_physics::collision::BlockWithShape;
use azalea_protocol::packets::game::ClientboundGamePacket;
use bevy_app::{App, Plugin, Update};
use bevy_ecs::{component::Component, prelude::EventReader, system::Commands};
@@ -54,14 +55,28 @@ impl ContainerClientExt for Client {
/// # }
/// ```
async fn open_container_at(&self, pos: BlockPos) -> Option<ContainerHandle> {
+ let mut ticks = self.get_tick_broadcaster();
+ // wait until it's not air (up to 10 ticks)
+ for _ in 0..10 {
+ if !self
+ .world()
+ .read()
+ .get_block_state(&pos)
+ .unwrap_or_default()
+ .is_collision_shape_empty()
+ {
+ break;
+ }
+ let _ = ticks.recv().await;
+ }
+
self.ecs
.lock()
.entity_mut(self.entity)
.insert(WaitingForInventoryOpen);
self.block_interact(pos);
- let mut receiver = self.get_tick_broadcaster();
- while receiver.recv().await.is_ok() {
+ while ticks.recv().await.is_ok() {
let ecs = self.ecs.lock();
if ecs.get::<WaitingForInventoryOpen>(self.entity).is_none() {
break;
diff --git a/azalea/src/pathfinder/goals.rs b/azalea/src/pathfinder/goals.rs
index aa6f357a..4c0dbafa 100644
--- a/azalea/src/pathfinder/goals.rs
+++ b/azalea/src/pathfinder/goals.rs
@@ -220,6 +220,12 @@ impl Goal for ReachBlockPosGoal {
BlockPosGoal(self.pos).heuristic(n)
}
fn success(&self, n: BlockPos) -> bool {
+ if n.up(1) == self.pos {
+ // our head is in the block, assume it's always reachable (to reduce the amount
+ // of impossible goals)
+ return true;
+ }
+
// only do the expensive check if we're close enough
let distance = self.pos.distance_squared_to(&n);
if distance > self.max_check_distance.pow(2) {