1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 06:16:04 +00:00

add mine_with_auto_tool

This commit is contained in:
mat 2025-06-10 19:47:42 -01:00
parent e4ead93f19
commit 2a6ac0764f

View file

@ -1,8 +1,11 @@
use azalea_block::{BlockState, BlockTrait, fluid_state::FluidKind};
use azalea_client::{Client, inventory::Inventory};
use azalea_core::position::BlockPos;
use azalea_entity::{FluidOnEyes, Physics};
use azalea_inventory::{ItemStack, Menu, components};
use crate::BotClientExt;
#[derive(Debug)]
pub struct BestToolResult {
pub index: usize,
@ -11,6 +14,7 @@ pub struct BestToolResult {
pub trait AutoToolClientExt {
fn best_tool_in_hotbar_for_block(&self, block: BlockState) -> BestToolResult;
fn mine_with_auto_tool(&self, block_pos: BlockPos) -> impl Future<Output = ()> + Send;
}
impl AutoToolClientExt for Client {
@ -22,6 +26,17 @@ impl AutoToolClientExt for Client {
accurate_best_tool_in_hotbar_for_block(block, menu, physics, fluid_on_eyes)
}
async fn mine_with_auto_tool(&self, block_pos: BlockPos) {
let block_state = self
.world()
.read()
.get_block_state(&block_pos)
.unwrap_or_default();
let best_tool_result = self.best_tool_in_hotbar_for_block(block_state);
self.set_selected_hotbar_slot(best_tool_result.index as u8);
self.mine(block_pos).await;
}
}
/// Returns the best tool in the hotbar for the given block.