aboutsummaryrefslogtreecommitdiff
path: root/azalea/src/auto_tool.rs
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2023-12-15 11:26:40 -0600
committerGitHub <noreply@github.com>2023-12-15 11:26:40 -0600
commita707e2eb82b74994a16083b31fa4576332cf1995 (patch)
treedb6c2ac94dd73590befd68a9b1b0ef960410b0df /azalea/src/auto_tool.rs
parent59e140ddd655c7dc6e35109b91286118c51bcc06 (diff)
downloadazalea-drasl-a707e2eb82b74994a16083b31fa4576332cf1995.tar.xz
Add mining to the pathfinder (#122)
* basic pathfinder mining poc * mining descending and autotool * pathfinder mining descending * pathfinder fixes * allow disabling pathfinder miner and other fixes * small optimization to avoid chunk vec iter lookup sometimes * seeded rng in pathfinder bench * consistently use f32::INFINITY this brings performance much closer to how it was before * astar heuristic optimization from baritone * add downward_move * fix downward move execute * avoid liquids and falling blocks when mining * fix COST_HEURISTIC * fix to not path through flowing liquids * only reset pathfinder timeout while mining if the block is close enough * cache mining costs of block positions * fix mine_while_at_start and move PathfinderDebugParticles to its own module * add ReachBlockPosGoal in other news: azalea's sin/cos functions were broken this whole time and i never noticed * clippy and add things that i accidentally didn't commit * improve wording on doc for azalea::pathfinder
Diffstat (limited to 'azalea/src/auto_tool.rs')
-rw-r--r--azalea/src/auto_tool.rs51
1 files changed, 51 insertions, 0 deletions
diff --git a/azalea/src/auto_tool.rs b/azalea/src/auto_tool.rs
index 2cf53085..bc9bb474 100644
--- a/azalea/src/auto_tool.rs
+++ b/azalea/src/auto_tool.rs
@@ -4,6 +4,7 @@ use azalea_entity::{FluidOnEyes, Physics};
use azalea_inventory::{ItemSlot, Menu};
use azalea_registry::Fluid;
+#[derive(Debug)]
pub struct BestToolResult {
pub index: usize,
pub percentage_per_tick: f32,
@@ -62,7 +63,57 @@ pub fn accurate_best_tool_in_hotbar_for_block(
let mut best_slot = None;
let block = Box::<dyn Block>::from(block);
+ let registry_block = block.as_registry_block();
+ if matches!(
+ registry_block,
+ azalea_registry::Block::Water | azalea_registry::Block::Lava
+ ) {
+ // can't mine fluids
+ return BestToolResult {
+ index: 0,
+ percentage_per_tick: 0.,
+ };
+ }
+
+ // find the first slot that has an item without durability
+ for (i, item_slot) in hotbar_slots.iter().enumerate() {
+ let this_item_speed;
+ match item_slot {
+ ItemSlot::Empty => {
+ this_item_speed = Some(azalea_entity::mining::get_mine_progress(
+ block.as_ref(),
+ azalea_registry::Item::Air,
+ menu,
+ fluid_on_eyes,
+ physics,
+ ));
+ }
+ ItemSlot::Present(item_slot) => {
+ // lazy way to avoid checking durability since azalea doesn't have durability
+ // data yet
+ if item_slot.nbt.is_none() {
+ this_item_speed = Some(azalea_entity::mining::get_mine_progress(
+ block.as_ref(),
+ item_slot.kind,
+ menu,
+ fluid_on_eyes,
+ physics,
+ ));
+ } else {
+ this_item_speed = None;
+ }
+ }
+ }
+ if let Some(this_item_speed) = this_item_speed {
+ if this_item_speed > best_speed {
+ best_slot = Some(i);
+ best_speed = this_item_speed;
+ }
+ }
+ }
+
+ // now check every item
for (i, item_slot) in hotbar_slots.iter().enumerate() {
if let ItemSlot::Present(item_slot) = item_slot {
let this_item_speed = azalea_entity::mining::get_mine_progress(