Skip to content

Commit 6be7be4

Browse files
committed
fixed leave_view not working
1 parent 746d32a commit 6be7be4

File tree

3 files changed

+11
-17
lines changed

3 files changed

+11
-17
lines changed

server/src/entity/entity.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ impl<W : WorldExtension> Entity<W> {
108108
}
109109

110110
pub fn leave_view(&mut self, player: &mut Player<W::Player>) {
111-
self.appearance.enter_player_view(&mut self.base, player);
111+
self.appearance.leave_player_view(&mut self.base, player);
112112
}
113113

114114
pub fn destroy(&mut self, packet: &mut DestroyEntites) {

server/src/entity/entity_appearance.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ impl<W: WorldExtension> EntityAppearance<W> for PlayerAppearance {
150150
entity_id: entity.id,
151151
yaw: entity.yaw,
152152
});
153-
player.test(
153+
player.add_delayed_profile_remove(
154154
self.uuid
155155
)
156156
}

server/src/player/player.rs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use crate::world::world::VIEW_DISTANCE;
2020
use crate::world::world::{World, WorldExtension};
2121
use fstr::FString;
2222
use glam::{dvec3, DVec3, IVec3, Vec3};
23-
use std::collections::{HashMap, HashSet};
23+
use std::collections::HashMap;
2424
use std::f32::consts::PI;
2525
use std::ptr::NonNull;
2626
use uuid::Uuid;
@@ -166,29 +166,25 @@ impl<E : PlayerExtension> Player<E> {
166166
accepted: false,
167167
});
168168

169-
let mut to_remove = HashSet::new();
170-
171-
for (uuid, ticks) in self.npc_profiles_for_removal.iter_mut() {
172-
// println!("ticks {ticks}");
173-
*ticks -= 1;
174-
if *ticks == 0 {
169+
self.npc_profiles_for_removal.retain(|k, v| {
170+
*v -= 1;
171+
if *v == 0 {
175172
self.packet_buffer.write_packet(&PlayerListItem {
176173
action: VarInt(4),
177174
players: &[PlayerData {
178175
ping: 0,
179176
game_mode: 0,
180177
profile: &GameProfile {
181-
uuid: *uuid,
178+
uuid: *k,
182179
username: FString::EMPTY,
183180
properties: HashMap::new(),
184181
},
185182
display_name: None,
186183
}]
187184
});
188-
to_remove.insert(*uuid);
189-
}
190-
}
191-
self.npc_profiles_for_removal.retain(|uuid, _| !to_remove.contains(uuid));
185+
};
186+
*v != 0
187+
});
192188

193189
// tick extension
194190
E::tick(self);
@@ -312,9 +308,7 @@ impl<E : PlayerExtension> Player<E> {
312308
Vec3::new(yaw_sin * -pitch_cos, pitch_sin, yaw_cos * -pitch_cos)
313309
}
314310

315-
pub (crate) fn test(&mut self, uuid: Uuid) {
316-
// 20 ticks should be a good amount
317-
println!("inserted");
311+
pub(crate) fn add_delayed_profile_remove(&mut self, uuid: Uuid) {
318312
self.npc_profiles_for_removal.insert(uuid, 40);
319313
}
320314
}

0 commit comments

Comments
 (0)