mirror of
https://github.com/italicsjenga/valence.git
synced 2024-12-23 22:41:30 +11:00
Fix entity create/delete bugs
This commit is contained in:
parent
6c0eef1ae7
commit
c4590a45fc
|
@ -9,8 +9,8 @@ use num::Integer;
|
||||||
use rayon::iter::{IndexedParallelIterator, IntoParallelRefMutIterator, ParallelIterator};
|
use rayon::iter::{IndexedParallelIterator, IntoParallelRefMutIterator, ParallelIterator};
|
||||||
use valence::client::{ClientEvent, ClientId, GameMode};
|
use valence::client::{ClientEvent, ClientId, GameMode};
|
||||||
use valence::config::{Config, ServerListPing};
|
use valence::config::{Config, ServerListPing};
|
||||||
use valence::entity::EntityMeta;
|
|
||||||
use valence::entity::meta::Pose;
|
use valence::entity::meta::Pose;
|
||||||
|
use valence::entity::EntityMeta;
|
||||||
use valence::text::Color;
|
use valence::text::Color;
|
||||||
use valence::{
|
use valence::{
|
||||||
async_trait, ident, Biome, BlockState, Dimension, DimensionId, EntityId, EntityType, Server,
|
async_trait, ident, Biome, BlockState, Dimension, DimensionId, EntityId, EntityType, Server,
|
||||||
|
@ -118,12 +118,6 @@ impl Config for Game {
|
||||||
|
|
||||||
server.clients.retain(|client_id, client| {
|
server.clients.retain(|client_id, client| {
|
||||||
if client.created_tick() == server.shared.current_tick() {
|
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
|
if self
|
||||||
.player_count
|
.player_count
|
||||||
.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |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());
|
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
|
true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -108,6 +108,7 @@ impl Config for Game {
|
||||||
|
|
||||||
if client.is_disconnected() {
|
if client.is_disconnected() {
|
||||||
self.player_count.fetch_sub(1, Ordering::SeqCst);
|
self.player_count.fetch_sub(1, Ordering::SeqCst);
|
||||||
|
world.meta.player_list_mut().remove(client.uuid());
|
||||||
false
|
false
|
||||||
} else {
|
} else {
|
||||||
true
|
true
|
||||||
|
|
|
@ -80,11 +80,6 @@ impl Config for Game {
|
||||||
let mut chunks_to_unload = HashSet::<_>::from_iter(world.chunks.iter().map(|t| t.0));
|
let mut chunks_to_unload = HashSet::<_>::from_iter(world.chunks.iter().map(|t| t.0));
|
||||||
|
|
||||||
server.clients.retain(|_, client| {
|
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 client.created_tick() == server.shared.current_tick() {
|
||||||
if self
|
if self
|
||||||
.player_count
|
.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 dist = client.view_distance();
|
||||||
let p = client.position();
|
let p = client.position();
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ pub use types::{EntityMeta, EntityType};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
use vek::{Aabb, Vec3};
|
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::{
|
use crate::protocol::packets::play::s2c::{
|
||||||
AddEntity, AddExperienceOrb, AddPlayer, S2cPlayPacket, SetEntityMetadata,
|
AddEntity, AddExperienceOrb, AddPlayer, S2cPlayPacket, SetEntityMetadata,
|
||||||
};
|
};
|
||||||
|
@ -70,6 +70,9 @@ impl Entities {
|
||||||
events: Vec::new(),
|
events: Vec::new(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// TODO check for overflowing version?
|
||||||
|
self.network_id_to_entity.insert(k.version(), k.index());
|
||||||
|
|
||||||
ve.insert(EntityId(k));
|
ve.insert(EntityId(k));
|
||||||
|
|
||||||
Some((EntityId(k), e))
|
Some((EntityId(k), e))
|
||||||
|
|
|
@ -56,7 +56,6 @@ impl Key {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unused)]
|
|
||||||
pub fn index(self) -> u32 {
|
pub fn index(self) -> u32 {
|
||||||
self.index
|
self.index
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue