@@ -9,7 +9,7 @@ use flecs_ecs::{
9
9
prelude:: Module ,
10
10
} ;
11
11
use hyperion:: {
12
- BlockKind ,
12
+ BlockKind , chat ,
13
13
net:: { Compose , NetworkStreamRef , agnostic} ,
14
14
simulation:: {
15
15
Xp ,
@@ -43,6 +43,16 @@ pub struct SetLevel {
43
43
pub stage : u8 ,
44
44
}
45
45
46
+ impl SetLevel {
47
+ pub fn new ( position : IVec3 , stage : u8 ) -> Self {
48
+ Self {
49
+ position,
50
+ sequence : fastrand:: i32 ( ..) ,
51
+ stage,
52
+ }
53
+ }
54
+ }
55
+
46
56
pub struct DestroyValue {
47
57
pub position : IVec3 ,
48
58
pub from : Entity ,
@@ -239,45 +249,58 @@ impl Module for BlockModule {
239
249
}
240
250
} ) ;
241
251
242
- system ! ( "handle_placed_blocks" , world, & mut Blocks ( $) , & mut EventQueue <event:: PlaceBlock >( $) , & mut PendingDestruction ( $) )
243
- . each_iter ( move |it, _, ( mc, event_queue, pending_air) : ( & mut Blocks , & mut EventQueue < event:: PlaceBlock > , & mut PendingDestruction ) | {
252
+ system ! ( "handle_placed_blocks" , world, & mut Blocks ( $) , & mut EventQueue <event:: PlaceBlock >( $) , & mut PendingDestruction ( $) , & Compose ( $ ) )
253
+ . each_iter ( move |it, _, ( mc, event_queue, pending_air, compose ) : ( & mut Blocks , & mut EventQueue < event:: PlaceBlock > , & mut PendingDestruction , & Compose ) | {
244
254
let world = it. world ( ) ;
245
255
let span = info_span ! ( "handle_placed_blocks" ) ;
246
256
let _enter = span. enter ( ) ;
247
- for event in event_queue. drain ( ) {
248
- let position = event. position ;
257
+ for event:: PlaceBlock { position, block, from, sequence } in event_queue. drain ( ) {
258
+ if block. collision_shapes ( ) . is_empty ( ) {
259
+ mc. to_confirm . push ( EntityAndSequence :: new ( from, sequence) ) ;
249
260
250
- mc. set_block ( position, event. block ) . unwrap ( ) ;
261
+ from. entity_view ( world) . get :: < ( & mut PlayerInventory , & NetworkStreamRef ) > ( |( inventory, stream) | {
262
+ // so we send update to player
263
+ let _ = inventory. get_cursor_mut ( ) ;
251
264
252
- event. from . entity_view ( world) . get :: < & mut MainBlockCount > ( |main_block_count| {
265
+ let msg = chat ! ( "§cYou can't place this block" ) ;
266
+
267
+ compose. unicast ( & msg, * stream, SystemId ( 8 ) , & world) . unwrap ( ) ;
268
+ } ) ;
269
+
270
+ continue ;
271
+ }
272
+
273
+ mc. set_block ( position, block) . unwrap ( ) ;
274
+
275
+ from. entity_view ( world) . get :: < & mut PlayerInventory > ( |inventory| {
276
+ inventory. take_one_held ( ) ;
277
+ } ) ;
278
+
279
+ from. entity_view ( world) . get :: < & mut MainBlockCount > ( |main_block_count| {
253
280
* * main_block_count = ( * * main_block_count - 1 ) . max ( 0 ) ;
254
281
} ) ;
255
282
256
283
let destroy = DestroyValue {
257
284
position,
258
- from : event . from ,
285
+ from,
259
286
} ;
260
287
288
+
261
289
pending_air. destroy_at . schedule ( Instant :: now ( ) + TOTAL_DESTRUCTION_TIME , destroy) ;
262
290
263
291
{
264
- let sequence = fastrand:: i32 ( ..) ;
265
292
// Schedule destruction stages 0 through 9
266
293
for stage in 0_u8 ..=10 { // 10 represents no animation
267
294
let delay = TOTAL_DESTRUCTION_TIME / 10 * u32:: from ( stage) ;
268
295
pending_air. set_level_at . schedule (
269
296
Instant :: now ( ) + delay,
270
- SetLevel {
271
- position,
272
- sequence,
273
- stage,
274
- } ,
297
+ SetLevel :: new ( position, stage) ,
275
298
) ;
276
299
}
277
300
}
278
301
mc. to_confirm . push ( EntityAndSequence {
279
- entity : event . from ,
280
- sequence : event . sequence ,
302
+ entity : from,
303
+ sequence,
281
304
} ) ;
282
305
}
283
306
} ) ;
0 commit comments