@@ -2,8 +2,8 @@ use crate::constants::EntityVariant;
22use crate :: entity:: entity:: EntityBase ;
33use crate :: entity:: entity_metadata:: { EntityMetadata , PlayerMetadata } ;
44use crate :: network:: binary:: var_int:: VarInt ;
5+ use crate :: network:: packets:: packet_buffer:: PacketBuffer ;
56use crate :: network:: protocol:: play:: clientbound:: { DestroyEntites , EntityRotate , EntityTeleport , EntityYawRotate , PlayerData , PlayerListItem , SpawnMob , SpawnPlayer } ;
6- use crate :: world:: chunk:: get_chunk_position;
77use crate :: { GameProfile , GameProfileProperty , Player , WorldExtension } ;
88use fstr:: FString ;
99use std:: collections:: HashMap ;
@@ -18,9 +18,9 @@ pub trait EntityAppearance<W: WorldExtension> {
1818
1919 fn leave_player_view ( & self , entity : & mut EntityBase < W > , player : & mut Player < W :: Player > ) ;
2020
21- fn update_position ( & self , entity : & mut EntityBase < W > ) ;
21+ fn update_position ( & self , entity : & mut EntityBase < W > , chunk_buffer : & mut PacketBuffer ) ;
2222
23- fn update_rotation ( & self , entity : & mut EntityBase < W > ) ;
23+ fn update_rotation ( & self , entity : & mut EntityBase < W > , chunk_buffer : & mut PacketBuffer ) ;
2424}
2525
2626pub struct MobAppearance {
@@ -62,35 +62,29 @@ impl<W: WorldExtension> EntityAppearance<W> for MobAppearance {
6262 } )
6363 }
6464
65- fn update_position ( & self , entity : & mut EntityBase < W > ) {
66- let ( chunk_x, chunk_z) = get_chunk_position ( entity. position ) ;
67- if let Some ( chunk) = entity. world_mut ( ) . chunk_grid . get_chunk_mut ( chunk_x, chunk_z) {
68- chunk. packet_buffer . write_packet ( & EntityTeleport {
69- entity_id : entity. id ,
70- pos_x : entity. position . x ,
71- pos_y : entity. position . y ,
72- pos_z : entity. position . z ,
73- yaw : entity. yaw ,
74- pitch : entity. pitch ,
75- on_ground : false ,
76- } )
77- }
65+ fn update_position ( & self , entity : & mut EntityBase < W > , packet_buffer : & mut PacketBuffer ) {
66+ packet_buffer. write_packet ( & EntityTeleport {
67+ entity_id : entity. id ,
68+ pos_x : entity. position . x ,
69+ pos_y : entity. position . y ,
70+ pos_z : entity. position . z ,
71+ yaw : entity. yaw ,
72+ pitch : entity. pitch ,
73+ on_ground : false ,
74+ } )
7875 }
7976
80- fn update_rotation ( & self , entity : & mut EntityBase < W > ) {
81- let ( chunk_x, chunk_z) = get_chunk_position ( entity. position ) ;
82- if let Some ( chunk) = entity. world_mut ( ) . chunk_grid . get_chunk_mut ( chunk_x, chunk_z) {
83- chunk. packet_buffer . write_packet ( & EntityRotate {
84- entity_id : entity. id ,
85- yaw : entity. yaw ,
86- pitch : entity. pitch ,
87- on_ground : false ,
88- } ) ;
89- chunk. packet_buffer . write_packet ( & EntityYawRotate {
90- entity_id : entity. id ,
91- yaw : entity. yaw ,
92- } ) ;
93- }
77+ fn update_rotation ( & self , entity : & mut EntityBase < W > , packet_buffer : & mut PacketBuffer ) {
78+ packet_buffer. write_packet ( & EntityRotate {
79+ entity_id : entity. id ,
80+ yaw : entity. yaw ,
81+ pitch : entity. pitch ,
82+ on_ground : false ,
83+ } ) ;
84+ packet_buffer. write_packet ( & EntityYawRotate {
85+ entity_id : entity. id ,
86+ yaw : entity. yaw ,
87+ } ) ;
9488 }
9589}
9690
@@ -112,6 +106,7 @@ impl PlayerAppearance {
112106
113107impl < W : WorldExtension > EntityAppearance < W > for PlayerAppearance {
114108 fn initialize ( & self , _: & mut EntityBase < W > ) { }
109+
115110 fn destroy ( & self , entity : & mut EntityBase < W > , packet : & mut DestroyEntites ) {
116111 packet. entities . push ( VarInt ( entity. id ) )
117112 }
@@ -161,34 +156,28 @@ impl<W: WorldExtension> EntityAppearance<W> for PlayerAppearance {
161156 } )
162157 }
163158
164- fn update_position ( & self , entity : & mut EntityBase < W > ) {
165- let ( chunk_x, chunk_z) = get_chunk_position ( entity. position ) ;
166- if let Some ( chunk) = entity. world_mut ( ) . chunk_grid . get_chunk_mut ( chunk_x, chunk_z) {
167- chunk. packet_buffer . write_packet ( & EntityTeleport {
168- entity_id : entity. id ,
169- pos_x : entity. position . x ,
170- pos_y : entity. position . y ,
171- pos_z : entity. position . z ,
172- yaw : entity. yaw ,
173- pitch : entity. pitch ,
174- on_ground : false ,
175- } )
176- }
159+ fn update_position ( & self , entity : & mut EntityBase < W > , packet_buffer : & mut PacketBuffer ) {
160+ packet_buffer. write_packet ( & EntityTeleport {
161+ entity_id : entity. id ,
162+ pos_x : entity. position . x ,
163+ pos_y : entity. position . y ,
164+ pos_z : entity. position . z ,
165+ yaw : entity. yaw ,
166+ pitch : entity. pitch ,
167+ on_ground : false ,
168+ } )
177169 }
178170
179- fn update_rotation ( & self , entity : & mut EntityBase < W > ) {
180- let ( chunk_x, chunk_z) = get_chunk_position ( entity. position ) ;
181- if let Some ( chunk) = entity. world_mut ( ) . chunk_grid . get_chunk_mut ( chunk_x, chunk_z) {
182- chunk. packet_buffer . write_packet ( & EntityRotate {
183- entity_id : entity. id ,
184- yaw : entity. yaw ,
185- pitch : entity. pitch ,
186- on_ground : false ,
187- } ) ;
188- chunk. packet_buffer . write_packet ( & EntityYawRotate {
189- entity_id : entity. id ,
190- yaw : entity. yaw ,
191- } ) ;
192- }
171+ fn update_rotation ( & self , entity : & mut EntityBase < W > , packet_buffer : & mut PacketBuffer ) {
172+ packet_buffer. write_packet ( & EntityRotate {
173+ entity_id : entity. id ,
174+ yaw : entity. yaw ,
175+ pitch : entity. pitch ,
176+ on_ground : false ,
177+ } ) ;
178+ packet_buffer. write_packet ( & EntityYawRotate {
179+ entity_id : entity. id ,
180+ yaw : entity. yaw ,
181+ } ) ;
193182 }
194183}
0 commit comments