aboutsummaryrefslogtreecommitdiff
path: root/azalea/src/pathfinder/mining.rs
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2023-10-10 23:21:23 -0500
committermat <git@matdoes.dev>2023-10-10 23:21:23 -0500
commit9a687f0ffebad80441e036aabe14e7cf80c774d3 (patch)
tree2f6ad5a1a14cae23723550c934df395aab1733f6 /azalea/src/pathfinder/mining.rs
parent0297b8aacee27d9e86cea781b3751591e32df401 (diff)
downloadazalea-drasl-9a687f0ffebad80441e036aabe14e7cf80c774d3.tar.xz
start adding mining to pathfinder
Diffstat (limited to 'azalea/src/pathfinder/mining.rs')
-rw-r--r--azalea/src/pathfinder/mining.rs30
1 files changed, 30 insertions, 0 deletions
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<u32, f32>,
+ 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
+ }
+ }
+}