mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 23:44:38 +00:00
make packet an Arc in PacketEvent
This commit is contained in:
parent
e39de79a6b
commit
71cd3f021e
5 changed files with 30 additions and 31 deletions
|
@ -165,7 +165,7 @@ fn packet_listener(query: Query<&LocalPlayerEvents>, mut events: EventReader<Pac
|
||||||
.get(event.entity)
|
.get(event.entity)
|
||||||
.expect("Non-local entities shouldn't be able to receive add player events");
|
.expect("Non-local entities shouldn't be able to receive add player events");
|
||||||
local_player_events
|
local_player_events
|
||||||
.send(Event::Packet(Arc::new(event.packet.clone())))
|
.send(Event::Packet(event.packet.clone()))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,8 +68,8 @@ pub struct PlayerAbilities {
|
||||||
/// Used for the fov
|
/// Used for the fov
|
||||||
pub walking_speed: f32,
|
pub walking_speed: f32,
|
||||||
}
|
}
|
||||||
impl From<ClientboundPlayerAbilitiesPacket> for PlayerAbilities {
|
impl From<&ClientboundPlayerAbilitiesPacket> for PlayerAbilities {
|
||||||
fn from(packet: ClientboundPlayerAbilitiesPacket) -> Self {
|
fn from(packet: &ClientboundPlayerAbilitiesPacket) -> Self {
|
||||||
Self {
|
Self {
|
||||||
invulnerable: packet.flags.invulnerable,
|
invulnerable: packet.flags.invulnerable,
|
||||||
flying: packet.flags.flying,
|
flying: packet.flags.flying,
|
||||||
|
|
|
@ -74,7 +74,7 @@ pub struct PacketEvent {
|
||||||
/// The client entity that received the packet.
|
/// The client entity that received the packet.
|
||||||
pub entity: Entity,
|
pub entity: Entity,
|
||||||
/// The packet that was actually received.
|
/// 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
|
/// A player joined the game (or more specifically, was added to the tab
|
||||||
|
@ -163,13 +163,10 @@ pub fn send_packet_events(
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if let ClientboundGamePacket::LevelChunkWithLight(_) = packet {
|
packet_events.send(PacketEvent {
|
||||||
} else {
|
entity: player_entity,
|
||||||
packet_events.send(PacketEvent {
|
packet: Arc::new(packet),
|
||||||
entity: player_entity,
|
});
|
||||||
packet,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// clear the packets right after we read them
|
// clear the packets right after we read them
|
||||||
packets.clear();
|
packets.clear();
|
||||||
|
@ -190,7 +187,9 @@ pub fn process_packet_events(ecs: &mut World) {
|
||||||
events_owned.push((*player_entity, packet.clone()));
|
events_owned.push((*player_entity, packet.clone()));
|
||||||
}
|
}
|
||||||
for (player_entity, packet) in events_owned {
|
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) => {
|
ClientboundGamePacket::Login(p) => {
|
||||||
debug!("Got login packet");
|
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 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
|
// we use RelativeEntityUpdate because it makes sure changes aren't made
|
||||||
// multiple times
|
// multiple times
|
||||||
commands.entity(entity).add(RelativeEntityUpdate {
|
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_system_state = SystemState::<Commands>::new(world);
|
||||||
let mut commands = commands_system_state.get_mut(world);
|
let mut commands = commands_system_state.get_mut(world);
|
||||||
let mut entity_comands = commands.entity(entity_id);
|
let mut entity_comands = commands.entity(entity_id);
|
||||||
if let Err(e) = apply_metadata(
|
if let Err(e) =
|
||||||
&mut entity_comands,
|
apply_metadata(&mut entity_comands, *entity_kind, packed_items)
|
||||||
*entity_kind,
|
{
|
||||||
(*p.packed_items).clone(),
|
|
||||||
) {
|
|
||||||
warn!("{e}");
|
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
|
// this is to make sure the same entity velocity update doesn't get sent
|
||||||
// multiple times when in swarms
|
// 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 {
|
commands.entity(entity).add(RelativeEntityUpdate {
|
||||||
partial_world: instance_holder.partial_instance.clone(),
|
partial_world: instance_holder.partial_instance.clone(),
|
||||||
update: Box::new(move |entity_mut| {
|
update: Box::new(move |entity_mut| {
|
||||||
entity_mut.world_scope(|world| {
|
entity_mut.world_scope(|world| {
|
||||||
world.send_event(KnockbackEvent {
|
world.send_event(KnockbackEvent { entity, knockback })
|
||||||
entity,
|
|
||||||
knockback: KnockbackType::Set(Vec3 {
|
|
||||||
x: p.xa as f64 / 8000.,
|
|
||||||
y: p.ya as f64 / 8000.,
|
|
||||||
z: p.za as f64 / 8000.,
|
|
||||||
}),
|
|
||||||
})
|
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
@ -1226,7 +1225,7 @@ pub fn process_packet_events(ecs: &mut World) {
|
||||||
entity: player_entity,
|
entity: player_entity,
|
||||||
window_id: p.container_id,
|
window_id: p.container_id,
|
||||||
menu_type: p.menu_type,
|
menu_type: p.menu_type,
|
||||||
title: p.title,
|
title: p.title.to_owned(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
ClientboundGamePacket::OpenSignEditor(_) => {}
|
ClientboundGamePacket::OpenSignEditor(_) => {}
|
||||||
|
@ -1281,10 +1280,10 @@ pub fn process_packet_events(ecs: &mut World) {
|
||||||
|
|
||||||
resource_pack_events.send(ResourcePackEvent {
|
resource_pack_events.send(ResourcePackEvent {
|
||||||
entity: player_entity,
|
entity: player_entity,
|
||||||
url: p.url,
|
url: p.url.to_owned(),
|
||||||
hash: p.hash,
|
hash: p.hash.to_owned(),
|
||||||
required: p.required,
|
required: p.required,
|
||||||
prompt: p.prompt,
|
prompt: p.prompt.to_owned(),
|
||||||
});
|
});
|
||||||
|
|
||||||
system_state.apply(ecs);
|
system_state.apply(ecs);
|
||||||
|
|
|
@ -47,7 +47,7 @@ async fn main() -> anyhow::Result<()> {
|
||||||
|
|
||||||
let mut accounts = Vec::new();
|
let mut accounts = Vec::new();
|
||||||
|
|
||||||
for i in 0..200 {
|
for i in 0..3 {
|
||||||
accounts.push(Account::offline(&format!("bot{i}")));
|
accounts.push(Account::offline(&format!("bot{i}")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -180,7 +180,7 @@ pub struct WaitingForInventoryOpen;
|
||||||
|
|
||||||
fn handle_menu_opened_event(mut commands: Commands, mut events: EventReader<PacketEvent>) {
|
fn handle_menu_opened_event(mut commands: Commands, mut events: EventReader<PacketEvent>) {
|
||||||
for event in events.read() {
|
for event in events.read() {
|
||||||
if let ClientboundGamePacket::ContainerSetContent { .. } = event.packet {
|
if let ClientboundGamePacket::ContainerSetContent { .. } = event.packet.as_ref() {
|
||||||
commands
|
commands
|
||||||
.entity(event.entity)
|
.entity(event.entity)
|
||||||
.remove::<WaitingForInventoryOpen>();
|
.remove::<WaitingForInventoryOpen>();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue