diff options
Diffstat (limited to 'azalea/src')
| -rw-r--r-- | azalea/src/auto_tool.rs | 10 | ||||
| -rw-r--r-- | azalea/src/pathfinder/mod.rs | 61 | ||||
| -rw-r--r-- | azalea/src/pathfinder/moves/basic.rs | 8 | ||||
| -rw-r--r-- | azalea/src/pathfinder/world.rs | 30 |
4 files changed, 55 insertions, 54 deletions
diff --git a/azalea/src/auto_tool.rs b/azalea/src/auto_tool.rs index 81fe3131..ace032d9 100644 --- a/azalea/src/auto_tool.rs +++ b/azalea/src/auto_tool.rs @@ -95,11 +95,11 @@ pub fn accurate_best_tool_in_hotbar_for_block( } } } - if let Some(this_item_speed) = this_item_speed { - if this_item_speed > best_speed { - best_slot = Some(i); - best_speed = this_item_speed; - } + if let Some(this_item_speed) = this_item_speed + && this_item_speed > best_speed + { + best_slot = Some(i); + best_speed = this_item_speed; } } diff --git a/azalea/src/pathfinder/mod.rs b/azalea/src/pathfinder/mod.rs index aba8610a..820d6f8b 100644 --- a/azalea/src/pathfinder/mod.rs +++ b/azalea/src/pathfinder/mod.rs @@ -715,12 +715,12 @@ pub fn check_node_reached( direction: WalkDirection::None, }); commands.entity(entity).remove::<ExecutingPath>(); - if let Some(goal) = pathfinder.goal.clone() { - if goal.success(movement.target) { - info!("goal was reached!"); - pathfinder.goal = None; - pathfinder.successors_fn = None; - } + if let Some(goal) = pathfinder.goal.clone() + && goal.success(movement.target) + { + info!("goal was reached!"); + pathfinder.goal = None; + pathfinder.successors_fn = None; } } @@ -875,17 +875,17 @@ fn patch_path( let mut is_patch_complete = false; if let Some(path_found_event) = path_found_event { - if let Some(found_path_patch) = path_found_event.path { - if !found_path_patch.is_empty() { - new_path.extend(found_path_patch); - - if !path_found_event.is_partial { - new_path.extend(executing_path.path.iter().skip(*patch_nodes.end()).cloned()); - is_patch_complete = true; - debug!("the patch is not partial :)"); - } else { - debug!("the patch is partial, throwing away rest of path :("); - } + if let Some(found_path_patch) = path_found_event.path + && !found_path_patch.is_empty() + { + new_path.extend(found_path_patch); + + if !path_found_event.is_partial { + new_path.extend(executing_path.path.iter().skip(*patch_nodes.end()).cloned()); + is_patch_complete = true; + debug!("the patch is not partial :)"); + } else { + debug!("the patch is partial, throwing away rest of path :("); } } } else { @@ -1028,19 +1028,20 @@ pub fn recalculate_if_has_goal_but_no_path( mut goto_events: EventWriter<GotoEvent>, ) { for (entity, mut pathfinder) in &mut query { - if pathfinder.goal.is_some() && !pathfinder.is_calculating { - if let Some(goal) = pathfinder.goal.as_ref().cloned() { - debug!("Recalculating path because it has a goal but no ExecutingPath"); - goto_events.write(GotoEvent { - entity, - goal, - successors_fn: pathfinder.successors_fn.unwrap(), - allow_mining: pathfinder.allow_mining, - min_timeout: pathfinder.min_timeout.expect("min_timeout should be set"), - max_timeout: pathfinder.max_timeout.expect("max_timeout should be set"), - }); - pathfinder.is_calculating = true; - } + if pathfinder.goal.is_some() + && !pathfinder.is_calculating + && let Some(goal) = pathfinder.goal.as_ref().cloned() + { + debug!("Recalculating path because it has a goal but no ExecutingPath"); + goto_events.write(GotoEvent { + entity, + goal, + successors_fn: pathfinder.successors_fn.unwrap(), + allow_mining: pathfinder.allow_mining, + min_timeout: pathfinder.min_timeout.expect("min_timeout should be set"), + max_timeout: pathfinder.max_timeout.expect("max_timeout should be set"), + }); + pathfinder.is_calculating = true; } } } diff --git a/azalea/src/pathfinder/moves/basic.rs b/azalea/src/pathfinder/moves/basic.rs index 354472a7..fe0d81f5 100644 --- a/azalea/src/pathfinder/moves/basic.rs +++ b/azalea/src/pathfinder/moves/basic.rs @@ -173,10 +173,10 @@ fn execute_ascend_move(mut ctx: ExecuteCtx) { (-1, 0) => Some(properties::FacingCardinal::West), _ => None, }; - if let Some(expected_stair_facing) = expected_stair_facing { - if stair_facing == expected_stair_facing { - return; - } + if let Some(expected_stair_facing) = expected_stair_facing + && stair_facing == expected_stair_facing + { + return; } } diff --git a/azalea/src/pathfinder/world.rs b/azalea/src/pathfinder/world.rs index 3b1b36b9..940a7c84 100644 --- a/azalea/src/pathfinder/world.rs +++ b/azalea/src/pathfinder/world.rs @@ -47,10 +47,10 @@ impl CachedSections { if let Some(last_item) = self.sections.get(self.last_index) { if last_item.pos == pos { return Some(&mut self.sections[self.last_index]); - } else if let Some(second_last_item) = self.sections.get(self.second_last_index) { - if second_last_item.pos == pos { - return Some(&mut self.sections[self.second_last_index]); - } + } else if let Some(second_last_item) = self.sections.get(self.second_last_index) + && second_last_item.pos == pos + { + return Some(&mut self.sections[self.second_last_index]); } } @@ -134,17 +134,17 @@ impl CachedWorld { // optimization: avoid doing the iter lookup if the last chunk we looked up is // the same - if let Some(last_chunk_cache_index) = *self.last_chunk_cache_index.borrow() { - if cached_chunks[last_chunk_cache_index].0 == chunk_pos { - // don't bother with the iter lookup - let sections = &cached_chunks[last_chunk_cache_index].1; - if section_index >= sections.len() { - // y position is out of bounds - return None; - }; - let section: &azalea_world::palette::PalettedContainer = §ions[section_index]; - return Some(f(section)); - } + if let Some(last_chunk_cache_index) = *self.last_chunk_cache_index.borrow() + && cached_chunks[last_chunk_cache_index].0 == chunk_pos + { + // don't bother with the iter lookup + let sections = &cached_chunks[last_chunk_cache_index].1; + if section_index >= sections.len() { + // y position is out of bounds + return None; + }; + let section: &azalea_world::palette::PalettedContainer = §ions[section_index]; + return Some(f(section)); } // get section from cache |
