File tree Expand file tree Collapse file tree 9 files changed +92
-0
lines changed Expand file tree Collapse file tree 9 files changed +92
-0
lines changed Original file line number Diff line number Diff line change
1
+ use ferrumc_macros:: event_handler;
2
+ use ferrumc_net:: errors:: NetError ;
3
+ use ferrumc_net:: packets:: outgoing:: entity_animation:: EntityAnimationEvent ;
4
+ use ferrumc_net:: utils:: broadcast:: { broadcast, BroadcastOptions } ;
5
+ use ferrumc_state:: GlobalState ;
6
+
7
+ #[ event_handler]
8
+ async fn entity_animation (
9
+ event : EntityAnimationEvent ,
10
+ state : GlobalState ,
11
+ ) -> Result < EntityAnimationEvent , NetError > {
12
+ //TODO change this global broadcast to a broadcast that affects only players in the view distance
13
+ // of the player doing it, but as long as we still cant see other players, this will be fine.
14
+ broadcast (
15
+ & event. packet ,
16
+ & state,
17
+ BroadcastOptions :: default ( ) . except ( [ event. entity ] ) ,
18
+ )
19
+ . await ?;
20
+ Ok ( event)
21
+ }
Original file line number Diff line number Diff line change
1
+ mod animations;
1
2
mod handshake;
2
3
mod login_process;
3
4
mod tick_handler;
Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ impl_for_primitives!(
35
35
u32 | i32 ,
36
36
u64 | i64 ,
37
37
u128 | i128 ,
38
+ usize | isize ,
38
39
f32 ,
39
40
f64
40
41
) ;
Original file line number Diff line number Diff line change @@ -40,6 +40,7 @@ impl_for_primitives!(
40
40
u32 | i32 ,
41
41
u64 | i64 ,
42
42
u128 | i128 ,
43
+ usize | isize ,
43
44
f32 ,
44
45
f64
45
46
) ;
Original file line number Diff line number Diff line change @@ -14,3 +14,5 @@ pub mod packet_skeleton;
14
14
pub mod set_player_position;
15
15
pub mod set_player_position_and_rotation;
16
16
pub mod set_player_rotation;
17
+
18
+ pub mod swing_arm;
Original file line number Diff line number Diff line change
1
+ use crate :: packets:: outgoing:: entity_animation:: EntityAnimationEvent ;
2
+ use crate :: packets:: IncomingPacket ;
3
+ use crate :: NetResult ;
4
+ use ferrumc_ecs:: entities:: Entity ;
5
+ use ferrumc_events:: infrastructure:: Event ;
6
+ use ferrumc_macros:: { packet, NetDecode } ;
7
+ use ferrumc_net_codec:: net_types:: var_int:: VarInt ;
8
+ use ferrumc_state:: ServerState ;
9
+ use std:: sync:: Arc ;
10
+
11
+ #[ derive( NetDecode ) ]
12
+ #[ packet( packet_id = 0x36 , state = "play" ) ]
13
+ pub struct SwingArmPacket {
14
+ hand : VarInt ,
15
+ }
16
+
17
+ impl IncomingPacket for SwingArmPacket {
18
+ async fn handle ( self , conn_id : Entity , state : Arc < ServerState > ) -> NetResult < ( ) > {
19
+ let animation = {
20
+ if self . hand == 0 {
21
+ 0
22
+ } else {
23
+ 3
24
+ }
25
+ } ;
26
+ let event = EntityAnimationEvent :: new ( conn_id, animation) ;
27
+ EntityAnimationEvent :: trigger ( event, state) . await ?;
28
+ Ok ( ( ) )
29
+ }
30
+ }
Original file line number Diff line number Diff line change
1
+ use ferrumc_ecs:: entities:: Entity ;
2
+ use ferrumc_macros:: { packet, Event , NetEncode } ;
3
+ use std:: io:: Write ;
4
+
5
+ #[ derive( NetEncode ) ]
6
+ #[ packet( packet_id = 0x03 ) ]
7
+ pub struct EntityAnimationPacket {
8
+ pub eid : Entity ,
9
+ pub animation : u8 ,
10
+ }
11
+
12
+ #[ derive( Event ) ]
13
+ pub struct EntityAnimationEvent {
14
+ pub entity : Entity ,
15
+ pub animation : u8 ,
16
+ pub packet : EntityAnimationPacket ,
17
+ }
18
+
19
+ impl EntityAnimationPacket {
20
+ pub fn new ( eid : Entity , animation : u8 ) -> Self {
21
+ Self { eid, animation }
22
+ }
23
+ }
24
+
25
+ impl EntityAnimationEvent {
26
+ pub fn new ( eid : Entity , animation : u8 ) -> Self {
27
+ Self {
28
+ entity : eid,
29
+ animation,
30
+ packet : EntityAnimationPacket :: new ( eid, animation) ,
31
+ }
32
+ }
33
+ }
Original file line number Diff line number Diff line change @@ -17,3 +17,5 @@ pub mod set_render_distance;
17
17
pub mod status_response;
18
18
pub mod synchronize_player_position;
19
19
pub mod update_time;
20
+
21
+ pub mod entity_animation;
Original file line number Diff line number Diff line change 1
1
pub mod broadcast;
2
+
2
3
pub mod ecs_helpers;
3
4
pub mod state;
You can’t perform that action at this time.
0 commit comments