From 12118ebfa3f8165c345c98596957b25a156c8b74 Mon Sep 17 00:00:00 2001 From: mat Date: Sat, 26 Aug 2023 22:19:10 -0500 Subject: use better pathfinder costs and also fix relative entity updates breaking sometimes --- azalea-entity/src/plugin/indexing.rs | 2 +- azalea-entity/src/plugin/mod.rs | 1 - azalea-entity/src/plugin/relative_updates.rs | 34 +++++++++------------------- 3 files changed, 12 insertions(+), 25 deletions(-) (limited to 'azalea-entity/src/plugin') diff --git a/azalea-entity/src/plugin/indexing.rs b/azalea-entity/src/plugin/indexing.rs index be5c0a5b..507e6737 100644 --- a/azalea-entity/src/plugin/indexing.rs +++ b/azalea-entity/src/plugin/indexing.rs @@ -290,7 +290,7 @@ pub fn remove_despawned_entities_from_indexes( warn!("Tried to remove entity from chunk {chunk:?} but the entity was not there."); } } else { - warn!("Tried to remove entity from chunk {chunk:?} but the chunk was not found."); + debug!("Tried to remove entity from chunk {chunk:?} but the chunk was not found."); } // remove it from the uuid index if entity_infos.entity_by_uuid.remove(uuid).is_none() { diff --git a/azalea-entity/src/plugin/mod.rs b/azalea-entity/src/plugin/mod.rs index 41ec4e6a..94e8e79d 100644 --- a/azalea-entity/src/plugin/mod.rs +++ b/azalea-entity/src/plugin/mod.rs @@ -59,7 +59,6 @@ impl Plugin for EntityPlugin { ) .in_set(EntityUpdateSet::Index), ( - relative_updates::add_updates_received, relative_updates::debug_detect_updates_received_on_local_entities, debug_new_entity, add_dead, diff --git a/azalea-entity/src/plugin/relative_updates.rs b/azalea-entity/src/plugin/relative_updates.rs index 7d01feda..21b57cff 100644 --- a/azalea-entity/src/plugin/relative_updates.rs +++ b/azalea-entity/src/plugin/relative_updates.rs @@ -20,8 +20,8 @@ use std::sync::Arc; use azalea_world::{MinecraftEntityId, PartialInstance}; use bevy_ecs::{ prelude::{Component, Entity}, - query::{Changed, With, Without}, - system::{Commands, EntityCommand, Query}, + query::With, + system::{EntityCommand, Query}, world::{EntityMut, World}, }; use derive_more::{Deref, DerefMut}; @@ -69,24 +69,29 @@ impl EntityCommand for RelativeEntityUpdate { }; let entity_id = *entity_mut.get::().unwrap(); - let Some(updates_received) = entity_mut.get_mut::() else { + if entity_mut.contains::() { // a client tried to update another client, which isn't allowed return; - }; + } let this_client_updates_received = partial_entity_infos .updates_received .get(&entity_id) .copied(); - let can_update = this_client_updates_received.unwrap_or(1) == **updates_received; + let can_update = if let Some(updates_received) = entity_mut.get::() { + this_client_updates_received.unwrap_or(1) == **updates_received + } else { + // no UpdatesReceived means the entity was just spawned + true + }; if can_update { let new_updates_received = this_client_updates_received.unwrap_or(0) + 1; partial_entity_infos .updates_received .insert(entity_id, new_updates_received); - **entity_mut.get_mut::().unwrap() = new_updates_received; + entity_mut.insert(UpdatesReceived(new_updates_received)); let mut entity = world.entity_mut(entity); (self.update)(&mut entity); @@ -94,23 +99,6 @@ impl EntityCommand for RelativeEntityUpdate { } } -#[allow(clippy::type_complexity)] -pub fn add_updates_received( - mut commands: Commands, - query: Query< - Entity, - ( - Changed, - (Without, Without), - ), - >, -) { - for entity in query.iter() { - // entities always start with 1 update received - commands.entity(entity).insert(UpdatesReceived(1)); - } -} - /// The [`UpdatesReceived`] component should never be on [`Local`] entities. /// This warns if an entity has both components. pub fn debug_detect_updates_received_on_local_entities( -- cgit v1.2.3