Fix entity create/delete bugs

This commit is contained in:
Ryan 2022-07-04 16:30:37 -07:00
parent 6c0eef1ae7
commit c4590a45fc
5 changed files with 20 additions and 14 deletions

View file

@ -9,8 +9,8 @@ use num::Integer;
use rayon::iter::{IndexedParallelIterator, IntoParallelRefMutIterator, ParallelIterator};
use valence::client::{ClientEvent, ClientId, GameMode};
use valence::config::{Config, ServerListPing};
use valence::entity::EntityMeta;
use valence::entity::meta::Pose;
use valence::entity::EntityMeta;
use valence::text::Color;
use valence::{
async_trait, ident, Biome, BlockState, Dimension, DimensionId, EntityId, EntityType, Server,
@ -118,12 +118,6 @@ impl Config for Game {
server.clients.retain(|client_id, client| {
if client.created_tick() == server.shared.current_tick() {
if client.is_disconnected() {
self.player_count.fetch_sub(1, Ordering::SeqCst);
player_entities.remove(&client_id);
return false;
}
if self
.player_count
.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |count| {
@ -161,6 +155,14 @@ impl Config for Game {
client.send_message("Hold the left mouse button to bring blocks to life.".italic());
}
if client.is_disconnected() {
self.player_count.fetch_sub(1, Ordering::SeqCst);
let id = player_entities.remove(&client_id).unwrap();
server.entities.delete(id);
world.meta.player_list_mut().remove(client.uuid());
return false;
}
true
});

View file

@ -108,6 +108,7 @@ impl Config for Game {
if client.is_disconnected() {
self.player_count.fetch_sub(1, Ordering::SeqCst);
world.meta.player_list_mut().remove(client.uuid());
false
} else {
true

View file

@ -80,11 +80,6 @@ impl Config for Game {
let mut chunks_to_unload = HashSet::<_>::from_iter(world.chunks.iter().map(|t| t.0));
server.clients.retain(|_, client| {
if client.is_disconnected() {
self.player_count.fetch_sub(1, Ordering::SeqCst);
return false;
}
if client.created_tick() == server.shared.current_tick() {
if self
.player_count
@ -118,6 +113,12 @@ impl Config for Game {
);
}
if client.is_disconnected() {
self.player_count.fetch_sub(1, Ordering::SeqCst);
world.meta.player_list_mut().remove(client.uuid());
return false;
}
let dist = client.view_distance();
let p = client.position();

View file

@ -12,7 +12,7 @@ pub use types::{EntityMeta, EntityType};
use uuid::Uuid;
use vek::{Aabb, Vec3};
pub use crate::protocol::packets::play::s2c::EntityEvent as EntityEvent;
pub use crate::protocol::packets::play::s2c::EntityEvent;
use crate::protocol::packets::play::s2c::{
AddEntity, AddExperienceOrb, AddPlayer, S2cPlayPacket, SetEntityMetadata,
};
@ -70,6 +70,9 @@ impl Entities {
events: Vec::new(),
});
// TODO check for overflowing version?
self.network_id_to_entity.insert(k.version(), k.index());
ve.insert(EntityId(k));
Some((EntityId(k), e))

View file

@ -56,7 +56,6 @@ impl Key {
}
}
#[allow(unused)]
pub fn index(self) -> u32 {
self.index
}