Don't load entities with the same UUID as the client

This commit is contained in:
Ryan 2022-07-04 00:48:21 -07:00
parent 0d07b3659f
commit 4aca4e24a7
3 changed files with 12 additions and 12 deletions

View file

@ -962,8 +962,13 @@ impl Client {
world.spatial_index.query::<_, _, ()>(
|bb| bb.projected_point(pos).distance(pos) <= view_dist as f64 * 16.0,
|id, _| {
let entity = entities.get(id).unwrap();
if entity.typ() != EntityType::Marker && self.loaded_entities.insert(id) {
let entity = entities
.get(id)
.expect("entities in spatial index should be valid");
if entity.typ() != EntityType::Marker
&& entity.uuid() != self.uuid
&& self.loaded_entities.insert(id)
{
self.send_packet(
entity
.spawn_packet(id)

View file

@ -310,6 +310,10 @@ impl Entity {
self.flags.set_on_ground(on_ground);
}
pub fn uuid(&self) -> Uuid {
self.uuid
}
pub fn push_event(&mut self, event: EntityEvent) {
self.events.push(event);
}

View file

@ -426,16 +426,7 @@ fn join_player(server: &mut Server, msg: NewClientMessage) {
let client = Client::new(c2s_packet_channels, &server.shared, msg.ncd);
if server.entities.get_with_uuid(client.uuid()).is_none() {
server.clients.insert(client);
} else {
log::warn!(
"client '{}' cannot join the server because their UUID ({}) conflicts with an \
existing entity",
client.username(),
client.uuid()
);
}
}
struct Codec {