aboutsummaryrefslogtreecommitdiff
path: root/azalea-client/src
diff options
context:
space:
mode:
Diffstat (limited to 'azalea-client/src')
-rwxr-xr-xazalea-client/src/chat.rs10
-rw-r--r--azalea-client/src/client.rs45
-rw-r--r--azalea-client/src/disconnect.rs6
-rw-r--r--azalea-client/src/events.rs27
-rw-r--r--azalea-client/src/interact.rs7
-rw-r--r--azalea-client/src/inventory.rs14
-rw-r--r--azalea-client/src/local_player.rs8
-rw-r--r--azalea-client/src/mining.rs5
-rw-r--r--azalea-client/src/movement.rs18
-rw-r--r--azalea-client/src/packet_handling.rs25
-rw-r--r--azalea-client/src/respawn.rs6
-rw-r--r--azalea-client/src/task_pool.rs9
12 files changed, 98 insertions, 82 deletions
diff --git a/azalea-client/src/chat.rs b/azalea-client/src/chat.rs
index 90618c80..337bce51 100755
--- a/azalea-client/src/chat.rs
+++ b/azalea-client/src/chat.rs
@@ -7,11 +7,12 @@ use azalea_protocol::packets::game::{
serverbound_chat_command_packet::ServerboundChatCommandPacket,
serverbound_chat_packet::{LastSeenMessagesUpdate, ServerboundChatPacket},
};
-use bevy_app::{App, Plugin};
+use bevy_app::{App, Plugin, Update};
use bevy_ecs::{
entity::Entity,
event::{EventReader, EventWriter},
- schedule::{IntoSystemConfig, IntoSystemConfigs},
+ prelude::Event,
+ schedule::IntoSystemConfigs,
};
use std::{
sync::Arc,
@@ -170,6 +171,7 @@ impl Plugin for ChatPlugin {
.add_event::<SendChatKindEvent>()
.add_event::<ChatReceivedEvent>()
.add_systems(
+ Update,
(
handle_send_chat_event,
handle_send_chat_kind_event.after(handle_send_packet_event),
@@ -180,13 +182,14 @@ impl Plugin for ChatPlugin {
}
/// A client received a chat message packet.
-#[derive(Debug, Clone)]
+#[derive(Event, Debug, Clone)]
pub struct ChatReceivedEvent {
pub entity: Entity,
pub packet: ChatPacket,
}
/// Send a chat message (or command, if it starts with a slash) to the server.
+#[derive(Event)]
pub struct SendChatEvent {
pub entity: Entity,
pub content: String,
@@ -222,6 +225,7 @@ fn handle_send_chat_event(
///
/// If you're wondering why this isn't two separate events, it's so ordering is
/// preserved if multiple chat messages and commands are sent at the same time.
+#[derive(Event)]
pub struct SendChatKindEvent {
pub entity: Entity,
pub content: String,
diff --git a/azalea-client/src/client.rs b/azalea-client/src/client.rs
index ee133dd5..725cd9f3 100644
--- a/azalea-client/src/client.rs
+++ b/azalea-client/src/client.rs
@@ -45,13 +45,12 @@ use azalea_world::{
entity::{EntityPlugin, EntityUpdateSet, Local, Position, WorldName},
Instance, InstanceContainer, PartialInstance,
};
-use bevy_app::{App, CoreSchedule, IntoSystemAppConfig, Plugin, PluginGroup, PluginGroupBuilder};
+use bevy_app::{App, FixedUpdate, Main, Plugin, PluginGroup, PluginGroupBuilder, Update};
use bevy_ecs::{
bundle::Bundle,
component::Component,
entity::Entity,
- schedule::IntoSystemConfig,
- schedule::{LogLevel, ScheduleBuildSettings, ScheduleLabel},
+ schedule::{IntoSystemConfigs, LogLevel, ScheduleBuildSettings, ScheduleLabel},
system::{ResMut, Resource},
world::World,
};
@@ -568,20 +567,20 @@ pub struct AzaleaPlugin;
impl Plugin for AzaleaPlugin {
fn build(&self, app: &mut App) {
// Minecraft ticks happen every 50ms
- app.insert_resource(FixedTime::new(Duration::from_millis(50)));
-
- app.add_system(update_in_loaded_chunk.after(PhysicsSet));
-
- // fire the Death event when the player dies.
- app.add_system(death_event);
-
- // add GameProfileComponent when we get an AddPlayerEvent
- app.add_system(retroactively_add_game_profile_component.after(EntityUpdateSet::Index));
-
- app.add_event::<SendPacketEvent>()
- .add_system(handle_send_packet_event);
-
- app.init_resource::<InstanceContainer>();
+ app.insert_resource(FixedTime::new(Duration::from_millis(50)))
+ .add_systems(
+ Update,
+ (
+ update_in_loaded_chunk.after(PhysicsSet),
+ // fire the Death event when the player dies.
+ death_event,
+ // add GameProfileComponent when we get an AddPlayerEvent
+ retroactively_add_game_profile_component.after(EntityUpdateSet::Index),
+ handle_send_packet_event,
+ ),
+ )
+ .add_event::<SendPacketEvent>()
+ .init_resource::<InstanceContainer>();
}
}
@@ -591,19 +590,17 @@ impl Plugin for AzaleaPlugin {
/// [`DefaultPlugins`].
#[doc(hidden)]
pub fn start_ecs(
- mut app: App,
+ app: App,
run_schedule_receiver: mpsc::UnboundedReceiver<()>,
run_schedule_sender: mpsc::UnboundedSender<()>,
) -> Arc<Mutex<World>> {
- app.setup();
-
// all resources should have been added by now so we can take the ecs from the
// app
let ecs = Arc::new(Mutex::new(app.world));
tokio::spawn(run_schedule_loop(
ecs.clone(),
- app.outer_schedule_label,
+ app.main_schedule_label,
run_schedule_receiver,
));
tokio::spawn(tick_run_schedule_loop(run_schedule_sender));
@@ -620,7 +617,7 @@ async fn run_schedule_loop(
// whenever we get an event from run_schedule_receiver, run the schedule
run_schedule_receiver.recv().await;
let mut ecs = ecs.lock();
- ecs.run_schedule_ref(&*outer_schedule_label);
+ ecs.run_schedule(&outer_schedule_label);
ecs.clear_trackers();
}
}
@@ -671,14 +668,14 @@ pub struct TickBroadcastPlugin;
impl Plugin for TickBroadcastPlugin {
fn build(&self, app: &mut App) {
app.insert_resource(TickBroadcast(broadcast::channel(1).0))
- .add_system(send_tick_broadcast.in_schedule(CoreSchedule::FixedUpdate));
+ .add_systems(FixedUpdate, send_tick_broadcast);
}
}
pub struct AmbiguityLoggerPlugin;
impl Plugin for AmbiguityLoggerPlugin {
fn build(&self, app: &mut App) {
- app.edit_schedule(CoreSchedule::Main, |schedule| {
+ app.edit_schedule(Main, |schedule| {
schedule.set_build_settings(ScheduleBuildSettings {
ambiguity_detection: LogLevel::Warn,
..Default::default()
diff --git a/azalea-client/src/disconnect.rs b/azalea-client/src/disconnect.rs
index 3b8d133e..10aef7ba 100644
--- a/azalea-client/src/disconnect.rs
+++ b/azalea-client/src/disconnect.rs
@@ -1,10 +1,11 @@
//! Disconnect a client from the server.
-use bevy_app::{App, CoreSet, Plugin};
+use bevy_app::{App, Plugin, PostUpdate};
use bevy_ecs::{
component::Component,
entity::Entity,
event::{EventReader, EventWriter},
+ prelude::Event,
query::Changed,
schedule::IntoSystemConfigs,
system::{Commands, Query},
@@ -17,18 +18,19 @@ pub struct DisconnectPlugin;
impl Plugin for DisconnectPlugin {
fn build(&self, app: &mut App) {
app.add_event::<DisconnectEvent>().add_systems(
+ PostUpdate,
(
update_read_packets_task_running_component,
disconnect_on_read_packets_ended,
remove_components_from_disconnected_players,
)
- .in_base_set(CoreSet::PostUpdate)
.chain(),
);
}
}
/// An event sent when a client is getting disconnected.
+#[derive(Event)]
pub struct DisconnectEvent {
pub entity: Entity,
}
diff --git a/azalea-client/src/events.rs b/azalea-client/src/events.rs
index c7ff20aa..e97f3477 100644
--- a/azalea-client/src/events.rs
+++ b/azalea-client/src/events.rs
@@ -7,7 +7,7 @@ use azalea_protocol::packets::game::{
clientbound_player_combat_kill_packet::ClientboundPlayerCombatKillPacket, ClientboundGamePacket,
};
use azalea_world::entity::MinecraftEntityId;
-use bevy_app::{App, CoreSchedule, IntoSystemAppConfig, Plugin};
+use bevy_app::{App, FixedUpdate, Plugin, Update};
use bevy_ecs::{component::Component, event::EventReader, query::Added, system::Query};
use derive_more::{Deref, DerefMut};
use tokio::sync::mpsc;
@@ -100,16 +100,21 @@ pub struct LocalPlayerEvents(pub mpsc::UnboundedSender<Event>);
pub struct EventPlugin;
impl Plugin for EventPlugin {
fn build(&self, app: &mut App) {
- app.add_system(chat_listener)
- .add_system(login_listener)
- .add_system(init_listener)
- .add_system(packet_listener)
- .add_system(add_player_listener)
- .add_system(update_player_listener)
- .add_system(remove_player_listener)
- .add_system(death_listener)
- .add_system(keepalive_listener)
- .add_system(tick_listener.in_schedule(CoreSchedule::FixedUpdate));
+ app.add_systems(
+ Update,
+ (
+ chat_listener,
+ login_listener,
+ init_listener,
+ packet_listener,
+ add_player_listener,
+ update_player_listener,
+ remove_player_listener,
+ death_listener,
+ keepalive_listener,
+ ),
+ )
+ .add_systems(FixedUpdate, tick_listener);
}
}
diff --git a/azalea-client/src/interact.rs b/azalea-client/src/interact.rs
index c389f2f3..45b845f9 100644
--- a/azalea-client/src/interact.rs
+++ b/azalea-client/src/interact.rs
@@ -11,12 +11,13 @@ use azalea_world::{
entity::{clamp_look_direction, view_vector, EyeHeight, LookDirection, Position, WorldName},
Instance, InstanceContainer,
};
-use bevy_app::{App, Plugin};
+use bevy_app::{App, Plugin, Update};
use bevy_ecs::{
component::Component,
entity::Entity,
event::EventReader,
- schedule::{IntoSystemConfig, IntoSystemConfigs},
+ prelude::Event,
+ schedule::IntoSystemConfigs,
system::{Commands, Query, Res},
};
use derive_more::{Deref, DerefMut};
@@ -33,6 +34,7 @@ pub struct InteractPlugin;
impl Plugin for InteractPlugin {
fn build(&self, app: &mut App) {
app.add_event::<BlockInteractEvent>().add_systems(
+ Update,
(
update_hit_result_component.after(clamp_look_direction),
handle_block_interact_event,
@@ -61,6 +63,7 @@ impl Client {
/// Right click a block. The behavior of this depends on the target block,
/// and it'll either place the block you're holding in your hand or use the
/// block you clicked (like toggling a lever).
+#[derive(Event)]
pub struct BlockInteractEvent {
/// The local player entity that's opening the container.
pub entity: Entity,
diff --git a/azalea-client/src/inventory.rs b/azalea-client/src/inventory.rs
index b7269ef1..25ce157e 100644
--- a/azalea-client/src/inventory.rs
+++ b/azalea-client/src/inventory.rs
@@ -14,13 +14,13 @@ use azalea_protocol::packets::game::{
serverbound_container_close_packet::ServerboundContainerClosePacket,
};
use azalea_registry::MenuKind;
-use bevy_app::{App, Plugin};
+use bevy_app::{App, Plugin, Update};
use bevy_ecs::{
component::Component,
entity::Entity,
event::EventReader,
- prelude::EventWriter,
- schedule::{IntoSystemConfig, IntoSystemConfigs},
+ prelude::{Event, EventWriter},
+ schedule::IntoSystemConfigs,
system::Query,
};
use log::warn;
@@ -36,6 +36,7 @@ impl Plugin for InventoryPlugin {
.add_event::<ContainerClickEvent>()
.add_event::<SetContainerContentEvent>()
.add_systems(
+ Update,
(
handle_menu_opened_event,
handle_set_container_content_event,
@@ -563,7 +564,7 @@ impl Default for InventoryComponent {
/// Sent from the server when a menu (like a chest or crafting table) was
/// opened by the client.
-#[derive(Debug)]
+#[derive(Event, Debug)]
pub struct MenuOpenedEvent {
pub entity: Entity,
pub window_id: u32,
@@ -585,6 +586,7 @@ fn handle_menu_opened_event(
///
/// Note that this is also sent when the client closes its own inventory, even
/// though there is no packet for opening its inventory.
+#[derive(Event)]
pub struct CloseContainerEvent {
pub entity: Entity,
/// The ID of the container to close. 0 for the player's inventory. If this
@@ -621,6 +623,7 @@ fn handle_container_close_event(
/// Close a container without notifying the server.
///
/// Note that this also gets fired when we get a [`CloseContainerEvent`].
+#[derive(Event)]
pub struct ClientSideCloseContainerEvent {
pub entity: Entity,
}
@@ -635,7 +638,7 @@ pub fn handle_client_side_close_container_event(
}
}
-#[derive(Debug)]
+#[derive(Event, Debug)]
pub struct ContainerClickEvent {
pub entity: Entity,
pub window_id: u8,
@@ -687,6 +690,7 @@ pub fn handle_container_click_event(
/// Sent from the server when the contents of a container are replaced. Usually
/// triggered by the `ContainerSetContent` packet.
+#[derive(Event)]
pub struct SetContainerContentEvent {
pub entity: Entity,
pub slots: Vec<ItemSlot>,
diff --git a/azalea-client/src/local_player.rs b/azalea-client/src/local_player.rs
index 691f9ced..4368c47c 100644
--- a/azalea-client/src/local_player.rs
+++ b/azalea-client/src/local_player.rs
@@ -11,6 +11,7 @@ use bevy_ecs::{
component::Component,
entity::Entity,
event::EventReader,
+ prelude::Event,
query::Added,
system::{Query, Res},
};
@@ -20,7 +21,7 @@ use thiserror::Error;
use tokio::{sync::mpsc, task::JoinHandle};
use crate::{
- events::{Event, LocalPlayerEvents},
+ events::{Event as AzaleaEvent, LocalPlayerEvents},
ClientInformation, WalkDirection,
};
@@ -155,7 +156,7 @@ pub fn update_in_loaded_chunk(
/// Send the "Death" event for [`LocalPlayer`]s that died with no reason.
pub fn death_event(query: Query<&LocalPlayerEvents, Added<Dead>>) {
for local_player_events in &query {
- local_player_events.send(Event::Death(None)).unwrap();
+ local_player_events.send(AzaleaEvent::Death(None)).unwrap();
}
}
@@ -168,7 +169,7 @@ pub enum HandlePacketError {
#[error(transparent)]
Other(#[from] anyhow::Error),
#[error("{0}")]
- Send(#[from] mpsc::error::SendError<Event>),
+ Send(#[from] mpsc::error::SendError<AzaleaEvent>),
}
impl<T> From<std::sync::PoisonError<T>> for HandlePacketError {
@@ -178,6 +179,7 @@ impl<T> From<std::sync::PoisonError<T>> for HandlePacketError {
}
/// Event for sending a packet to the server.
+#[derive(Event)]
pub struct SendPacketEvent {
pub entity: Entity,
pub packet: ServerboundGamePacket,
diff --git a/azalea-client/src/mining.rs b/azalea-client/src/mining.rs
index ab141661..241c4fde 100644
--- a/azalea-client/src/mining.rs
+++ b/azalea-client/src/mining.rs
@@ -1,5 +1,5 @@
use azalea_core::BlockPos;
-use bevy_app::{App, Plugin};
+use bevy_app::{App, Plugin, Update};
use bevy_ecs::prelude::*;
use crate::Client;
@@ -9,7 +9,7 @@ pub struct MinePlugin;
impl Plugin for MinePlugin {
fn build(&self, app: &mut App) {
app.add_event::<StartMiningBlockEvent>()
- .add_system(handle_start_mining_block_event);
+ .add_systems(Update, handle_start_mining_block_event);
}
}
@@ -23,6 +23,7 @@ impl Client {
}
}
+#[derive(Event)]
pub struct StartMiningBlockEvent {
pub entity: Entity,
pub position: BlockPos,
diff --git a/azalea-client/src/movement.rs b/azalea-client/src/movement.rs
index d68be8b8..2db392b4 100644
--- a/azalea-client/src/movement.rs
+++ b/azalea-client/src/movement.rs
@@ -14,14 +14,11 @@ use azalea_world::{
entity::{self, metadata::Sprinting, Attributes, Jumping, MinecraftEntityId},
MoveEntityError,
};
-use bevy_app::{App, CoreSchedule, IntoSystemAppConfigs, Plugin};
+use bevy_app::{App, FixedUpdate, Plugin, Update};
+use bevy_ecs::prelude::Event;
use bevy_ecs::{
- component::Component,
- entity::Entity,
- event::EventReader,
- query::With,
- schedule::{IntoSystemConfig, IntoSystemConfigs},
- system::Query,
+ component::Component, entity::Entity, event::EventReader, query::With,
+ schedule::IntoSystemConfigs, system::Query,
};
use std::backtrace::Backtrace;
use thiserror::Error;
@@ -51,17 +48,18 @@ impl Plugin for PlayerMovePlugin {
app.add_event::<StartWalkEvent>()
.add_event::<StartSprintEvent>()
.add_systems(
+ Update,
(sprint_listener, walk_listener)
.chain()
.before(force_jump_listener),
)
.add_systems(
+ FixedUpdate,
(
local_player_ai_step.in_set(PhysicsSet),
send_position.after(update_in_loaded_chunk),
)
- .chain()
- .in_schedule(CoreSchedule::FixedUpdate),
+ .chain(),
);
}
}
@@ -379,6 +377,7 @@ impl Client {
/// An event sent when the client starts walking. This does not get sent for
/// non-local entities.
+#[derive(Event)]
pub struct StartWalkEvent {
pub entity: Entity,
pub direction: WalkDirection,
@@ -402,6 +401,7 @@ pub fn walk_listener(
/// An event sent when the client starts sprinting. This does not get sent for
/// non-local entities.
+#[derive(Event)]
pub struct StartSprintEvent {
pub entity: Entity,
pub direction: SprintDirection,
diff --git a/azalea-client/src/packet_handling.rs b/azalea-client/src/packet_handling.rs
index 50887096..2371d834 100644
--- a/azalea-client/src/packet_handling.rs
+++ b/azalea-client/src/packet_handling.rs
@@ -24,12 +24,13 @@ use azalea_world::{
entity::{LoadedBy, RelativeEntityUpdate},
InstanceContainer, PartialInstance,
};
-use bevy_app::{App, CoreSet, Plugin};
+use bevy_app::{App, First, Plugin, PreUpdate};
use bevy_ecs::{
component::Component,
entity::Entity,
event::{EventReader, EventWriter, Events},
- schedule::IntoSystemConfig,
+ prelude::Event,
+ schedule::IntoSystemConfigs,
system::{Commands, Query, ResMut, SystemState},
world::World,
};
@@ -69,7 +70,7 @@ use crate::{
/// }
/// }
/// ```
-#[derive(Debug, Clone)]
+#[derive(Event, Debug, Clone)]
pub struct PacketEvent {
/// The client entity that received the packet.
pub entity: Entity,
@@ -81,10 +82,10 @@ pub struct PacketHandlerPlugin;
impl Plugin for PacketHandlerPlugin {
fn build(&self, app: &mut App) {
- app.add_system(send_packet_events.in_base_set(CoreSet::First))
- .add_system(
+ app.add_systems(First, send_packet_events)
+ .add_systems(
+ PreUpdate,
process_packet_events
- .in_base_set(CoreSet::PreUpdate)
// we want to index and deindex right after
.before(EntityUpdateSet::Deindex),
)
@@ -100,7 +101,7 @@ impl Plugin for PacketHandlerPlugin {
/// A player joined the game (or more specifically, was added to the tab
/// list of a local player).
-#[derive(Debug, Clone)]
+#[derive(Event, Debug, Clone)]
pub struct AddPlayerEvent {
/// The local player entity that received this event.
pub entity: Entity,
@@ -108,7 +109,7 @@ pub struct AddPlayerEvent {
}
/// A player left the game (or maybe is still in the game and was just
/// removed from the tab list of a local player).
-#[derive(Debug, Clone)]
+#[derive(Event, Debug, Clone)]
pub struct RemovePlayerEvent {
/// The local player entity that received this event.
pub entity: Entity,
@@ -116,7 +117,7 @@ pub struct RemovePlayerEvent {
}
/// A player was updated in the tab list of a local player (gamemode, display
/// name, or latency changed).
-#[derive(Debug, Clone)]
+#[derive(Event, Debug, Clone)]
pub struct UpdatePlayerEvent {
/// The local player entity that received this event.
pub entity: Entity,
@@ -126,7 +127,7 @@ pub struct UpdatePlayerEvent {
/// Event for when an entity dies. dies. If it's a local player and there's a
/// reason in the death screen, the [`ClientboundPlayerCombatKillPacket`] will
/// be included.
-#[derive(Debug, Clone)]
+#[derive(Event, Debug, Clone)]
pub struct DeathEvent {
pub entity: Entity,
pub packet: Option<ClientboundPlayerCombatKillPacket>,
@@ -134,7 +135,7 @@ pub struct DeathEvent {
/// A KeepAlive packet is sent from the server to verify that the client is
/// still connected.
-#[derive(Debug, Clone)]
+#[derive(Event, Debug, Clone)]
pub struct KeepAliveEvent {
pub entity: Entity,
/// The ID of the keepalive. This is an arbitrary number, but vanilla
@@ -143,7 +144,7 @@ pub struct KeepAliveEvent {
}
/// Something that receives packets from the server.
-#[derive(Component, Clone)]
+#[derive(Event, Component, Clone)]
pub struct PacketReceiver {
pub packets: Arc<Mutex<Vec<ClientboundGamePacket>>>,
pub run_schedule_sender: mpsc::UnboundedSender<()>,
diff --git a/azalea-client/src/respawn.rs b/azalea-client/src/respawn.rs
index 3ac17612..d0ef1cca 100644
--- a/azalea-client/src/respawn.rs
+++ b/azalea-client/src/respawn.rs
@@ -1,13 +1,13 @@
use azalea_protocol::packets::game::serverbound_client_command_packet::{
self, ServerboundClientCommandPacket,
};
-use bevy_app::{App, Plugin};
+use bevy_app::{App, Plugin, Update};
use bevy_ecs::prelude::*;
use crate::local_player::{handle_send_packet_event, SendPacketEvent};
/// Tell the server that we're respawning.
-#[derive(Debug, Clone)]
+#[derive(Event, Debug, Clone)]
pub struct PerformRespawnEvent {
pub entity: Entity,
}
@@ -17,7 +17,7 @@ pub struct RespawnPlugin;
impl Plugin for RespawnPlugin {
fn build(&self, app: &mut App) {
app.add_event::<PerformRespawnEvent>()
- .add_system(perform_respawn.before(handle_send_packet_event));
+ .add_systems(Update, perform_respawn.before(handle_send_packet_event));
}
}
diff --git a/azalea-client/src/task_pool.rs b/azalea-client/src/task_pool.rs
index 8df554f0..982c3396 100644
--- a/azalea-client/src/task_pool.rs
+++ b/azalea-client/src/task_pool.rs
@@ -2,11 +2,8 @@
use std::marker::PhantomData;
-use bevy_app::{App, CoreSet, Plugin};
-use bevy_ecs::{
- schedule::IntoSystemConfig,
- system::{NonSend, Resource},
-};
+use bevy_app::{App, Last, Plugin};
+use bevy_ecs::system::{NonSend, Resource};
use bevy_tasks::{
tick_global_task_pools_on_main_thread, AsyncComputeTaskPool, ComputeTaskPool, IoTaskPool,
TaskPoolBuilder,
@@ -27,7 +24,7 @@ impl Plugin for TaskPoolPlugin {
self.task_pool_options.create_default_pools();
#[cfg(not(target_arch = "wasm32"))]
- app.add_system(tick_global_task_pools.in_base_set(CoreSet::Last));
+ app.add_systems(Last, tick_global_task_pools);
}
}