11use crate :: dungeon:: dungeon:: Dungeon ;
22use crate :: dungeon:: dungeon_player:: DungeonPlayer ;
3- use bevy_ecs:: entity:: Entity ;
43use bevy_ecs:: prelude:: Component ;
5- use bevy_ecs:: query:: With ;
64use glam:: { ivec3, DVec3 } ;
75use server:: block:: Block ;
86use server:: constants:: { EntityVariant , ObjectVariant } ;
@@ -18,28 +16,20 @@ use server::{Player, World};
1816pub struct DoorBehaviour ;
1917
2018impl EntityBehaviour < Dungeon > for DoorBehaviour {
19+ fn tick ( entity : & mut MinecraftEntity < Dungeon > , _: & mut Self ) {
20+ entity. position . y -= 0.25 ;
2121
22- fn tick ( _: & mut MinecraftEntity < Dungeon > , _: & mut Self ) { }
22+ if entity. ticks_existed == 20 {
23+ let world = entity. world_mut ( ) ;
24+ let x = entity. position . x as i32 ;
25+ let z = entity. position . z as i32 ;
2326
24- fn query ( world : & mut bevy_ecs:: prelude:: World ) {
25- // need entity(id) from query,
26- // without using macro IDK if there's a good way to define a nicer query with traits ,
27- let mut query = world. query_filtered :: < ( Entity , & mut MinecraftEntity < Dungeon > ) , With < DoorBehaviour > > ( ) ;
28- for ( entity_id, mut entity) in query. iter_mut ( world) {
29- entity. position . y -= 0.25 ;
30-
31- if entity. ticks_existed == 20 {
32- let world = entity. world_mut ( ) ;
33- let x = entity. position . x as i32 ;
34- let z = entity. position . z as i32 ;
35-
36- world. chunk_grid . fill_blocks (
37- Block :: Air ,
38- ivec3 ( x, 69 , z) ,
39- ivec3 ( x + 2 , 72 , z + 2 ) ,
40- ) ;
41- world. remove_entity ( entity_id) ;
42- }
27+ world. chunk_grid . fill_blocks (
28+ Block :: Air ,
29+ ivec3 ( x, 69 , z) ,
30+ ivec3 ( x + 2 , 72 , z + 2 ) ,
31+ ) ;
32+ entity. destroy ( )
4333 }
4434 }
4535}
0 commit comments