Skip to content

Commit 615d5e0

Browse files
committed
Merge branch 'master' into fix/fixing-broken-shit
# Conflicts: # scripts/new_packet.py # src/lib/net/src/utils/broadcast.rs
2 parents 12ba493 + 2d60101 commit 615d5e0

File tree

9 files changed

+92
-0
lines changed

9 files changed

+92
-0
lines changed
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
}

src/bin/src/packet_handlers/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
mod animations;
12
mod handshake;
23
mod login_process;
34
mod tick_handler;

src/lib/net/crates/codec/src/decode/primitives.rs

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ impl_for_primitives!(
3535
u32 | i32,
3636
u64 | i64,
3737
u128 | i128,
38+
usize | isize,
3839
f32,
3940
f64
4041
);

src/lib/net/crates/codec/src/encode/primitives.rs

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ impl_for_primitives!(
4040
u32 | i32,
4141
u64 | i64,
4242
u128 | i128,
43+
usize | isize,
4344
f32,
4445
f64
4546
);

src/lib/net/src/packets/incoming/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ pub mod packet_skeleton;
1414
pub mod set_player_position;
1515
pub mod set_player_position_and_rotation;
1616
pub mod set_player_rotation;
17+
18+
pub mod swing_arm;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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 numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
}

src/lib/net/src/packets/outgoing/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ pub mod set_render_distance;
1717
pub mod status_response;
1818
pub mod synchronize_player_position;
1919
pub mod update_time;
20+
21+
pub mod entity_animation;

src/lib/net/src/utils/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
pub mod broadcast;
2+
23
pub mod ecs_helpers;
34
pub mod state;

0 commit comments

Comments
 (0)