@@ -4,7 +4,7 @@ use std::{
4
4
} ;
5
5
6
6
use flecs_ecs:: {
7
- core:: { EntityViewGet , QueryBuilderImpl , SystemAPI , TableIter , TermBuilderImpl , World } ,
7
+ core:: { Entity , EntityViewGet , QueryBuilderImpl , SystemAPI , TableIter , TermBuilderImpl , World } ,
8
8
macros:: { Component , system} ,
9
9
prelude:: Module ,
10
10
} ;
@@ -27,6 +27,8 @@ use hyperion::{
27
27
text:: IntoText ,
28
28
} ,
29
29
} ;
30
+ use hyperion_inventory:: PlayerInventory ;
31
+ use hyperion_rank_tree:: inventory;
30
32
use hyperion_scheduled:: Scheduled ;
31
33
use tracing:: { error, info_span} ;
32
34
@@ -41,9 +43,14 @@ pub struct SetLevel {
41
43
pub stage : u8 ,
42
44
}
43
45
46
+ pub struct DestroyValue {
47
+ pub position : IVec3 ,
48
+ pub from : Entity ,
49
+ }
50
+
44
51
#[ derive( Default , Component ) ]
45
52
pub struct PendingDestruction {
46
- pub destroy_at : Scheduled < Instant , IVec3 > ,
53
+ pub destroy_at : Scheduled < Instant , DestroyValue > ,
47
54
pub set_level_at : Scheduled < Instant , SetLevel > ,
48
55
}
49
56
@@ -56,6 +63,7 @@ impl Module for BlockModule {
56
63
world. set ( PendingDestruction :: default ( ) ) ;
57
64
58
65
system ! ( "handle_pending_air" , world, & mut PendingDestruction ( $) , & mut Blocks ( $) , & Compose ( $) )
66
+ . write :: < PlayerInventory > ( )
59
67
. multi_threaded ( )
60
68
. each_iter (
61
69
move |it : TableIter < ' _ , false > ,
@@ -87,9 +95,9 @@ impl Module for BlockModule {
87
95
. send ( & world)
88
96
. unwrap ( ) ;
89
97
}
90
- for position in pending_air. destroy_at . pop_until ( & now) {
98
+ for destroy in pending_air. destroy_at . pop_until ( & now) {
91
99
// Play particle effect for block destruction
92
- let center_block = position. as_dvec3 ( ) + DVec3 :: splat ( 0.5 ) ;
100
+ let center_block = destroy . position . as_dvec3 ( ) + DVec3 :: splat ( 0.5 ) ;
93
101
94
102
let particle_packet = play:: ParticleS2c {
95
103
particle : Cow :: Owned ( Particle :: Explosion ) ,
@@ -116,7 +124,18 @@ impl Module for BlockModule {
116
124
. send ( & world)
117
125
. unwrap ( ) ;
118
126
119
- blocks. set_block ( position, BlockState :: AIR ) . unwrap ( ) ;
127
+ destroy. from
128
+ . entity_view ( world)
129
+ . get :: < & mut PlayerInventory > ( |inventory| {
130
+ let stack = inventory
131
+ . get_hand_slot_mut ( inventory:: BLOCK_SLOT )
132
+ . unwrap ( ) ;
133
+
134
+ stack. count = stack. count . saturating_add ( 1 ) ;
135
+ } ) ;
136
+
137
+
138
+ blocks. set_block ( destroy. position , BlockState :: AIR ) . unwrap ( ) ;
120
139
}
121
140
} ,
122
141
) ;
@@ -186,7 +205,6 @@ impl Module for BlockModule {
186
205
} ;
187
206
188
207
189
-
190
208
let from = event. from ;
191
209
let from_entity = world. entity_from_id ( from) ;
192
210
from_entity. get :: < ( & NetworkStreamRef , & mut Xp ) > ( |( & net, xp) | {
@@ -220,7 +238,6 @@ impl Module for BlockModule {
220
238
} ) ;
221
239
222
240
system ! ( "handle_placed_blocks" , world, & mut Blocks ( $) , & mut EventQueue <event:: PlaceBlock >( $) , & mut PendingDestruction ( $) )
223
- . multi_threaded ( )
224
241
. each ( move |( mc, event_queue, pending_air) : ( & mut Blocks , & mut EventQueue < event:: PlaceBlock > , & mut PendingDestruction ) | {
225
242
let span = info_span ! ( "handle_placed_blocks" ) ;
226
243
let _enter = span. enter ( ) ;
@@ -229,7 +246,12 @@ impl Module for BlockModule {
229
246
230
247
mc. set_block ( position, event. block ) . unwrap ( ) ;
231
248
232
- pending_air. destroy_at . schedule ( Instant :: now ( ) + TOTAL_DESTRUCTION_TIME , position) ;
249
+ let destroy = DestroyValue {
250
+ position,
251
+ from : event. from ,
252
+ } ;
253
+
254
+ pending_air. destroy_at . schedule ( Instant :: now ( ) + TOTAL_DESTRUCTION_TIME , destroy) ;
233
255
234
256
{
235
257
let sequence = fastrand:: i32 ( ..) ;
0 commit comments