aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--azalea-client/src/events.rs2
-rw-r--r--azalea-client/src/local_player.rs4
-rw-r--r--azalea-client/src/packet_handling/game.rs51
-rw-r--r--azalea/examples/testbot.rs2
-rw-r--r--azalea/src/container.rs2
5 files changed, 30 insertions, 31 deletions
diff --git a/azalea-client/src/events.rs b/azalea-client/src/events.rs
index 46c0189a..e5e30b6a 100644
--- a/azalea-client/src/events.rs
+++ b/azalea-client/src/events.rs
@@ -165,7 +165,7 @@ fn packet_listener(query: Query<&LocalPlayerEvents>, mut events: EventReader<Pac
.get(event.entity)
.expect("Non-local entities shouldn't be able to receive add player events");
local_player_events
- .send(Event::Packet(Arc::new(event.packet.clone())))
+ .send(Event::Packet(event.packet.clone()))
.unwrap();
}
}
diff --git a/azalea-client/src/local_player.rs b/azalea-client/src/local_player.rs
index e49a81fe..ac0e4ea1 100644
--- a/azalea-client/src/local_player.rs
+++ b/azalea-client/src/local_player.rs
@@ -68,8 +68,8 @@ pub struct PlayerAbilities {
/// Used for the fov
pub walking_speed: f32,
}
-impl From<ClientboundPlayerAbilitiesPacket> for PlayerAbilities {
- fn from(packet: ClientboundPlayerAbilitiesPacket) -> Self {
+impl From<&ClientboundPlayerAbilitiesPacket> for PlayerAbilities {
+ fn from(packet: &ClientboundPlayerAbilitiesPacket) -> Self {
Self {
invulnerable: packet.flags.invulnerable,
flying: packet.flags.flying,
diff --git a/azalea-client/src/packet_handling/game.rs b/azalea-client/src/packet_handling/game.rs
index 8f3b0e99..dad4a555 100644
--- a/azalea-client/src/packet_handling/game.rs
+++ b/azalea-client/src/packet_handling/game.rs
@@ -74,7 +74,7 @@ pub struct PacketEvent {
/// The client entity that received the packet.
pub entity: Entity,
/// The packet that was actually received.
- pub packet: ClientboundGamePacket,
+ pub packet: Arc<ClientboundGamePacket>,
}
/// A player joined the game (or more specifically, was added to the tab
@@ -163,13 +163,10 @@ pub fn send_packet_events(
continue;
}
};
- if let ClientboundGamePacket::LevelChunkWithLight(_) = packet {
- } else {
- packet_events.send(PacketEvent {
- entity: player_entity,
- packet,
- });
- }
+ packet_events.send(PacketEvent {
+ entity: player_entity,
+ packet: Arc::new(packet),
+ });
}
// clear the packets right after we read them
packets.clear();
@@ -190,7 +187,9 @@ pub fn process_packet_events(ecs: &mut World) {
events_owned.push((*player_entity, packet.clone()));
}
for (player_entity, packet) in events_owned {
- match packet {
+ let packet_clone = packet.clone();
+ let packet_ref = packet_clone.as_ref();
+ match packet_ref {
ClientboundGamePacket::Login(p) => {
debug!("Got login packet");
@@ -756,6 +755,8 @@ pub fn process_packet_events(ecs: &mut World) {
};
let entity_kind = *entity_kind_query.get(entity).unwrap();
+ let packed_items = p.packed_items.clone().to_vec();
+
// we use RelativeEntityUpdate because it makes sure changes aren't made
// multiple times
commands.entity(entity).add(RelativeEntityUpdate {
@@ -766,11 +767,9 @@ pub fn process_packet_events(ecs: &mut World) {
let mut commands_system_state = SystemState::<Commands>::new(world);
let mut commands = commands_system_state.get_mut(world);
let mut entity_comands = commands.entity(entity_id);
- if let Err(e) = apply_metadata(
- &mut entity_comands,
- *entity_kind,
- (*p.packed_items).clone(),
- ) {
+ if let Err(e) =
+ apply_metadata(&mut entity_comands, *entity_kind, packed_items)
+ {
warn!("{e}");
}
});
@@ -803,18 +802,18 @@ pub fn process_packet_events(ecs: &mut World) {
// this is to make sure the same entity velocity update doesn't get sent
// multiple times when in swarms
+
+ let knockback = KnockbackType::Set(Vec3 {
+ x: p.xa as f64 / 8000.,
+ y: p.ya as f64 / 8000.,
+ z: p.za as f64 / 8000.,
+ });
+
commands.entity(entity).add(RelativeEntityUpdate {
partial_world: instance_holder.partial_instance.clone(),
update: Box::new(move |entity_mut| {
entity_mut.world_scope(|world| {
- world.send_event(KnockbackEvent {
- entity,
- knockback: KnockbackType::Set(Vec3 {
- x: p.xa as f64 / 8000.,
- y: p.ya as f64 / 8000.,
- z: p.za as f64 / 8000.,
- }),
- })
+ world.send_event(KnockbackEvent { entity, knockback })
});
}),
});
@@ -1226,7 +1225,7 @@ pub fn process_packet_events(ecs: &mut World) {
entity: player_entity,
window_id: p.container_id,
menu_type: p.menu_type,
- title: p.title,
+ title: p.title.to_owned(),
})
}
ClientboundGamePacket::OpenSignEditor(_) => {}
@@ -1281,10 +1280,10 @@ pub fn process_packet_events(ecs: &mut World) {
resource_pack_events.send(ResourcePackEvent {
entity: player_entity,
- url: p.url,
- hash: p.hash,
+ url: p.url.to_owned(),
+ hash: p.hash.to_owned(),
required: p.required,
- prompt: p.prompt,
+ prompt: p.prompt.to_owned(),
});
system_state.apply(ecs);
diff --git a/azalea/examples/testbot.rs b/azalea/examples/testbot.rs
index a7f34a77..38f8d499 100644
--- a/azalea/examples/testbot.rs
+++ b/azalea/examples/testbot.rs
@@ -47,7 +47,7 @@ async fn main() -> anyhow::Result<()> {
let mut accounts = Vec::new();
- for i in 0..200 {
+ for i in 0..3 {
accounts.push(Account::offline(&format!("bot{i}")));
}
diff --git a/azalea/src/container.rs b/azalea/src/container.rs
index 08c60dd9..5406170a 100644
--- a/azalea/src/container.rs
+++ b/azalea/src/container.rs
@@ -180,7 +180,7 @@ pub struct WaitingForInventoryOpen;
fn handle_menu_opened_event(mut commands: Commands, mut events: EventReader<PacketEvent>) {
for event in events.read() {
- if let ClientboundGamePacket::ContainerSetContent { .. } = event.packet {
+ if let ClientboundGamePacket::ContainerSetContent { .. } = event.packet.as_ref() {
commands
.entity(event.entity)
.remove::<WaitingForInventoryOpen>();