aboutsummaryrefslogtreecommitdiff
path: root/azalea-client/src
diff options
context:
space:
mode:
Diffstat (limited to 'azalea-client/src')
-rw-r--r--azalea-client/src/lib.rs1
-rw-r--r--azalea-client/src/plugins/chat/handler.rs2
-rw-r--r--azalea-client/src/plugins/packet/config/events.rs4
-rw-r--r--azalea-client/src/plugins/packet/config/mod.rs4
-rw-r--r--azalea-client/src/plugins/packet/game/mod.rs70
-rw-r--r--azalea-client/src/test_simulation.rs21
6 files changed, 55 insertions, 47 deletions
diff --git a/azalea-client/src/lib.rs b/azalea-client/src/lib.rs
index d2302b78..bcea00bc 100644
--- a/azalea-client/src/lib.rs
+++ b/azalea-client/src/lib.rs
@@ -6,6 +6,7 @@
//! [`azalea`]: https://docs.rs/azalea
#![feature(error_generic_member_access)]
+#![feature(never_type)]
mod account;
mod client;
diff --git a/azalea-client/src/plugins/chat/handler.rs b/azalea-client/src/plugins/chat/handler.rs
index d598acdb..be99b667 100644
--- a/azalea-client/src/plugins/chat/handler.rs
+++ b/azalea-client/src/plugins/chat/handler.rs
@@ -1,8 +1,8 @@
use std::time::{SystemTime, UNIX_EPOCH};
use azalea_protocol::packets::{
- game::{s_chat::LastSeenMessagesUpdate, ServerboundChat, ServerboundChatCommand},
Packet,
+ game::{ServerboundChat, ServerboundChatCommand, s_chat::LastSeenMessagesUpdate},
};
use bevy_ecs::prelude::*;
diff --git a/azalea-client/src/plugins/packet/config/events.rs b/azalea-client/src/plugins/packet/config/events.rs
index 6b647d74..a9b2179a 100644
--- a/azalea-client/src/plugins/packet/config/events.rs
+++ b/azalea-client/src/plugins/packet/config/events.rs
@@ -2,15 +2,15 @@ use std::io::Cursor;
use azalea_protocol::{
packets::{
- config::{ClientboundConfigPacket, ServerboundConfigPacket},
Packet,
+ config::{ClientboundConfigPacket, ServerboundConfigPacket},
},
read::deserialize_packet,
};
use bevy_ecs::prelude::*;
use tracing::{debug, error};
-use crate::{raw_connection::RawConnection, InConfigState};
+use crate::{InConfigState, raw_connection::RawConnection};
#[derive(Event, Debug, Clone)]
pub struct ReceiveConfigPacketEvent {
diff --git a/azalea-client/src/plugins/packet/config/mod.rs b/azalea-client/src/plugins/packet/config/mod.rs
index 5cb19b9d..2e0ce354 100644
--- a/azalea-client/src/plugins/packet/config/mod.rs
+++ b/azalea-client/src/plugins/packet/config/mod.rs
@@ -1,7 +1,7 @@
mod events;
-use azalea_protocol::packets::config::*;
use azalea_protocol::packets::ConnectionProtocol;
+use azalea_protocol::packets::config::*;
use bevy_ecs::prelude::*;
use bevy_ecs::system::SystemState;
pub use events::*;
@@ -12,7 +12,7 @@ use crate::client::InConfigState;
use crate::disconnect::DisconnectEvent;
use crate::packet::game::KeepAliveEvent;
use crate::raw_connection::RawConnection;
-use crate::{declare_packet_handlers, InstanceHolder};
+use crate::{InstanceHolder, declare_packet_handlers};
pub fn process_packet_events(ecs: &mut World) {
let mut events_owned = Vec::new();
diff --git a/azalea-client/src/plugins/packet/game/mod.rs b/azalea-client/src/plugins/packet/game/mod.rs
index 98f76d13..5f3e125f 100644
--- a/azalea-client/src/plugins/packet/game/mod.rs
+++ b/azalea-client/src/plugins/packet/game/mod.rs
@@ -752,9 +752,9 @@ impl GamePacketHandler<'_> {
// we use RelativeEntityUpdate because it makes sure changes aren't made
// multiple times
- commands.entity(entity).queue(RelativeEntityUpdate {
- partial_world: instance_holder.partial_instance.clone(),
- update: Box::new(move |entity| {
+ commands.entity(entity).queue(RelativeEntityUpdate::new(
+ instance_holder.partial_instance.clone(),
+ move |entity| {
let entity_id = entity.id();
entity.world_scope(|world| {
let mut commands_system_state = SystemState::<Commands>::new(world);
@@ -767,8 +767,8 @@ impl GamePacketHandler<'_> {
}
commands_system_state.apply(world);
});
- }),
- });
+ },
+ ));
});
}
@@ -805,14 +805,14 @@ impl GamePacketHandler<'_> {
z: p.delta.za as f64 / 8000.,
});
- commands.entity(entity).queue(RelativeEntityUpdate {
- partial_world: instance_holder.partial_instance.clone(),
- update: Box::new(move |entity_mut| {
+ commands.entity(entity).queue(RelativeEntityUpdate::new(
+ instance_holder.partial_instance.clone(),
+ move |entity_mut| {
entity_mut.world_scope(|world| {
world.send_event(KnockbackEvent { entity, knockback })
});
- }),
- });
+ },
+ ));
},
);
}
@@ -868,9 +868,9 @@ impl GamePacketHandler<'_> {
x_rot: (p.change.look_direction.x_rot as i32 * 360) as f32 / 256.,
y_rot: (p.change.look_direction.y_rot as i32 * 360) as f32 / 256.,
};
- commands.entity(entity).queue(RelativeEntityUpdate {
- partial_world: instance_holder.partial_instance.clone(),
- update: Box::new(move |entity| {
+ commands.entity(entity).queue(RelativeEntityUpdate::new(
+ instance_holder.partial_instance.clone(),
+ move |entity| {
let mut position = entity.get_mut::<Position>().unwrap();
if new_pos != **position {
**position = new_pos;
@@ -883,8 +883,8 @@ impl GamePacketHandler<'_> {
// old_pos is set to the current position when we're teleported
let mut physics = entity.get_mut::<Physics>().unwrap();
physics.set_old_pos(&position);
- }),
- });
+ },
+ ));
},
);
}
@@ -913,9 +913,9 @@ impl GamePacketHandler<'_> {
let new_delta = p.delta.clone();
let new_on_ground = p.on_ground;
- commands.entity(entity).queue(RelativeEntityUpdate {
- partial_world: instance_holder.partial_instance.clone(),
- update: Box::new(move |entity_mut| {
+ commands.entity(entity).queue(RelativeEntityUpdate::new(
+ instance_holder.partial_instance.clone(),
+ move |entity_mut| {
let mut physics = entity_mut.get_mut::<Physics>().unwrap();
let new_pos = physics.vec_delta_codec.decode(
new_delta.xa as i64,
@@ -929,8 +929,8 @@ impl GamePacketHandler<'_> {
if new_pos != **position {
**position = new_pos;
}
- }),
- });
+ },
+ ));
},
);
}
@@ -962,9 +962,9 @@ impl GamePacketHandler<'_> {
let new_on_ground = p.on_ground;
- commands.entity(entity).queue(RelativeEntityUpdate {
- partial_world: instance_holder.partial_instance.clone(),
- update: Box::new(move |entity_mut| {
+ commands.entity(entity).queue(RelativeEntityUpdate::new(
+ instance_holder.partial_instance.clone(),
+ move |entity_mut| {
let mut physics = entity_mut.get_mut::<Physics>().unwrap();
let new_pos = physics.vec_delta_codec.decode(
new_delta.xa as i64,
@@ -983,8 +983,8 @@ impl GamePacketHandler<'_> {
if new_look_direction != *look_direction {
*look_direction = new_look_direction;
}
- }),
- });
+ },
+ ));
},
);
}
@@ -1003,9 +1003,9 @@ impl GamePacketHandler<'_> {
};
let new_on_ground = p.on_ground;
- commands.entity(entity).queue(RelativeEntityUpdate {
- partial_world: instance_holder.partial_instance.clone(),
- update: Box::new(move |entity_mut| {
+ commands.entity(entity).queue(RelativeEntityUpdate::new(
+ instance_holder.partial_instance.clone(),
+ move |entity_mut| {
let mut physics = entity_mut.get_mut::<Physics>().unwrap();
physics.set_on_ground(new_on_ground);
@@ -1013,8 +1013,8 @@ impl GamePacketHandler<'_> {
if new_look_direction != *look_direction {
*look_direction = new_look_direction;
}
- }),
- });
+ },
+ ));
} else {
warn!(
"Got move entity rot packet for unknown entity id {}",
@@ -1507,9 +1507,9 @@ impl GamePacketHandler<'_> {
let new_on_ground = p.on_ground;
let new_look_direction = p.values.look_direction;
- commands.entity(entity).queue(RelativeEntityUpdate {
- partial_world: instance_holder.partial_instance.clone(),
- update: Box::new(move |entity_mut| {
+ commands.entity(entity).queue(RelativeEntityUpdate::new(
+ instance_holder.partial_instance.clone(),
+ move |entity_mut| {
let is_local_entity = entity_mut.get::<LocalEntity>().is_some();
let mut physics = entity_mut.get_mut::<Physics>().unwrap();
@@ -1530,8 +1530,8 @@ impl GamePacketHandler<'_> {
let mut look_direction = entity_mut.get_mut::<LookDirection>().unwrap();
*look_direction = new_look_direction;
- }),
- });
+ },
+ ));
},
);
}
diff --git a/azalea-client/src/test_simulation.rs b/azalea-client/src/test_simulation.rs
index 2479e953..27cf4a57 100644
--- a/azalea-client/src/test_simulation.rs
+++ b/azalea-client/src/test_simulation.rs
@@ -21,6 +21,7 @@ use bevy_app::App;
use bevy_ecs::{prelude::*, schedule::ExecutorKind};
use parking_lot::{Mutex, RwLock};
use simdnbt::owned::Nbt;
+use tokio::task::JoinHandle;
use tokio::{sync::mpsc, time::sleep};
use uuid::Uuid;
@@ -39,14 +40,14 @@ pub struct Simulation {
pub rt: tokio::runtime::Runtime,
pub incoming_packet_queue: Arc<Mutex<Vec<Box<[u8]>>>>,
- pub outgoing_packets_receiver: mpsc::UnboundedReceiver<Box<[u8]>>,
+ pub clear_outgoing_packets_receiver_task: JoinHandle<!>,
}
impl Simulation {
pub fn new(initial_connection_protocol: ConnectionProtocol) -> Self {
let mut app = create_simulation_app();
let mut entity = app.world_mut().spawn_empty();
- let (player, outgoing_packets_receiver, incoming_packet_queue, rt) =
+ let (player, clear_outgoing_packets_receiver_task, incoming_packet_queue, rt) =
create_local_player_bundle(entity.id(), initial_connection_protocol);
entity.insert(player);
@@ -68,7 +69,7 @@ impl Simulation {
entity,
rt,
incoming_packet_queue,
- outgoing_packets_receiver,
+ clear_outgoing_packets_receiver_task,
}
}
@@ -105,14 +106,14 @@ fn create_local_player_bundle(
connection_protocol: ConnectionProtocol,
) -> (
LocalPlayerBundle,
- mpsc::UnboundedReceiver<Box<[u8]>>,
+ JoinHandle<!>,
Arc<Mutex<Vec<Box<[u8]>>>>,
tokio::runtime::Runtime,
) {
// unused since we'll trigger ticks ourselves
- let (run_schedule_sender, _run_schedule_receiver) = tokio::sync::mpsc::unbounded_channel();
+ let (run_schedule_sender, _run_schedule_receiver) = mpsc::unbounded_channel();
- let (outgoing_packets_sender, outgoing_packets_receiver) = mpsc::unbounded_channel();
+ let (outgoing_packets_sender, mut outgoing_packets_receiver) = mpsc::unbounded_channel();
let incoming_packet_queue = Arc::new(Mutex::new(Vec::new()));
let reader = RawConnectionReader {
incoming_packet_queue: incoming_packet_queue.clone(),
@@ -136,6 +137,12 @@ fn create_local_player_bundle(
}
});
+ let clear_outgoing_packets_receiver_task = rt.spawn(async move {
+ loop {
+ let _ = outgoing_packets_receiver.recv().await;
+ }
+ });
+
let raw_connection = RawConnection {
reader,
writer,
@@ -160,7 +167,7 @@ fn create_local_player_bundle(
(
local_player_bundle,
- outgoing_packets_receiver,
+ clear_outgoing_packets_receiver_task,
incoming_packet_queue,
rt,
)