11use crate :: dungeon:: dungeon:: { Dungeon , DungeonState } ;
22use crate :: dungeon:: items:: ability:: { Ability , ActiveAbility , Cooldown } ;
3+ #[ cfg( feature = "dungeon-breaker" ) ]
4+ use crate :: dungeon:: items:: dungeon_breaker:: dungeon_breaker_dig;
35use crate :: dungeon:: items:: dungeon_items:: DungeonItem ;
46use crate :: dungeon:: room:: room:: Room ;
57use chrono:: Local ;
6- #[ cfg( feature = "dungeon_breaker" ) ]
7- use glam:: { dvec3, IVec3 } ;
8+ use glam:: IVec3 ;
89use indoc:: { formatdoc, indoc} ;
9- #[ cfg( feature = "dungeon_breaker" ) ]
10- use server:: block:: blocks:: Blocks ;
1110use server:: constants:: PotionEffect ;
1211use server:: inventory:: item:: get_item_stack;
1312use server:: inventory:: item_stack:: ItemStack ;
1413use server:: network:: protocol:: play:: clientbound:: { AddEffect , BlockChange , Chat } ;
1514use server:: network:: protocol:: play:: serverbound:: PlayerDiggingAction ;
1615use server:: player:: packet_handling:: BlockInteractResult ;
1716use server:: player:: sidebar:: Sidebar ;
18- #[ cfg( feature = "dungeon_breaker" ) ]
19- use server:: types:: aabb:: AABB ;
2017use server:: types:: chat_component:: ChatComponent ;
2118use server:: types:: direction:: Direction ;
2219use server:: { Player , PlayerExtension , World } ;
2320use std:: cell:: { Cell , RefCell } ;
24- #[ cfg( feature = "dungeon_breaker" ) ]
25- use std:: cmp:: min;
2621use std:: collections:: HashMap ;
2722use std:: rc:: Rc ;
2823use std:: time:: { SystemTime , UNIX_EPOCH } ;
@@ -38,10 +33,10 @@ pub struct DungeonPlayer {
3833 pub active_abilities : Cell < Vec < ActiveAbility > > ,
3934 pub cooldowns : HashMap < DungeonItem , Cooldown > ,
4035
41- #[ cfg( feature = "dungeon_breaker " ) ]
36+ #[ cfg( feature = "dungeon-breaker " ) ]
4237 pub pickaxe_charges : usize ,
43- #[ cfg( feature = "dungeon_breaker " ) ]
44- pub broken_blocks : Vec < ( IVec3 , Blocks , usize ) > ,
38+ #[ cfg( feature = "dungeon-breaker " ) ]
39+ pub broken_blocks : Vec < ( IVec3 , server :: block :: blocks :: Blocks , usize ) > ,
4540
4641}
4742
@@ -71,24 +66,24 @@ impl PlayerExtension for DungeonPlayer {
7166 DungeonPlayer :: update_sidebar ( player) ;
7267 }
7368
74- let mut abilities = player. extension . active_abilities . take ( ) ;
69+ let mut abilities = player. active_abilities . take ( ) ;
7570 abilities. retain_mut ( |active| {
7671 active. ticks_active += 1 ;
7772 active. ability . tick ( active. ticks_active , player) ;
7873 active. ticks_active != active. ability . duration ( )
7974 } ) ;
80- player. extension . active_abilities . set ( abilities) ;
75+ player. active_abilities . set ( abilities) ;
8176
82- player. extension . cooldowns . retain ( |_, cooldown| {
77+ player. cooldowns . retain ( |_, cooldown| {
8378 cooldown. ticks_remaining -= 1 ;
8479 cooldown. ticks_remaining != 0
8580 } ) ;
8681
87- #[ cfg( feature = "dungeon_breaker " ) ]
82+ #[ cfg( feature = "dungeon-breaker " ) ]
8883 {
8984 if player. ticks_existed . is_multiple_of ( 20 ) {
9085 if player. extension . pickaxe_charges != 20 {
91- let min = min ( 20 - player. extension . pickaxe_charges , 2 ) ;
86+ let min = std :: cmp :: min ( 20 - player. extension . pickaxe_charges , 2 ) ;
9287 player. extension . pickaxe_charges += min;
9388 }
9489 }
@@ -107,7 +102,7 @@ impl PlayerExtension for DungeonPlayer {
107102
108103 fn dig ( player : & mut Player < Self > , position : IVec3 , action : & PlayerDiggingAction ) {
109104
110- #[ cfg( not( feature = "dungeon_breaker " ) ) ]
105+ #[ cfg( not( feature = "dungeon-breaker " ) ) ]
111106 {
112107 let mut restore_block = false ;
113108 match action {
@@ -136,52 +131,26 @@ impl PlayerExtension for DungeonPlayer {
136131 }
137132 }
138133
139- #[ cfg( feature = "dungeon_breaker " ) ]
134+ #[ cfg( feature = "dungeon-breaker " ) ]
140135 {
141- let world = & mut player. world_mut ( ) ;
142-
143- let can_break = world. has_started ( ) && player. extension . pickaxe_charges != 0 ;
144- if matches ! ( action, PlayerDiggingAction :: StartDestroyBlock ) && can_break {
145-
146- let opened_door = DungeonPlayer :: try_open_door ( player, world, & position) ;
147- let held_slot = player. inventory . get_hotbar_slot ( player. held_slot as usize ) ;
148-
149- if !opened_door && matches ! ( held_slot, Some ( DungeonItem :: Pickaxe ) ) {
150- let chunk_grid = & mut world. chunk_grid ;
151-
152- let block_aabb = AABB :: new (
153- position. as_dvec3 ( ) + dvec3 ( -0.75 , -0.75 , -0.75 ) ,
154- position. as_dvec3 ( ) + dvec3 ( 1.5 , 1.5 , 1.5 ) ,
155- ) ;
156-
157- if let Some ( ( room_rc, _) ) = & player. extension . current_room {
158- let room = room_rc. borrow ( ) ;
159-
160- // check if room doesn't allow, check if overlaps with secrets
161-
162- let mut volume_inside = 0.0 ;
136+ let world = player. world_mut ( ) ;
163137
164- for bounds in room. room_bounds . iter ( ) {
165- volume_inside += block_aabb. intersection_volume ( & bounds. aabb ) ;
166- }
167- // if volume doesn't match, that means the block is likely on the border
168- if block_aabb. volume ( ) == volume_inside {
169- let previous = chunk_grid. get_block_at ( position. x , position. y , position. z ) ;
170- player. extension . broken_blocks . push ( ( position, previous, 200 ) ) ;
171-
172- chunk_grid. set_block_at ( Blocks :: Air , position. x , position. y , position. z ) ;
173- player. extension . pickaxe_charges -= 1 ;
174- return ;
175- }
176- }
177- }
138+ // try open doors with left click before continuing with dungeon breaker
139+ if DungeonPlayer :: try_open_door ( player, world, & position) {
140+ return ;
178141 }
179142
180- let block = world. chunk_grid . get_block_at ( position. x , position. y , position. z ) ;
181- player. write_packet ( & BlockChange {
182- block_pos : position,
183- block_state : block. get_block_state_id ( ) ,
184- } )
143+ if !dungeon_breaker_dig ( player, world, position, action) {
144+ let block = world. chunk_grid . get_block_at (
145+ position. x ,
146+ position. y ,
147+ position. z
148+ ) ;
149+ player. write_packet ( & BlockChange {
150+ block_pos : position,
151+ block_state : block. get_block_state_id ( ) ,
152+ } )
153+ }
185154 }
186155 }
187156
@@ -238,7 +207,7 @@ impl DungeonPlayer {
238207 }
239208
240209 pub fn ready ( player : & mut Player < Self > ) {
241- player. extension . is_ready = !player. extension . is_ready ;
210+ player. is_ready = !player. is_ready ;
242211 Dungeon :: update_ready_status ( player. world_mut ( ) , player) ;
243212 }
244213
@@ -360,15 +329,14 @@ impl DungeonPlayer {
360329 score = "0" ,
361330 } ) ;
362331
363- // if cfg!(feature = "dungeon_breaker") {
364- #[ cfg( feature = "dungeon_breaker " ) ]
365- sidebar. push ( & format ! { r#"
332+ // temp
333+ #[ cfg( feature = "dungeon-breaker " ) ]
334+ sidebar. push ( & formatdoc ! { r#"
366335 charges {charges}
367336
368337 "# ,
369338 charges = player. extension. pickaxe_charges,
370339 } ) ;
371- // }
372340
373341 if world. players . len ( ) == 1 {
374342 sidebar. push ( indoc ! { r#"
0 commit comments