11use azalea_block:: { BlockBehavior , BlockTrait } ;
2- use azalea_core:: tier:: get_item_tier;
3- use azalea_registry:: {
4- builtin:: { BlockKind , ItemKind , MobEffect } ,
5- tags,
6- } ;
2+ use azalea_inventory:: { ItemStack , components:: Tool } ;
3+ use azalea_registry:: builtin:: { BlockKind , MobEffect } ;
74
85use crate :: { ActiveEffects , Attributes , FluidOnEyes , Physics } ;
96
@@ -19,7 +16,7 @@ use crate::{ActiveEffects, Attributes, FluidOnEyes, Physics};
1916/// to your mining speed.
2017pub fn get_mine_progress (
2118 block : & dyn BlockTrait ,
22- held_item : ItemKind ,
19+ held_item : & ItemStack ,
2320 fluid_on_eyes : & FluidOnEyes ,
2421 physics : & Physics ,
2522 attributes : & Attributes ,
@@ -45,34 +42,26 @@ pub fn get_mine_progress(
4542 attributes,
4643 active_effects,
4744 ) ;
48- ( base_destroy_speed / destroy_time) / divisor as f32
45+ ( base_destroy_speed / destroy_time) / ( divisor as f32 )
4946}
5047
51- fn has_correct_tool_for_drops ( block : & dyn BlockTrait , tool : ItemKind ) -> bool {
48+ fn has_correct_tool_for_drops ( block : & dyn BlockTrait , item : & ItemStack ) -> bool {
5249 if !block. behavior ( ) . requires_correct_tool_for_drops {
5350 return true ;
5451 }
52+ let Some ( tool) = item. get_component :: < Tool > ( ) else {
53+ return false ;
54+ } ;
5555 let registry_block = block. as_registry_block ( ) ;
56- if tool == ItemKind :: Shears {
57- matches ! (
58- registry_block,
59- BlockKind :: Cobweb | BlockKind :: RedstoneWire | BlockKind :: Tripwire
60- )
61- } else if tags:: items:: SWORDS . contains ( & tool) {
62- registry_block == BlockKind :: Cobweb
63- } else if tags:: items:: PICKAXES . contains ( & tool)
64- || tags:: items:: SHOVELS . contains ( & tool)
65- || tags:: items:: HOES . contains ( & tool)
66- || tags:: items:: AXES . contains ( & tool)
67- {
68- let tier = get_item_tier ( tool) . expect ( "all pickaxes and shovels should be matched" ) ;
69- let tier_level = tier. level ( ) ;
70- !( ( tier_level < 3 && tags:: blocks:: NEEDS_DIAMOND_TOOL . contains ( & registry_block) )
71- || ( tier_level < 2 && tags:: blocks:: NEEDS_IRON_TOOL . contains ( & registry_block) )
72- || ( tier_level < 1 && tags:: blocks:: NEEDS_STONE_TOOL . contains ( & registry_block) ) )
73- } else {
74- false
56+ for rule in & tool. rules {
57+ if let Some ( correct) = rule. correct_for_drops
58+ && rule. blocks . contains ( registry_block)
59+ {
60+ return correct;
61+ }
7562 }
63+
64+ false
7665}
7766
7867/// Returns the destroy speed of the given block with the given tool, taking
@@ -82,21 +71,21 @@ fn has_correct_tool_for_drops(block: &dyn BlockTrait, tool: ItemKind) -> bool {
8271/// `ItemKind::Air`.
8372fn destroy_speed (
8473 block : BlockKind ,
85- tool : ItemKind ,
74+ tool : & ItemStack ,
8675 _fluid_on_eyes : & FluidOnEyes ,
8776 physics : & Physics ,
8877 attributes : & Attributes ,
8978 active_effects : & ActiveEffects ,
9079) -> f32 {
91- let mut base_destroy_speed = base_destroy_speed ( block, tool) ;
80+ let mut speed = base_destroy_speed ( block, tool) ;
9281
93- if base_destroy_speed > 1. {
82+ if speed > 1. {
9483 // efficiency enchantment
95- base_destroy_speed += attributes. mining_efficiency . calculate ( ) as f32 ;
84+ speed += attributes. mining_efficiency . calculate ( ) as f32 ;
9685 }
9786
9887 if let Some ( dig_speed_amplifier) = active_effects. get_dig_speed_amplifier ( ) {
99- base_destroy_speed *= 1. + ( dig_speed_amplifier + 1 ) as f32 * 0.2 ;
88+ speed *= 1. + ( dig_speed_amplifier + 1 ) as f32 * 0.2 ;
10089 }
10190
10291 if let Some ( dig_slowdown) = active_effects. get_level ( MobEffect :: MiningFatigue ) {
@@ -106,9 +95,11 @@ fn destroy_speed(
10695 2 => 0.0027 ,
10796 _ => 8.1E-4 ,
10897 } ;
109- base_destroy_speed *= multiplier;
98+ speed *= multiplier;
11099 }
111100
101+ speed *= attributes. block_break_speed . calculate ( ) as f32 ;
102+
112103 // TODO
113104 // if **fluid_on_eyes == FluidKind::Water
114105 // && enchantments::get_enchant_level(registry::Enchantment::AquaAffinity,
@@ -118,56 +109,21 @@ fn destroy_speed(
118109 // }
119110
120111 if !physics. on_ground {
121- base_destroy_speed /= 5. ;
112+ speed /= 5. ;
122113 }
123114
124- base_destroy_speed
115+ speed
125116}
126117
127- fn base_destroy_speed ( block : BlockKind , tool : ItemKind ) -> f32 {
128- if tool == ItemKind :: Shears {
129- if block == BlockKind :: Cobweb || tags:: blocks:: LEAVES . contains ( & block) {
130- 15.
131- } else if tags:: blocks:: WOOL . contains ( & block) {
132- 5.
133- } else if matches ! ( block, BlockKind :: Vine | BlockKind :: GlowLichen ) {
134- 2.
135- } else {
136- 1.
137- }
138- } else if tags:: items:: SWORDS . contains ( & tool) {
139- if block == BlockKind :: Cobweb {
140- 15.
141- } else if tags:: blocks:: SWORD_EFFICIENT . contains ( & block) {
142- 1.5
143- } else {
144- 1.
118+ fn base_destroy_speed ( block : BlockKind , item : & ItemStack ) -> f32 {
119+ let tool = item. get_component :: < Tool > ( ) ;
120+ let Some ( tool) = tool else { return 1. } ;
121+ for rule in & tool. rules {
122+ if let Some ( speed) = rule. speed
123+ && rule. blocks . contains ( block)
124+ {
125+ return speed;
145126 }
146- } else if tags:: items:: PICKAXES . contains ( & tool) {
147- if tags:: blocks:: MINEABLE_PICKAXE . contains ( & block) {
148- get_item_tier ( tool) . unwrap ( ) . speed ( )
149- } else {
150- 1.
151- }
152- } else if tags:: items:: SHOVELS . contains ( & tool) {
153- if tags:: blocks:: MINEABLE_SHOVEL . contains ( & block) {
154- get_item_tier ( tool) . unwrap ( ) . speed ( )
155- } else {
156- 1.
157- }
158- } else if tags:: items:: HOES . contains ( & tool) {
159- if tags:: blocks:: MINEABLE_HOE . contains ( & block) {
160- get_item_tier ( tool) . unwrap ( ) . speed ( )
161- } else {
162- 1.
163- }
164- } else if tags:: items:: AXES . contains ( & tool) {
165- if tags:: blocks:: MINEABLE_AXE . contains ( & block) {
166- get_item_tier ( tool) . unwrap ( ) . speed ( )
167- } else {
168- 1.
169- }
170- } else {
171- 1.
172127 }
128+ tool. default_mining_speed
173129}
0 commit comments