22//! range of a player.
33
44use crate :: entity:: movement:: degrees_to_stops;
5- use crate :: entity:: Metadata ;
6- use crate :: entity:: { EntityComponent , EntityType , VelocityComponent } ;
5+ use crate :: entity:: { EntityType , VelocityComponent } ;
6+ use crate :: entity:: { Metadata , NamedComponent , PositionComponent } ;
77use crate :: network:: { send_packet_to_all_players, NetworkComponent } ;
88use crate :: util:: protocol_velocity;
99use feather_core:: network:: packet:: implementation:: SpawnObject ;
@@ -12,6 +12,7 @@ use shrev::EventChannel;
1212use specs:: {
1313 Entities , Entity , Read , ReadStorage , ReaderId , System , SystemData , World , WriteStorage ,
1414} ;
15+ use uuid:: Uuid ;
1516
1617//const ITEM_OBJECT_ID: i8 = 2;
1718
@@ -38,7 +39,8 @@ pub struct EntityBroadcastSystem {
3839
3940impl < ' a > System < ' a > for EntityBroadcastSystem {
4041 type SystemData = (
41- ReadStorage < ' a , EntityComponent > ,
42+ ReadStorage < ' a , PositionComponent > ,
43+ ReadStorage < ' a , NamedComponent > ,
4244 ReadStorage < ' a , NetworkComponent > ,
4345 ReadStorage < ' a , VelocityComponent > ,
4446 WriteStorage < ' a , Metadata > ,
@@ -47,10 +49,10 @@ impl<'a> System<'a> for EntityBroadcastSystem {
4749 ) ;
4850
4951 fn run ( & mut self , data : Self :: SystemData ) {
50- let ( entity_comps , networks, velocities, mut metadatas, events, entities) = data;
52+ let ( positions , nameds , networks, velocities, mut metadatas, events, entities) = data;
5153
5254 for event in events. read ( & mut self . reader . as_mut ( ) . unwrap ( ) ) {
53- let entity = entity_comps . get ( event. entity ) . unwrap ( ) ;
55+ let position = positions . get ( event. entity ) . unwrap ( ) ;
5456 let metadata = metadatas. get_mut ( event. entity ) . unwrap ( ) ;
5557 let velocity = velocities. get ( event. entity ) . cloned ( ) . unwrap_or_default ( ) ;
5658 let ( velocity_x, velocity_y, velocity_z) = protocol_velocity ( * velocity) ;
@@ -62,14 +64,15 @@ impl<'a> System<'a> for EntityBroadcastSystem {
6264 // The Player Info packet was already sent by `JoinBroadcastSystem`.
6365 match event. ty {
6466 EntityType :: Player => {
67+ let named = nameds. get ( event. entity ) . unwrap ( ) ;
6568 let packet = SpawnPlayer {
6669 entity_id : event. entity . id ( ) as i32 ,
67- player_uuid : entity . uuid ,
68- x : entity . position . x ,
69- y : entity . position . y ,
70- z : entity . position . z ,
71- yaw : degrees_to_stops ( entity . position . yaw ) ,
72- pitch : degrees_to_stops ( entity . position . pitch ) ,
70+ player_uuid : named . uuid ,
71+ x : position. current . x ,
72+ y : position. current . y ,
73+ z : position. current . z ,
74+ yaw : degrees_to_stops ( position. current . yaw ) ,
75+ pitch : degrees_to_stops ( position. current . pitch ) ,
7376 metadata : metadata. to_raw_metadata ( ) ,
7477 } ;
7578
@@ -78,13 +81,13 @@ impl<'a> System<'a> for EntityBroadcastSystem {
7881 EntityType :: Item => {
7982 let packet = SpawnObject {
8083 entity_id : event. entity . id ( ) as i32 ,
81- object_uuid : entity . uuid ,
84+ object_uuid : Uuid :: new_v4 ( ) ,
8285 ty : 2 , // Type 2 for item stack
83- x : entity . position . x ,
84- y : entity . position . y ,
85- z : entity . position . z ,
86- pitch : degrees_to_stops ( entity . position . pitch ) ,
87- yaw : degrees_to_stops ( entity . position . yaw ) ,
86+ x : position. current . x ,
87+ y : position. current . y ,
88+ z : position. current . z ,
89+ pitch : degrees_to_stops ( position. current . pitch ) ,
90+ yaw : degrees_to_stops ( position. current . yaw ) ,
8891 data : 1 , // Has velocity
8992 velocity_x,
9093 velocity_y,
0 commit comments