From 9a687f0ffebad80441e036aabe14e7cf80c774d3 Mon Sep 17 00:00:00 2001 From: mat Date: Tue, 10 Oct 2023 23:21:23 -0500 Subject: start adding mining to pathfinder --- azalea/src/pathfinder/mining.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 azalea/src/pathfinder/mining.rs (limited to 'azalea/src/pathfinder/mining.rs') diff --git a/azalea/src/pathfinder/mining.rs b/azalea/src/pathfinder/mining.rs new file mode 100644 index 00000000..d5977973 --- /dev/null +++ b/azalea/src/pathfinder/mining.rs @@ -0,0 +1,30 @@ +use azalea_block::BlockState; +use azalea_inventory::Menu; +use nohash_hasher::IntMap; + +use crate::auto_tool::best_tool_in_hotbar_for_block; + +pub struct MiningCache { + block_state_id_costs: IntMap, + inventory_menu: Menu, +} + +impl MiningCache { + pub fn new(inventory_menu: Menu) -> Self { + Self { + block_state_id_costs: IntMap::default(), + inventory_menu, + } + } + + pub fn cost_for(&mut self, block: BlockState) -> f32 { + if let Some(cost) = self.block_state_id_costs.get(&block.id) { + *cost + } else { + let best_tool_result = best_tool_in_hotbar_for_block(block, &self.inventory_menu); + let cost = 1. / best_tool_result.percentage_per_tick; + self.block_state_id_costs.insert(block.id, cost); + cost + } + } +} -- cgit v1.2.3