aboutsummaryrefslogtreecommitdiff
path: root/azalea-client/src/packet_handling.rs
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2023-03-07 14:14:36 -0600
committerGitHub <noreply@github.com>2023-03-07 14:14:36 -0600
commit719379a8a76ab0685f2bd14bebe2f0cd1e97f06b (patch)
treece5d6c62bc36fb1d1ec31083bc8e81a0109c12df /azalea-client/src/packet_handling.rs
parentbf4ff517890cad3ff4e36b4b78959504192e5374 (diff)
downloadazalea-drasl-719379a8a76ab0685f2bd14bebe2f0cd1e97f06b.tar.xz
Bevy 0.10 (#79)
* replace 0.9.1 with 0.10.0 * start migrating to bevy .10 * well it compiles * doesn't immediately panic * remove unused imports * fmt * delete azalea-ecs * make RelativeEntityUpdate an EntityCommand * fix a doc test * explain what FixedUpdate does
Diffstat (limited to 'azalea-client/src/packet_handling.rs')
-rw-r--r--azalea-client/src/packet_handling.rs66
1 files changed, 30 insertions, 36 deletions
diff --git a/azalea-client/src/packet_handling.rs b/azalea-client/src/packet_handling.rs
index 9f8c5f1a..76e6ee41 100644
--- a/azalea-client/src/packet_handling.rs
+++ b/azalea-client/src/packet_handling.rs
@@ -1,15 +1,6 @@
use std::{collections::HashSet, io::Cursor, sync::Arc};
use azalea_core::{ChunkPos, ResourceLocation, Vec3};
-use azalea_ecs::{
- app::{App, CoreStage, Plugin},
- component::Component,
- ecs::Ecs,
- entity::Entity,
- event::{EventReader, EventWriter, Events},
- schedule::{StageLabel, SystemStage},
- system::{Commands, Query, ResMut, SystemState},
-};
use azalea_protocol::{
connect::{ReadConnection, WriteConnection},
packets::game::{
@@ -25,12 +16,21 @@ use azalea_protocol::{
use azalea_world::{
entity::{
metadata::{apply_metadata, Health, PlayerMetadataBundle},
- set_rotation, Dead, EntityBundle, EntityKind, LastSentPosition, MinecraftEntityId, Physics,
- PlayerBundle, Position, WorldName,
+ set_rotation, Dead, EntityBundle, EntityKind, EntityUpdateSet, LastSentPosition,
+ MinecraftEntityId, Physics, PlayerBundle, Position, WorldName,
},
entity::{LoadedBy, RelativeEntityUpdate},
PartialWorld, WorldContainer,
};
+use bevy_app::{App, CoreSet, Plugin};
+use bevy_ecs::{
+ component::Component,
+ entity::Entity,
+ event::{EventReader, EventWriter, Events},
+ schedule::IntoSystemConfig,
+ system::{Commands, Query, ResMut, SystemState},
+ world::World,
+};
use log::{debug, error, trace, warn};
use parking_lot::Mutex;
use tokio::sync::mpsc;
@@ -46,7 +46,7 @@ use crate::{
/// ```
/// # use azalea_client::packet_handling::PacketEvent;
/// # use azalea_protocol::packets::game::ClientboundGamePacket;
-/// # use azalea_ecs::event::EventReader;
+/// # use bevy_ecs::event::EventReader;
///
/// fn handle_packets(mut events: EventReader<PacketEvent>) {
/// for PacketEvent {
@@ -72,25 +72,22 @@ pub struct PacketEvent {
pub struct PacketHandlerPlugin;
-#[derive(StageLabel)]
-pub struct SendPacketEventsStage;
-
impl Plugin for PacketHandlerPlugin {
fn build(&self, app: &mut App) {
- app.add_stage_before(
- CoreStage::PreUpdate,
- SendPacketEventsStage,
- SystemStage::parallel(),
- )
- .add_system_to_stage(SendPacketEventsStage, send_packet_events)
- .add_system_to_stage(CoreStage::PreUpdate, process_packet_events)
- .init_resource::<Events<PacketEvent>>()
- .add_event::<AddPlayerEvent>()
- .add_event::<RemovePlayerEvent>()
- .add_event::<UpdatePlayerEvent>()
- .add_event::<ChatReceivedEvent>()
- .add_event::<DeathEvent>()
- .add_event::<KeepAliveEvent>();
+ app.add_system(send_packet_events.in_base_set(CoreSet::First))
+ .add_system(
+ process_packet_events
+ .in_base_set(CoreSet::PreUpdate)
+ // we want to index and deindex right after
+ .before(EntityUpdateSet::Deindex),
+ )
+ .init_resource::<Events<PacketEvent>>()
+ .add_event::<AddPlayerEvent>()
+ .add_event::<RemovePlayerEvent>()
+ .add_event::<UpdatePlayerEvent>()
+ .add_event::<ChatReceivedEvent>()
+ .add_event::<DeathEvent>()
+ .add_event::<KeepAliveEvent>();
}
}
@@ -168,7 +165,7 @@ pub fn send_packet_events(
}
}
-fn process_packet_events(ecs: &mut Ecs) {
+fn process_packet_events(ecs: &mut World) {
let mut events_owned = Vec::new();
let mut system_state: SystemState<EventReader<PacketEvent>> = SystemState::new(ecs);
let mut events = system_state.get_mut(ecs);
@@ -715,8 +712,7 @@ fn process_packet_events(ecs: &mut Ecs) {
if let Some(entity) = entity {
let new_position = p.position;
- commands.add(RelativeEntityUpdate {
- entity,
+ commands.entity(entity).add(RelativeEntityUpdate {
partial_world: local_player.partial_world.clone(),
update: Box::new(move |entity| {
let mut position = entity.get_mut::<Position>().unwrap();
@@ -747,8 +743,7 @@ fn process_packet_events(ecs: &mut Ecs) {
if let Some(entity) = entity {
let delta = p.delta.clone();
- commands.add(RelativeEntityUpdate {
- entity,
+ commands.entity(entity).add(RelativeEntityUpdate {
partial_world: local_player.partial_world.clone(),
update: Box::new(move |entity_mut| {
let mut position = entity_mut.get_mut::<Position>().unwrap();
@@ -776,8 +771,7 @@ fn process_packet_events(ecs: &mut Ecs) {
if let Some(entity) = entity {
let delta = p.delta.clone();
- commands.add(RelativeEntityUpdate {
- entity,
+ commands.entity(entity).add(RelativeEntityUpdate {
partial_world: local_player.partial_world.clone(),
update: Box::new(move |entity_mut| {
let mut position = entity_mut.get_mut::<Position>().unwrap();