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 { + 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::(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) {