aboutsummaryrefslogtreecommitdiff
path: root/azalea-entity/src
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2025-06-09 17:15:07 +0900
committermat <git@matdoes.dev>2025-06-09 17:15:07 +0900
commit4a4de819616d620d15680e71fb32390e28ab07cd (patch)
tree9bd1159dec3527b07651d0d9c78f96c95d115e7b /azalea-entity/src
parent45d73712746fbfd365e8a68a75dfad6ae2e0d174 (diff)
downloadazalea-drasl-4a4de819616d620d15680e71fb32390e28ab07cd.tar.xz
handle relative teleports correctly and fix entity chunk indexing warnings
Diffstat (limited to 'azalea-entity/src')
-rw-r--r--azalea-entity/src/plugin/indexing.rs36
-rw-r--r--azalea-entity/src/plugin/mod.rs5
-rw-r--r--azalea-entity/src/vec_delta_codec.rs8
3 files changed, 32 insertions, 17 deletions
diff --git a/azalea-entity/src/plugin/indexing.rs b/azalea-entity/src/plugin/indexing.rs
index 2fc89e84..f1926286 100644
--- a/azalea-entity/src/plugin/indexing.rs
+++ b/azalea-entity/src/plugin/indexing.rs
@@ -132,16 +132,17 @@ pub fn update_entity_chunk_positions(
instance_container: Res<InstanceContainer>,
) {
for (entity, pos, instance_name, mut entity_chunk_pos) in query.iter_mut() {
- // TODO: move this inside of the if statement so it's not called as often
- let instance_lock = instance_container.get(instance_name).unwrap();
- let mut instance = instance_lock.write();
-
let old_chunk = **entity_chunk_pos;
let new_chunk = ChunkPos::from(*pos);
if old_chunk != new_chunk {
**entity_chunk_pos = new_chunk;
if old_chunk != new_chunk {
+ let Some(instance_lock) = instance_container.get(instance_name) else {
+ continue;
+ };
+ let mut instance = instance_lock.write();
+
// move the entity from the old chunk to the new one
if let Some(entities) = instance.entities_by_chunk.get_mut(&old_chunk) {
entities.remove(&entity);
@@ -163,7 +164,10 @@ pub fn insert_entity_chunk_position(
instance_container: Res<InstanceContainer>,
) {
for (entity, pos, world_name) in query.iter() {
- let instance_lock = instance_container.get(world_name).unwrap();
+ let Some(instance_lock) = instance_container.get(world_name) else {
+ // entity must've been despawned already
+ continue;
+ };
let mut instance = instance_lock.write();
let chunk = ChunkPos::from(*pos);
@@ -213,13 +217,13 @@ pub fn remove_despawned_entities_from_indexes(
let mut instance = instance_lock.write();
- // if the entity has no references left, despawn it
+ // if the entity is being loaded by any of our clients, don't despawn it
if !loaded_by.is_empty() {
continue;
}
// remove the entity from the chunk index
- let chunk = ChunkPos::from(*position);
+ let chunk = ChunkPos::from(position);
match instance.entities_by_chunk.get_mut(&chunk) {
Some(entities_in_chunk) => {
if entities_in_chunk.remove(&entity) {
@@ -247,9 +251,21 @@ pub fn remove_despawned_entities_from_indexes(
}
}
_ => {
- debug!(
- "Tried to remove entity {entity:?} from chunk {chunk:?} but the chunk was not found."
- );
+ let mut found_in_other_chunks = HashSet::new();
+ for (other_chunk, entities_in_other_chunk) in &mut instance.entities_by_chunk {
+ if entities_in_other_chunk.remove(&entity) {
+ found_in_other_chunks.insert(other_chunk);
+ }
+ }
+ if found_in_other_chunks.is_empty() {
+ warn!(
+ "Tried to remove entity {entity:?} from chunk {chunk:?} but the chunk was not found and the entity wasn't in any other chunks."
+ );
+ } else {
+ warn!(
+ "Tried to remove entity {entity:?} from chunk {chunk:?} but the chunk was not found. Entity found in and removed from other chunk(s): {found_in_other_chunks:?}"
+ );
+ }
}
}
// remove it from the uuid index
diff --git a/azalea-entity/src/plugin/mod.rs b/azalea-entity/src/plugin/mod.rs
index 6a6c9615..03afe7cd 100644
--- a/azalea-entity/src/plugin/mod.rs
+++ b/azalea-entity/src/plugin/mod.rs
@@ -46,11 +46,6 @@ impl Plugin for EntityPlugin {
Update,
(
(
- // remove_despawned_entities_from_indexes is done again here to correctly
- // handle the case where an entity is spawned and then the world is removed at
- // the same time (like with ClientboundStartConfiguration).
- indexing::remove_despawned_entities_from_indexes
- .in_set(EntityUpdateSet::Deindex),
indexing::update_entity_chunk_positions,
indexing::insert_entity_chunk_position,
)
diff --git a/azalea-entity/src/vec_delta_codec.rs b/azalea-entity/src/vec_delta_codec.rs
index 51aa7cea..270daff2 100644
--- a/azalea-entity/src/vec_delta_codec.rs
+++ b/azalea-entity/src/vec_delta_codec.rs
@@ -1,4 +1,4 @@
-use azalea_core::position::Vec3;
+use azalea_core::{delta::PositionDelta8, position::Vec3};
#[derive(Debug, Clone, Default)]
pub struct VecDeltaCodec {
@@ -10,7 +10,11 @@ impl VecDeltaCodec {
Self { base }
}
- pub fn decode(&self, x: i64, y: i64, z: i64) -> Vec3 {
+ pub fn decode(&self, delta: &PositionDelta8) -> Vec3 {
+ let x = delta.xa as i64;
+ let y = delta.ya as i64;
+ let z = delta.za as i64;
+
if x == 0 && y == 0 && z == 0 {
return self.base;
}