@@ -74,7 +74,7 @@ pub struct PacketEvent {
74
74
/// The client entity that received the packet.
75
75
pub entity : Entity ,
76
76
/// The packet that was actually received.
77
- pub packet : ClientboundGamePacket ,
77
+ pub packet : Arc < ClientboundGamePacket > ,
78
78
}
79
79
80
80
/// A player joined the game (or more specifically, was added to the tab
@@ -163,13 +163,10 @@ pub fn send_packet_events(
163
163
continue ;
164
164
}
165
165
} ;
166
- if let ClientboundGamePacket :: LevelChunkWithLight ( _) = packet {
167
- } else {
168
- packet_events. send ( PacketEvent {
169
- entity : player_entity,
170
- packet,
171
- } ) ;
172
- }
166
+ packet_events. send ( PacketEvent {
167
+ entity : player_entity,
168
+ packet : Arc :: new ( packet) ,
169
+ } ) ;
173
170
}
174
171
// clear the packets right after we read them
175
172
packets. clear ( ) ;
@@ -190,7 +187,9 @@ pub fn process_packet_events(ecs: &mut World) {
190
187
events_owned. push ( ( * player_entity, packet. clone ( ) ) ) ;
191
188
}
192
189
for ( player_entity, packet) in events_owned {
193
- match packet {
190
+ let packet_clone = packet. clone ( ) ;
191
+ let packet_ref = packet_clone. as_ref ( ) ;
192
+ match packet_ref {
194
193
ClientboundGamePacket :: Login ( p) => {
195
194
debug ! ( "Got login packet" ) ;
196
195
@@ -756,6 +755,8 @@ pub fn process_packet_events(ecs: &mut World) {
756
755
} ;
757
756
let entity_kind = * entity_kind_query. get ( entity) . unwrap ( ) ;
758
757
758
+ let packed_items = p. packed_items . clone ( ) . to_vec ( ) ;
759
+
759
760
// we use RelativeEntityUpdate because it makes sure changes aren't made
760
761
// multiple times
761
762
commands. entity ( entity) . add ( RelativeEntityUpdate {
@@ -766,11 +767,9 @@ pub fn process_packet_events(ecs: &mut World) {
766
767
let mut commands_system_state = SystemState :: < Commands > :: new ( world) ;
767
768
let mut commands = commands_system_state. get_mut ( world) ;
768
769
let mut entity_comands = commands. entity ( entity_id) ;
769
- if let Err ( e) = apply_metadata (
770
- & mut entity_comands,
771
- * entity_kind,
772
- ( * p. packed_items ) . clone ( ) ,
773
- ) {
770
+ if let Err ( e) =
771
+ apply_metadata ( & mut entity_comands, * entity_kind, packed_items)
772
+ {
774
773
warn ! ( "{e}" ) ;
775
774
}
776
775
} ) ;
@@ -803,18 +802,18 @@ pub fn process_packet_events(ecs: &mut World) {
803
802
804
803
// this is to make sure the same entity velocity update doesn't get sent
805
804
// multiple times when in swarms
805
+
806
+ let knockback = KnockbackType :: Set ( Vec3 {
807
+ x : p. xa as f64 / 8000. ,
808
+ y : p. ya as f64 / 8000. ,
809
+ z : p. za as f64 / 8000. ,
810
+ } ) ;
811
+
806
812
commands. entity ( entity) . add ( RelativeEntityUpdate {
807
813
partial_world : instance_holder. partial_instance . clone ( ) ,
808
814
update : Box :: new ( move |entity_mut| {
809
815
entity_mut. world_scope ( |world| {
810
- world. send_event ( KnockbackEvent {
811
- entity,
812
- knockback : KnockbackType :: Set ( Vec3 {
813
- x : p. xa as f64 / 8000. ,
814
- y : p. ya as f64 / 8000. ,
815
- z : p. za as f64 / 8000. ,
816
- } ) ,
817
- } )
816
+ world. send_event ( KnockbackEvent { entity, knockback } )
818
817
} ) ;
819
818
} ) ,
820
819
} ) ;
@@ -1226,7 +1225,7 @@ pub fn process_packet_events(ecs: &mut World) {
1226
1225
entity : player_entity,
1227
1226
window_id : p. container_id ,
1228
1227
menu_type : p. menu_type ,
1229
- title : p. title ,
1228
+ title : p. title . to_owned ( ) ,
1230
1229
} )
1231
1230
}
1232
1231
ClientboundGamePacket :: OpenSignEditor ( _) => { }
@@ -1281,10 +1280,10 @@ pub fn process_packet_events(ecs: &mut World) {
1281
1280
1282
1281
resource_pack_events. send ( ResourcePackEvent {
1283
1282
entity : player_entity,
1284
- url : p. url ,
1285
- hash : p. hash ,
1283
+ url : p. url . to_owned ( ) ,
1284
+ hash : p. hash . to_owned ( ) ,
1286
1285
required : p. required ,
1287
- prompt : p. prompt ,
1286
+ prompt : p. prompt . to_owned ( ) ,
1288
1287
} ) ;
1289
1288
1290
1289
system_state. apply ( ecs) ;
0 commit comments