1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 14:26:04 +00:00

fix entities not being despawned

closes #103
This commit is contained in:
mat 2023-08-22 01:56:56 -05:00
parent 47a280212a
commit 07e3236f0b
2 changed files with 28 additions and 4 deletions

View file

@ -830,6 +830,33 @@ pub fn process_packet_events(ecs: &mut World) {
} }
ClientboundGamePacket::RemoveEntities(p) => { ClientboundGamePacket::RemoveEntities(p) => {
debug!("Got remove entities packet {:?}", p); debug!("Got remove entities packet {:?}", p);
let mut system_state: SystemState<(
Commands,
Query<&mut InstanceName>,
Res<InstanceContainer>,
)> = SystemState::new(ecs);
let (mut commands, mut query, instance_container) = system_state.get_mut(ecs);
let Ok(instance_name) = query.get_mut(player_entity) else {
println!("no instance name");
continue;
};
let Some(instance) = instance_container.get(&instance_name) else {
println!("no instance");
continue;
};
for &id in &p.entity_ids {
if let Some(entity) =
instance.write().entity_by_id.remove(&MinecraftEntityId(id))
{
println!("despawning entity");
commands.entity(entity).despawn();
}
}
system_state.apply(ecs);
} }
ClientboundGamePacket::PlayerChat(p) => { ClientboundGamePacket::PlayerChat(p) => {
debug!("Got player chat packet {:?}", p); debug!("Got player chat packet {:?}", p);

View file

@ -64,10 +64,7 @@ fn log_nearby_item_drops(
let item_drop = item_drops.get(entity).unwrap(); let item_drop = item_drops.get(entity).unwrap();
let kind = item_drop.kind(); let kind = item_drop.kind();
println!( println!("Bot {bot_id:?} can see an {kind:?} {distance:.1} meters away.");
"Bot {:?} can see an {:?} {:.1} meters away.",
bot_id, kind, distance
);
} }
} }
} }