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

pathfinder mining descending

This commit is contained in:
mat 2023-12-10 19:31:41 -06:00
parent 967da5aeba
commit f21355cba6
3 changed files with 64 additions and 11 deletions

View file

@ -1,4 +1,7 @@
use std::{collections::HashSet, ops::RangeInclusive};
use std::{
collections::HashSet,
ops::{Add, RangeInclusive},
};
use crate::BlockState;
@ -31,3 +34,13 @@ impl BlockStates {
self.set.contains(state)
}
}
impl Add for BlockStates {
type Output = Self;
fn add(self, rhs: Self) -> Self::Output {
Self {
set: self.set.union(&rhs.set).copied().collect(),
}
}
}

View file

@ -63,6 +63,18 @@ 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() {

View file

@ -151,19 +151,39 @@ fn descend_move(ctx: &mut PathfinderCtx, pos: BlockPos) {
for dir in CardinalDirection::iter() {
let dir_delta = BlockPos::new(dir.x(), 0, dir.z());
let new_horizontal_position = pos + dir_delta;
let fall_distance = ctx.world.fall_distance(new_horizontal_position);
if fall_distance == 0 || fall_distance > 3 {
let break_cost_1 = ctx
.world
.cost_for_passing(new_horizontal_position, ctx.mining_cache);
if break_cost_1 == f32::MAX {
continue;
}
let mut fall_distance = ctx.world.fall_distance(new_horizontal_position);
if fall_distance > 3 {
continue;
}
if fall_distance == 0 {
// if the fall distance is 0, set it to 1 so we try mining
fall_distance = 1
}
let new_position = new_horizontal_position.down(fall_distance as i32);
// check whether 3 blocks vertically forward are passable
if !ctx.world.is_passable(new_horizontal_position) {
continue;
}
// check whether we can stand on the target position
if !ctx.world.is_standable(new_position) {
continue;
// only mine if we're descending 1 block
let break_cost_2;
if fall_distance == 1 {
break_cost_2 = ctx.world.cost_for_standing(new_position, ctx.mining_cache);
if break_cost_2 == f32::MAX {
continue;
}
} else {
// check whether we can stand on the target position
if !ctx.world.is_standable(new_position) {
continue;
}
break_cost_2 = 0.;
}
let cost = WALK_OFF_BLOCK_COST
@ -175,7 +195,9 @@ fn descend_move(ctx: &mut PathfinderCtx, pos: BlockPos) {
// probably not possible but just in case
.unwrap_or(f32::MAX),
CENTER_AFTER_FALL_COST,
);
)
+ break_cost_1
+ break_cost_2;
ctx.edges.push(Edge {
movement: astar::Movement {
@ -197,6 +219,12 @@ fn execute_descend_move(mut ctx: ExecuteCtx) {
..
} = ctx;
for i in (0..=(start.y - target.y + 1)).rev() {
if ctx.mine(target.up(i)) {
return;
}
}
let start_center = start.center();
let center = target.center();