Skip to content

Commit 80222cb

Browse files
committed
Fixed a little mishap in primitives.rs that didn't allow for encoding of usize variables.
Changed type of `eid` to be an entity and be consistent with the typing of the rest of the project.
1 parent fe393fa commit 80222cb

File tree

5 files changed

+13
-14
lines changed

5 files changed

+13
-14
lines changed

src/bin/src/packet_handlers/animations.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@ async fn entity_animation(
1111
) -> Result<EntityAnimationEvent, NetError> {
1212
//TODO change this global broadcast to a broadcast that affects only players in the view distance
1313
// of the player doing it, but as long as we still cant see other players, this will be fine.
14-
1514
broadcast(
1615
&event.packet,
1716
&state,
18-
BroadcastOptions::default().except([event.eid.val as usize]),
17+
BroadcastOptions::default().except([event.entity]),
1918
)
2019
.await?;
2120
Ok(event)

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/swing_arm.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use ferrumc_macros::{packet, NetDecode};
66
use ferrumc_net_codec::net_types::var_int::VarInt;
77
use ferrumc_state::ServerState;
88
use std::sync::Arc;
9+
use ferrumc_ecs::entities::Entity;
910

1011
#[derive(NetDecode)]
1112
#[packet(packet_id = 0x36, state = "play")]
@@ -14,15 +15,15 @@ pub struct SwingArmPacket {
1415
}
1516

1617
impl IncomingPacket for SwingArmPacket {
17-
async fn handle(self, conn_id: usize, state: Arc<ServerState>) -> NetResult<()> {
18+
async fn handle(self, conn_id: Entity, state: Arc<ServerState>) -> NetResult<()> {
1819
let animation = {
1920
if self.hand == 0 {
2021
0
2122
} else {
2223
3
2324
}
2425
};
25-
let event = EntityAnimationEvent::new(VarInt::new(conn_id as i32), animation);
26+
let event = EntityAnimationEvent::new(conn_id, animation);
2627
EntityAnimationEvent::trigger(event, state).await?;
2728
Ok(())
2829
}

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

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,31 @@
1-
use crate::errors::NetError;
2-
use crate::utils::broadcast::{broadcast, BroadcastOptions};
3-
use ferrumc_macros::{event_handler, packet, Event, NetEncode};
4-
use ferrumc_net_codec::net_types::var_int::VarInt;
5-
use ferrumc_state::GlobalState;
1+
use ferrumc_macros::{packet, Event, NetEncode};
62
use std::io::Write;
3+
use ferrumc_ecs::entities::Entity;
74

85
#[derive(NetEncode)]
96
#[packet(packet_id = 0x03)]
107
pub struct EntityAnimationPacket {
11-
pub eid: VarInt,
8+
pub eid: Entity,
129
pub animation: u8,
1310
}
1411

1512
#[derive(Event)]
1613
pub struct EntityAnimationEvent {
17-
pub eid: VarInt,
14+
pub entity: Entity,
1815
pub animation: u8,
1916
pub packet: EntityAnimationPacket,
2017
}
2118

2219
impl EntityAnimationPacket {
23-
pub fn new(eid: VarInt, animation: u8) -> Self {
20+
pub fn new(eid: Entity, animation: u8) -> Self {
2421
Self { eid, animation }
2522
}
2623
}
2724

2825
impl EntityAnimationEvent {
29-
pub fn new(eid: VarInt, animation: u8) -> Self {
26+
pub fn new(eid: Entity, animation: u8) -> Self {
3027
Self {
31-
eid: eid.clone(),
28+
entity: eid.clone(),
3229
animation: animation,
3330
packet: EntityAnimationPacket::new(eid, animation.clone()),
3431
}

0 commit comments

Comments
 (0)