diff --git a/Cargo.toml b/Cargo.toml index b5ac683dc..269d1d2ae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -78,6 +78,7 @@ opt-level = 1 [workspace] members = ["crates/*", "tools/*"] +exclude = ["tools/dump_schedule"] resolver = "2" [workspace.package] @@ -95,11 +96,10 @@ arrayvec = "0.7.2" async-trait = "0.1.60" atty = "0.2.14" base64 = "0.21.0" -bevy_app = { version = "0.10.1", default-features = false } -bevy_ecs = { version = "0.10.1", default-features = false, features = [ - "trace", -] } -bevy_hierarchy = { version = "0.10.1", default-features = false } +bevy_app = { git = "https://github.com/bevyengine/bevy", rev = "910f984709fb58cddbb7393c948634a2540e8d72", default-features = false } +bevy_ecs = { git = "https://github.com/bevyengine/bevy", rev = "910f984709fb58cddbb7393c948634a2540e8d72", default-features = false } +bevy_hierarchy = { git = "https://github.com/bevyengine/bevy", rev = "910f984709fb58cddbb7393c948634a2540e8d72", default-features = false } +bevy_utils = { git = "https://github.com/bevyengine/bevy", rev = "910f984709fb58cddbb7393c948634a2540e8d72" } bevy_mod_debugdump = "0.7.0" bitfield-struct = "0.3.1" byteorder = "1.4.3" diff --git a/benches/idle.rs b/benches/idle.rs index dd9a2dac3..d82fed58c 100644 --- a/benches/idle.rs +++ b/benches/idle.rs @@ -7,7 +7,7 @@ pub fn idle_update(c: &mut Criterion) { let mut app = App::new(); app.add_plugins(DefaultPlugins); - app.add_startup_system(setup); + app.add_systems(Startup, setup); // Run startup schedule. app.update(); diff --git a/crates/valence_advancement/src/event.rs b/crates/valence_advancement/src/event.rs index 565e7d457..2d05aa068 100644 --- a/crates/valence_advancement/src/event.rs +++ b/crates/valence_advancement/src/event.rs @@ -1,12 +1,12 @@ -use bevy_ecs::prelude::{Entity, EventReader, EventWriter}; +use bevy_ecs::prelude::*; use valence_client::event_loop::PacketEvent; use valence_core::ident::Ident; use crate::packet::AdvancementTabC2s; /// This event sends when the client changes or closes advancement's tab. -#[derive(Clone, PartialEq, Eq, Debug)] -pub struct AdvancementTabChange { +#[derive(Event, Clone, PartialEq, Eq, Debug)] +pub struct AdvancementTabChangeEvent { pub client: Entity, /// If None then the client has closed advancement's tabs. pub opened_tab: Option>, @@ -14,11 +14,11 @@ pub struct AdvancementTabChange { pub(crate) fn handle_advancement_tab_change( mut packets: EventReader, - mut advancement_tab_change_events: EventWriter, + mut advancement_tab_change_events: EventWriter, ) { for packet in packets.iter() { if let Some(pkt) = packet.decode::() { - advancement_tab_change_events.send(AdvancementTabChange { + advancement_tab_change_events.send(AdvancementTabChangeEvent { client: packet.client, opened_tab: match pkt { AdvancementTabC2s::ClosedScreen => None, diff --git a/crates/valence_advancement/src/lib.rs b/crates/valence_advancement/src/lib.rs index 8703acb95..53273ebcf 100644 --- a/crates/valence_advancement/src/lib.rs +++ b/crates/valence_advancement/src/lib.rs @@ -8,14 +8,12 @@ use std::borrow::Cow; use std::io::Write; use std::time::{SystemTime, UNIX_EPOCH}; -use bevy_app::{CoreSet, Plugin}; -use bevy_ecs::prelude::{Bundle, Component, Entity}; -use bevy_ecs::query::{Added, Changed, Or, With}; -use bevy_ecs::schedule::{IntoSystemConfig, IntoSystemSetConfig, SystemSet}; -use bevy_ecs::system::{Commands, Query, SystemParam}; +use bevy_app::prelude::*; +use bevy_ecs::prelude::*; +use bevy_ecs::system::SystemParam; pub use bevy_hierarchy; use bevy_hierarchy::{Children, Parent}; -use event::{handle_advancement_tab_change, AdvancementTabChange}; +use event::{handle_advancement_tab_change, AdvancementTabChangeEvent}; use packet::SelectAdvancementTabS2c; use rustc_hash::FxHashMap; use valence_client::{Client, FlushPacketsSet, SpawnClientsSet}; @@ -37,23 +35,28 @@ pub struct WriteAdvancementToCacheSet; impl Plugin for AdvancementPlugin { fn build(&self, app: &mut bevy_app::App) { - app.configure_sets(( - WriteAdvancementPacketToClientsSet - .in_base_set(CoreSet::PostUpdate) - .before(FlushPacketsSet), - WriteAdvancementToCacheSet - .in_base_set(CoreSet::PostUpdate) - .before(WriteAdvancementPacketToClientsSet), - )) - .add_event::() - .add_system( - add_advancement_update_component_to_new_clients - .after(SpawnClientsSet) - .in_base_set(CoreSet::PreUpdate), + app.configure_sets( + PostUpdate, + ( + WriteAdvancementPacketToClientsSet.before(FlushPacketsSet), + WriteAdvancementToCacheSet.before(WriteAdvancementPacketToClientsSet), + ), + ) + .add_event::() + .add_systems( + PreUpdate, + ( + add_advancement_update_component_to_new_clients.after(SpawnClientsSet), + handle_advancement_tab_change, + ), ) - .add_system(handle_advancement_tab_change.in_base_set(CoreSet::PreUpdate)) - .add_system(update_advancement_cached_bytes.in_set(WriteAdvancementToCacheSet)) - .add_system(send_advancement_update_packet.in_set(WriteAdvancementPacketToClientsSet)); + .add_systems( + PostUpdate, + ( + update_advancement_cached_bytes, + send_advancement_update_packet, + ), + ); } } diff --git a/crates/valence_anvil/src/lib.rs b/crates/valence_anvil/src/lib.rs index f08f17afa..8fd4311cb 100644 --- a/crates/valence_anvil/src/lib.rs +++ b/crates/valence_anvil/src/lib.rs @@ -277,11 +277,11 @@ impl Plugin for AnvilPlugin { fn build(&self, app: &mut App) { app.add_event::() .add_event::() - .add_system(remove_unviewed_chunks.in_base_set(CoreSet::PreUpdate)) + .add_systems(PreUpdate, remove_unviewed_chunks) .add_systems( + PostUpdate, (init_anvil, update_client_views, send_recv_chunks) .chain() - .in_base_set(CoreSet::PostUpdate) .before(UpdateClientsSet), ); } @@ -433,7 +433,7 @@ fn anvil_worker(mut state: ChunkWorkerState) { } /// An event sent by `valence_anvil` after an attempt to load a chunk is made. -#[derive(Debug)] +#[derive(Event, Debug)] pub struct ChunkLoadEvent { /// The [`Instance`] where the chunk is located. pub instance: Entity, @@ -460,7 +460,7 @@ pub enum ChunkLoadStatus { } /// An event sent by `valence_anvil` when a chunk is unloaded from an instance. -#[derive(Debug)] +#[derive(Event, Debug)] pub struct ChunkUnloadEvent { /// The [`Instance`] where the chunk was unloaded. pub instance: Entity, diff --git a/crates/valence_biome/src/lib.rs b/crates/valence_biome/src/lib.rs index 83bbd6f69..2189b481a 100644 --- a/crates/valence_biome/src/lib.rs +++ b/crates/valence_biome/src/lib.rs @@ -34,12 +34,8 @@ pub struct BiomePlugin; impl Plugin for BiomePlugin { fn build(&self, app: &mut App) { app.init_resource::() - .add_startup_system(load_default_biomes.in_base_set(CoreSet::PreUpdate)) - .add_system( - update_biome_registry - .in_base_set(CoreSet::PostUpdate) - .before(RegistrySet), - ); + .add_systems(PreStartup, load_default_biomes) + .add_systems(PostUpdate, update_biome_registry.before(RegistrySet)); } } diff --git a/crates/valence_boss_bar/src/lib.rs b/crates/valence_boss_bar/src/lib.rs index 8d63f24a3..d1fd642f0 100644 --- a/crates/valence_boss_bar/src/lib.rs +++ b/crates/valence_boss_bar/src/lib.rs @@ -20,12 +20,8 @@ use std::borrow::Cow; -use bevy_app::CoreSet::PostUpdate; -use bevy_app::Plugin; -use bevy_ecs::prelude::Entity; -use bevy_ecs::query::{Added, Changed, With}; -use bevy_ecs::schedule::{IntoSystemConfig, IntoSystemConfigs}; -use bevy_ecs::system::Query; +use bevy_app::prelude::*; +use bevy_ecs::prelude::*; use packet::{BossBarAction, BossBarS2c}; use valence_client::{Client, FlushPacketsSet}; use valence_core::despawn::Despawned; @@ -42,6 +38,7 @@ pub struct BossBarPlugin; impl Plugin for BossBarPlugin { fn build(&self, app: &mut bevy_app::App) { app.add_systems( + PostUpdate, ( boss_bar_title_update, boss_bar_health_update, @@ -51,8 +48,7 @@ impl Plugin for BossBarPlugin { boss_bar_despawn, client_disconnection.before(boss_bar_viewers_update), ) - .before(FlushPacketsSet) - .in_base_set(PostUpdate), + .before(FlushPacketsSet), ); } } diff --git a/crates/valence_client/Cargo.toml b/crates/valence_client/Cargo.toml index 617a44924..b7df47732 100644 --- a/crates/valence_client/Cargo.toml +++ b/crates/valence_client/Cargo.toml @@ -7,6 +7,7 @@ edition.workspace = true anyhow.workspace = true bevy_app.workspace = true bevy_ecs.workspace = true +bevy_utils.workspace = true # Needed for `ScheduleLabel` derive macro. bitfield-struct.workspace = true bytes.workspace = true glam.workspace = true diff --git a/crates/valence_client/src/action.rs b/crates/valence_client/src/action.rs index 4e548e6fb..c23e1e8e8 100644 --- a/crates/valence_client/src/action.rs +++ b/crates/valence_client/src/action.rs @@ -4,20 +4,19 @@ use valence_core::protocol::var_int::VarInt; use valence_core::protocol::{packet_id, Decode, Encode, Packet}; use super::*; -use crate::event_loop::{EventLoopSchedule, EventLoopSet, PacketEvent}; +use crate::event_loop::{EventLoopPreUpdate, PacketEvent}; use crate::packet::{PlayerAction, PlayerActionC2s}; pub(super) fn build(app: &mut App) { app.add_event::() - .add_system( - handle_player_action - .in_schedule(EventLoopSchedule) - .in_base_set(EventLoopSet::PreUpdate), - ) - .add_system(acknowledge_player_actions.in_set(UpdateClientsSet)); + .add_systems(EventLoopPreUpdate, handle_player_action) + .add_systems( + PostUpdate, + acknowledge_player_actions.in_set(UpdateClientsSet), + ); } -#[derive(Copy, Clone, Debug)] +#[derive(Event, Copy, Clone, Debug)] pub struct DiggingEvent { pub client: Entity, pub position: BlockPos, diff --git a/crates/valence_client/src/command.rs b/crates/valence_client/src/command.rs index e9096fabd..756e13f83 100644 --- a/crates/valence_client/src/command.rs +++ b/crates/valence_client/src/command.rs @@ -5,21 +5,17 @@ use valence_core::protocol::{packet_id, Decode, Encode, Packet}; use valence_entity::entity::Flags; use valence_entity::{entity, Pose}; -use crate::event_loop::{EventLoopSchedule, EventLoopSet, PacketEvent}; +use crate::event_loop::{EventLoopPreUpdate, PacketEvent}; pub(super) fn build(app: &mut App) { app.add_event::() .add_event::() .add_event::() .add_event::() - .add_system( - handle_client_command - .in_schedule(EventLoopSchedule) - .in_base_set(EventLoopSet::PreUpdate), - ); + .add_systems(EventLoopPreUpdate, handle_client_command); } -#[derive(Copy, Clone, PartialEq, Eq, Debug)] +#[derive(Event, Copy, Clone, PartialEq, Eq, Debug)] pub struct SprintEvent { pub client: Entity, pub state: SprintState, @@ -31,7 +27,7 @@ pub enum SprintState { Stop, } -#[derive(Copy, Clone, PartialEq, Eq, Debug)] +#[derive(Event, Copy, Clone, PartialEq, Eq, Debug)] pub struct SneakEvent { pub client: Entity, pub state: SneakState, @@ -43,7 +39,7 @@ pub enum SneakState { Stop, } -#[derive(Copy, Clone, PartialEq, Eq, Debug)] +#[derive(Event, Copy, Clone, PartialEq, Eq, Debug)] pub struct JumpWithHorseEvent { pub client: Entity, pub state: JumpWithHorseState, @@ -58,7 +54,7 @@ pub enum JumpWithHorseState { Stop, } -#[derive(Copy, Clone, PartialEq, Eq, Debug)] +#[derive(Event, Copy, Clone, PartialEq, Eq, Debug)] pub struct LeaveBedEvent { pub client: Entity, } diff --git a/crates/valence_client/src/custom_payload.rs b/crates/valence_client/src/custom_payload.rs index ed7b0b8b7..15f52f561 100644 --- a/crates/valence_client/src/custom_payload.rs +++ b/crates/valence_client/src/custom_payload.rs @@ -2,17 +2,14 @@ use valence_core::protocol::raw::RawBytes; use valence_core::protocol::{packet_id, Decode, Encode}; use super::*; -use crate::event_loop::{EventLoopSchedule, EventLoopSet, PacketEvent}; +use crate::event_loop::{EventLoopPreUpdate, PacketEvent}; pub(super) fn build(app: &mut App) { - app.add_event::().add_system( - handle_custom_payload - .in_schedule(EventLoopSchedule) - .in_base_set(EventLoopSet::PreUpdate), - ); + app.add_event::() + .add_systems(EventLoopPreUpdate, handle_custom_payload); } -#[derive(Clone, Debug)] +#[derive(Event, Clone, Debug)] pub struct CustomPayloadEvent { pub client: Entity, pub channel: Ident, diff --git a/crates/valence_client/src/event_loop.rs b/crates/valence_client/src/event_loop.rs index d829317dd..d245031e8 100644 --- a/crates/valence_client/src/event_loop.rs +++ b/crates/valence_client/src/event_loop.rs @@ -1,55 +1,46 @@ use std::time::Instant; use bevy_app::prelude::*; +use bevy_app::MainScheduleOrder; use bevy_ecs::prelude::*; use bevy_ecs::schedule::ScheduleLabel; use bevy_ecs::system::SystemState; use bytes::Bytes; use tracing::{debug, warn}; use valence_core::protocol::{Decode, Packet}; -use valence_entity::hitbox::HitboxUpdateSet; -use crate::{Client, SpawnClientsSet}; +use crate::Client; pub(super) fn build(app: &mut App) { - app.configure_set( - RunEventLoopSet - .in_base_set(CoreSet::PreUpdate) - .after(SpawnClientsSet) - .after(HitboxUpdateSet), - ) - .add_system(run_event_loop.in_set(RunEventLoopSet)) - .add_event::(); - - // Add the event loop schedule. - let mut event_loop = Schedule::new(); - event_loop.set_default_base_set(EventLoopSet::Update); - event_loop.configure_sets(( - EventLoopSet::PreUpdate.before(EventLoopSet::Update), - EventLoopSet::Update.before(EventLoopSet::PostUpdate), - EventLoopSet::PostUpdate, - )); - - app.add_schedule(EventLoopSchedule, event_loop); + app.add_event::() + .add_schedule(RunEventLoop, Schedule::new()) + .add_schedule(EventLoopPreUpdate, Schedule::new()) + .add_schedule(EventLoopUpdate, Schedule::new()) + .add_schedule(EventLoopPostUpdate, Schedule::new()) + .add_systems(RunEventLoop, run_event_loop); + + app.world + .resource_mut::() + .insert_after(PreUpdate, RunEventLoop); } -/// The [`ScheduleLabel`] for the event loop [`Schedule`]. -#[derive(ScheduleLabel, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Debug)] -pub struct EventLoopSchedule; - -#[derive(SystemSet, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Debug)] -#[system_set(base)] -pub enum EventLoopSet { - PreUpdate, - #[default] - Update, - PostUpdate, -} +/// The schedule responsible for running [`EventLoopPreUpdate`], +/// [`EventLoopUpdate`], and [`EventLoopPostUpdate`]. +/// +/// This schedule is situated between [`PreUpdate`] and [`Update`]. +#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)] +pub struct RunEventLoop; + +#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)] +pub struct EventLoopPreUpdate; + +#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)] +pub struct EventLoopUpdate; -#[derive(SystemSet, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Debug)] -pub struct RunEventLoopSet; +#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)] +pub struct EventLoopPostUpdate; -#[derive(Clone, Debug)] +#[derive(Event, Clone, Debug)] pub struct PacketEvent { /// The client this packet originated from. pub client: Entity, @@ -98,6 +89,12 @@ impl PacketEvent { } } +fn run_event_loop_schedules(world: &mut World) { + world.run_schedule(EventLoopPreUpdate); + world.run_schedule(EventLoopUpdate); + world.run_schedule(EventLoopPostUpdate); +} + /// An exclusive system for running the event loop schedule. #[allow(clippy::type_complexity)] fn run_event_loop( @@ -139,7 +136,7 @@ fn run_event_loop( } state.apply(world); - world.run_schedule(EventLoopSchedule); + run_event_loop_schedules(world); while !check_again.is_empty() { let (mut clients, mut event_writer, mut commands) = state.get_mut(world); @@ -175,6 +172,6 @@ fn run_event_loop( }); state.apply(world); - world.run_schedule(EventLoopSchedule); + run_event_loop_schedules(world); } } diff --git a/crates/valence_client/src/hand_swing.rs b/crates/valence_client/src/hand_swing.rs index 86713508a..8c6ef45ba 100644 --- a/crates/valence_client/src/hand_swing.rs +++ b/crates/valence_client/src/hand_swing.rs @@ -4,17 +4,14 @@ use valence_core::hand::Hand; use valence_core::protocol::{packet_id, Decode, Encode, Packet}; use valence_entity::{EntityAnimation, EntityAnimations}; -use crate::event_loop::{EventLoopSchedule, EventLoopSet, PacketEvent}; +use crate::event_loop::{EventLoopPreUpdate, PacketEvent}; pub(super) fn build(app: &mut App) { - app.add_event::().add_system( - handle_hand_swing - .in_schedule(EventLoopSchedule) - .in_base_set(EventLoopSet::PreUpdate), - ); + app.add_event::() + .add_systems(EventLoopPreUpdate, handle_hand_swing); } -#[derive(Copy, Clone, PartialEq, Eq, Debug)] +#[derive(Event, Copy, Clone, PartialEq, Eq, Debug)] pub struct HandSwingEvent { pub client: Entity, pub hand: Hand, diff --git a/crates/valence_client/src/interact_block.rs b/crates/valence_client/src/interact_block.rs index 53d3ceabf..c2c9c36ed 100644 --- a/crates/valence_client/src/interact_block.rs +++ b/crates/valence_client/src/interact_block.rs @@ -8,17 +8,14 @@ use valence_core::protocol::var_int::VarInt; use valence_core::protocol::{packet_id, Decode, Encode, Packet}; use crate::action::ActionSequence; -use crate::event_loop::{EventLoopSchedule, EventLoopSet, PacketEvent}; +use crate::event_loop::{EventLoopPreUpdate, PacketEvent}; pub(super) fn build(app: &mut App) { - app.add_event::().add_system( - handle_interact_block - .in_schedule(EventLoopSchedule) - .in_base_set(EventLoopSet::PreUpdate), - ); + app.add_event::() + .add_systems(EventLoopPreUpdate, handle_interact_block); } -#[derive(Copy, Clone, Debug)] +#[derive(Event, Copy, Clone, Debug)] pub struct InteractBlockEvent { pub client: Entity, /// The hand that was used diff --git a/crates/valence_client/src/interact_entity.rs b/crates/valence_client/src/interact_entity.rs index 9593a9100..0c62b2ddf 100644 --- a/crates/valence_client/src/interact_entity.rs +++ b/crates/valence_client/src/interact_entity.rs @@ -6,17 +6,14 @@ use valence_core::protocol::var_int::VarInt; use valence_core::protocol::{packet_id, Decode, Encode, Packet}; use valence_entity::EntityManager; -use crate::event_loop::{EventLoopSchedule, EventLoopSet, PacketEvent}; +use crate::event_loop::{EventLoopPreUpdate, PacketEvent}; pub(super) fn build(app: &mut App) { - app.add_event::().add_system( - handle_interact_entity - .in_schedule(EventLoopSchedule) - .in_base_set(EventLoopSet::PreUpdate), - ); + app.add_event::() + .add_systems(EventLoopPreUpdate, handle_interact_entity); } -#[derive(Copy, Clone, Debug)] +#[derive(Event, Copy, Clone, Debug)] pub struct InteractEntityEvent { pub client: Entity, /// The entity being interacted with. diff --git a/crates/valence_client/src/interact_item.rs b/crates/valence_client/src/interact_item.rs index a2e23ec99..f265e7d9f 100644 --- a/crates/valence_client/src/interact_item.rs +++ b/crates/valence_client/src/interact_item.rs @@ -5,17 +5,14 @@ use valence_core::protocol::var_int::VarInt; use valence_core::protocol::{packet_id, Decode, Encode, Packet}; use crate::action::ActionSequence; -use crate::event_loop::{EventLoopSchedule, EventLoopSet, PacketEvent}; +use crate::event_loop::{EventLoopPreUpdate, PacketEvent}; pub(super) fn build(app: &mut App) { - app.add_event::().add_system( - handle_player_interact_item - .in_schedule(EventLoopSchedule) - .in_base_set(EventLoopSet::PreUpdate), - ); + app.add_event::() + .add_systems(EventLoopPreUpdate, handle_player_interact_item); } -#[derive(Copy, Clone, Debug)] +#[derive(Event, Copy, Clone, Debug)] pub struct InteractItemEvent { pub client: Entity, pub hand: Hand, diff --git a/crates/valence_client/src/keepalive.rs b/crates/valence_client/src/keepalive.rs index c903cec9e..6a5c5a6df 100644 --- a/crates/valence_client/src/keepalive.rs +++ b/crates/valence_client/src/keepalive.rs @@ -2,15 +2,11 @@ use valence_core::protocol::{packet_id, Decode, Encode, Packet}; use valence_core::CoreSettings; use super::*; -use crate::event_loop::{EventLoopSchedule, EventLoopSet, PacketEvent}; +use crate::event_loop::{EventLoopPreUpdate, PacketEvent}; pub(super) fn build(app: &mut App) { - app.add_system(send_keepalive.in_set(UpdateClientsSet)) - .add_system( - handle_keepalive_response - .in_base_set(EventLoopSet::PreUpdate) - .in_schedule(EventLoopSchedule), - ); + app.add_systems(PostUpdate, send_keepalive.in_set(UpdateClientsSet)) + .add_systems(EventLoopPreUpdate, handle_keepalive_response); } #[derive(Component, Debug)] diff --git a/crates/valence_client/src/lib.rs b/crates/valence_client/src/lib.rs index 55c6d9b66..18bb87027 100644 --- a/crates/valence_client/src/lib.rs +++ b/crates/valence_client/src/lib.rs @@ -93,18 +93,16 @@ pub mod weather; pub struct ClientPlugin; -/// When clients have their packet buffer flushed. Any system that writes -/// packets to clients should happen _before_ this. Otherwise, the data -/// will arrive one tick late. +/// The [`SystemSet`] in [`PostUpdate`] where clients have their packet buffer +/// flushed. Any system that writes packets to clients should happen _before_ +/// this. Otherwise, the data will arrive one tick late. #[derive(SystemSet, Copy, Clone, PartialEq, Eq, Hash, Debug)] pub struct FlushPacketsSet; -/// The [`SystemSet`] in [`CoreSet::PreUpdate`] where new clients should be +/// The [`SystemSet`] in [`PreUpdate`] where new clients should be /// spawned. Systems that need to perform initialization work on clients before -/// users get access to it should run _after_ this set in -/// [`CoreSet::PreUpdate`]. +/// users get access to it should run _after_ this set. #[derive(SystemSet, Copy, Clone, PartialEq, Eq, Hash, Debug)] - pub struct SpawnClientsSet; /// The system set where various facets of the client are updated. Systems that @@ -115,6 +113,7 @@ pub struct UpdateClientsSet; impl Plugin for ClientPlugin { fn build(&self, app: &mut App) { app.add_systems( + PostUpdate, ( initial_join.after(RegistrySet), update_chunk_load_dist, @@ -132,16 +131,17 @@ impl Plugin for ClientPlugin { ) .in_set(UpdateClientsSet), ) - .configure_sets(( - SpawnClientsSet.in_base_set(CoreSet::PreUpdate), - UpdateClientsSet - .in_base_set(CoreSet::PostUpdate) - .before(FlushPacketsSet), - ClearEntityChangesSet.after(UpdateClientsSet), - FlushPacketsSet.in_base_set(CoreSet::PostUpdate), - ClearInstanceChangesSet.after(FlushPacketsSet), - )) - .add_system(flush_packets.in_set(FlushPacketsSet)); + .add_systems(PostUpdate, flush_packets.in_set(FlushPacketsSet)) + .configure_set(PreUpdate, SpawnClientsSet) + .configure_sets( + PostUpdate, + ( + UpdateClientsSet.before(FlushPacketsSet), + ClearEntityChangesSet.after(UpdateClientsSet), + FlushPacketsSet, + ClearInstanceChangesSet.after(FlushPacketsSet), + ), + ); event_loop::build(app); movement::build(app); @@ -425,7 +425,7 @@ pub struct DisconnectClient { } impl Command for DisconnectClient { - fn write(self, world: &mut World) { + fn apply(self, world: &mut World) { if let Some(mut entity) = world.get_entity_mut(self.client) { if let Some(mut client) = entity.get_mut::() { client.write_packet(&DisconnectS2c { diff --git a/crates/valence_client/src/message.rs b/crates/valence_client/src/message.rs index 906bac8ce..f2bff1c49 100644 --- a/crates/valence_client/src/message.rs +++ b/crates/valence_client/src/message.rs @@ -6,14 +6,11 @@ use valence_core::protocol::encode::WritePacket; use valence_core::protocol::packet::chat::{ChatMessageC2s, GameMessageS2c}; use valence_core::text::Text; -use crate::event_loop::{EventLoopSchedule, EventLoopSet, PacketEvent}; +use crate::event_loop::{EventLoopPreUpdate, PacketEvent}; pub(super) fn build(app: &mut App) { - app.add_event::().add_system( - handle_chat_message - .in_schedule(EventLoopSchedule) - .in_base_set(EventLoopSet::PreUpdate), - ); + app.add_event::() + .add_systems(EventLoopPreUpdate, handle_chat_message); } pub trait SendMessage { @@ -39,7 +36,7 @@ impl SendMessage for T { } } -#[derive(Clone, Debug)] +#[derive(Event, Clone, Debug)] pub struct ChatMessageEvent { pub client: Entity, pub message: Box, diff --git a/crates/valence_client/src/movement.rs b/crates/valence_client/src/movement.rs index efe251016..76ddd2060 100644 --- a/crates/valence_client/src/movement.rs +++ b/crates/valence_client/src/movement.rs @@ -5,16 +5,12 @@ use valence_core::protocol::{packet_id, Decode, Encode, Packet}; use valence_entity::{HeadYaw, Look, OnGround, Position}; use super::teleport::TeleportState; -use crate::event_loop::{EventLoopSchedule, EventLoopSet, PacketEvent}; +use crate::event_loop::{EventLoopPreUpdate, PacketEvent}; pub(super) fn build(app: &mut App) { app.init_resource::() .add_event::() - .add_system( - handle_client_movement - .in_schedule(EventLoopSchedule) - .in_base_set(EventLoopSet::PreUpdate), - ); + .add_systems(EventLoopPreUpdate, handle_client_movement); } /// Configuration resource for client movement checks. @@ -24,7 +20,7 @@ pub struct MovementSettings { } /// Event sent when a client successfully moves. -#[derive(Clone, Debug)] +#[derive(Event, Clone, Debug)] pub struct MovementEvent { pub client: Entity, pub position: DVec3, diff --git a/crates/valence_client/src/op_level.rs b/crates/valence_client/src/op_level.rs index edbbf257c..7cf0ed5b4 100644 --- a/crates/valence_client/src/op_level.rs +++ b/crates/valence_client/src/op_level.rs @@ -3,7 +3,7 @@ use valence_entity::packet::EntityStatusS2c; use super::*; pub(super) fn build(app: &mut App) { - app.add_system(update_op_level.in_set(UpdateClientsSet)); + app.add_systems(PostUpdate, update_op_level.in_set(UpdateClientsSet)); } #[derive(Component, Clone, PartialEq, Eq, Default, Debug)] diff --git a/crates/valence_client/src/resource_pack.rs b/crates/valence_client/src/resource_pack.rs index 855dc2bfc..aeaee9bae 100644 --- a/crates/valence_client/src/resource_pack.rs +++ b/crates/valence_client/src/resource_pack.rs @@ -6,18 +6,15 @@ use valence_core::protocol::encode::WritePacket; use valence_core::protocol::{packet_id, Decode, Encode, Packet}; use valence_core::text::Text; -use crate::event_loop::{EventLoopSchedule, EventLoopSet, PacketEvent}; +use crate::event_loop::{EventLoopPreUpdate, PacketEvent}; use crate::Client; pub(super) fn build(app: &mut App) { - app.add_event::().add_system( - handle_resource_pack_status - .in_schedule(EventLoopSchedule) - .in_base_set(EventLoopSet::PreUpdate), - ); + app.add_event::() + .add_systems(EventLoopPreUpdate, handle_resource_pack_status); } -#[derive(Copy, Clone, PartialEq, Eq, Debug)] +#[derive(Event, Copy, Clone, PartialEq, Eq, Debug)] pub struct ResourcePackStatusEvent { pub client: Entity, pub status: ResourcePackStatus, diff --git a/crates/valence_client/src/settings.rs b/crates/valence_client/src/settings.rs index 1a6009fba..369dbccf8 100644 --- a/crates/valence_client/src/settings.rs +++ b/crates/valence_client/src/settings.rs @@ -4,15 +4,11 @@ use bitfield_struct::bitfield; use valence_core::protocol::{packet_id, Decode, Encode, Packet}; use valence_entity::player::{self, PlayerModelParts}; -use crate::event_loop::{EventLoopSchedule, EventLoopSet, PacketEvent}; +use crate::event_loop::{EventLoopPreUpdate, PacketEvent}; use crate::ViewDistance; pub(super) fn build(app: &mut App) { - app.add_system( - handle_client_settings - .in_schedule(EventLoopSchedule) - .in_base_set(EventLoopSet::PreUpdate), - ); + app.add_systems(EventLoopPreUpdate, handle_client_settings); } /// Component containing client-controlled settings about a client. diff --git a/crates/valence_client/src/status.rs b/crates/valence_client/src/status.rs index ba163c740..ec68232a6 100644 --- a/crates/valence_client/src/status.rs +++ b/crates/valence_client/src/status.rs @@ -2,23 +2,20 @@ use bevy_app::prelude::*; use bevy_ecs::prelude::*; use valence_core::protocol::{packet_id, Decode, Encode, Packet}; -use crate::event_loop::{EventLoopSchedule, EventLoopSet, PacketEvent}; +use crate::event_loop::{EventLoopPreUpdate, PacketEvent}; pub(super) fn build(app: &mut App) { app.add_event::() .add_event::() - .add_system( - handle_status - .in_schedule(EventLoopSchedule) - .in_base_set(EventLoopSet::PreUpdate), - ); + .add_systems(EventLoopPreUpdate, handle_status); } -#[derive(Copy, Clone, PartialEq, Eq, Debug)] +#[derive(Event, Copy, Clone, PartialEq, Eq, Debug)] pub struct RequestRespawnEvent { pub client: Entity, } +#[derive(Event, Copy, Clone, PartialEq, Eq, Debug)] pub struct RequestStatsEvent { pub client: Entity, } diff --git a/crates/valence_client/src/teleport.rs b/crates/valence_client/src/teleport.rs index fb8a8cddd..7db6ebf4d 100644 --- a/crates/valence_client/src/teleport.rs +++ b/crates/valence_client/src/teleport.rs @@ -4,15 +4,14 @@ use valence_core::protocol::var_int::VarInt; use valence_core::protocol::{packet_id, Decode, Encode, Packet}; use super::*; -use crate::event_loop::{EventLoopSchedule, EventLoopSet, PacketEvent}; +use crate::event_loop::{EventLoopPreUpdate, PacketEvent}; pub(super) fn build(app: &mut App) { - app.add_system(teleport.after(update_view).in_set(UpdateClientsSet)) - .add_system( - handle_teleport_confirmations - .in_schedule(EventLoopSchedule) - .in_base_set(EventLoopSet::PreUpdate), - ); + app.add_systems( + PostUpdate, + teleport.after(update_view).in_set(UpdateClientsSet), + ) + .add_systems(EventLoopPreUpdate, handle_teleport_confirmations); } #[derive(Component, Debug)] diff --git a/crates/valence_client/src/weather.rs b/crates/valence_client/src/weather.rs index 045c7071b..2f0ce9788 100644 --- a/crates/valence_client/src/weather.rs +++ b/crates/valence_client/src/weather.rs @@ -25,43 +25,38 @@ struct UpdateWeatherPerInstanceSet; struct UpdateWeatherPerClientSet; pub(super) fn build(app: &mut App) { - app.configure_set( - UpdateWeatherPerInstanceSet - .in_base_set(CoreSet::PostUpdate) - .before(WriteUpdatePacketsToInstancesSet), - ) - .configure_set( - UpdateWeatherPerClientSet - .in_base_set(CoreSet::PostUpdate) - .before(FlushPacketsSet), + app.configure_sets( + PostUpdate, + (UpdateWeatherPerInstanceSet, UpdateWeatherPerClientSet).before(FlushPacketsSet), ) .add_systems( + PostUpdate, ( - handle_rain_begin_per_instance, - handle_rain_change_per_instance, - handle_rain_end_per_instance, - handle_thunder_change_per_instance, - handle_thunder_end_per_instance, + rain_begin_per_instance, + rain_change_per_instance, + rain_end_per_instance, + thunder_change_per_instance, + thunder_end_per_instance, ) .chain() .in_set(UpdateWeatherPerInstanceSet) .before(UpdateWeatherPerClientSet), ) .add_systems( + PostUpdate, ( - handle_rain_begin_per_client, - handle_rain_change_per_client, - handle_rain_end_per_client, - handle_thunder_change_per_client, - handle_thunder_end_per_client, + rain_begin_per_client, + rain_change_per_client, + rain_end_per_client, + thunder_change_per_client, + thunder_end_per_client, ) .chain() .in_set(UpdateWeatherPerClientSet), ) - .add_system( - handle_weather_for_joined_player - .before(UpdateWeatherPerClientSet) - .in_base_set(CoreSet::PostUpdate), + .add_systems( + PostUpdate, + handle_weather_for_joined_player.before(UpdateWeatherPerClientSet), ); } @@ -105,7 +100,7 @@ fn handle_weather_for_joined_player( } } -fn handle_rain_begin_per_instance(mut instances: Query<&mut Instance, Added>) { +fn rain_begin_per_instance(mut instances: Query<&mut Instance, Added>) { for mut instance in &mut instances { instance.write_packet(&GameStateChangeS2c { kind: GameEventKind::BeginRaining, @@ -114,7 +109,7 @@ fn handle_rain_begin_per_instance(mut instances: Query<&mut Instance, Added>) { +fn rain_change_per_instance(mut instances: Query<(&mut Instance, &Rain), Changed>) { for (mut instance, rain) in &mut instances { instance.write_packet(&GameStateChangeS2c { kind: GameEventKind::RainLevelChange, @@ -123,7 +118,7 @@ fn handle_rain_change_per_instance(mut instances: Query<(&mut Instance, &Rain), } } -fn handle_rain_end_per_instance( +fn rain_end_per_instance( mut instances: Query<&mut Instance>, mut removed: RemovedComponents, ) { @@ -137,9 +132,7 @@ fn handle_rain_end_per_instance( } } -fn handle_thunder_change_per_instance( - mut instances: Query<(&mut Instance, &Thunder), Changed>, -) { +fn thunder_change_per_instance(mut instances: Query<(&mut Instance, &Thunder), Changed>) { for (mut instance, thunder) in &mut instances { instance.write_packet(&GameStateChangeS2c { kind: GameEventKind::ThunderLevelChange, @@ -148,7 +141,7 @@ fn handle_thunder_change_per_instance( } } -fn handle_thunder_end_per_instance( +fn thunder_end_per_instance( mut instances: Query<&mut Instance>, mut removed: RemovedComponents, ) { @@ -162,7 +155,7 @@ fn handle_thunder_end_per_instance( } } -fn handle_rain_begin_per_client(mut clients: Query<&mut Client, (Added, Without)>) { +fn rain_begin_per_client(mut clients: Query<&mut Client, (Added, Without)>) { for mut client in &mut clients { client.write_packet(&GameStateChangeS2c { kind: GameEventKind::BeginRaining, @@ -172,7 +165,7 @@ fn handle_rain_begin_per_client(mut clients: Query<&mut Client, (Added, Wi } #[allow(clippy::type_complexity)] -fn handle_rain_change_per_client( +fn rain_change_per_client( mut clients: Query<(&mut Client, &Rain), (Changed, Without)>, ) { for (mut client, rain) in &mut clients { @@ -183,10 +176,7 @@ fn handle_rain_change_per_client( } } -fn handle_rain_end_per_client( - mut clients: Query<&mut Client>, - mut removed: RemovedComponents, -) { +fn rain_end_per_client(mut clients: Query<&mut Client>, mut removed: RemovedComponents) { for entity in &mut removed { if let Ok(mut client) = clients.get_mut(entity) { client.write_packet(&GameStateChangeS2c { @@ -198,7 +188,7 @@ fn handle_rain_end_per_client( } #[allow(clippy::type_complexity)] -fn handle_thunder_change_per_client( +fn thunder_change_per_client( mut clients: Query<(&mut Client, &Thunder), (Changed, Without)>, ) { for (mut client, thunder) in &mut clients { @@ -209,7 +199,7 @@ fn handle_thunder_change_per_client( } } -fn handle_thunder_end_per_client( +fn thunder_end_per_client( mut clients: Query<&mut Client, Without>, mut removed: RemovedComponents, ) { diff --git a/crates/valence_core/src/lib.rs b/crates/valence_core/src/lib.rs index dddb56d0a..dc5857727 100644 --- a/crates/valence_core/src/lib.rs +++ b/crates/valence_core/src/lib.rs @@ -41,7 +41,7 @@ use std::num::NonZeroU32; use std::time::Duration; use bevy_app::prelude::*; -use bevy_app::{ScheduleRunnerPlugin, ScheduleRunnerSettings}; +use bevy_app::ScheduleRunnerPlugin; use bevy_ecs::prelude::*; use crate::despawn::despawn_marked_entities; @@ -88,16 +88,13 @@ impl Plugin for CorePlugin { let tick_period = Duration::from_secs_f64((tick_rate.get() as f64).recip()); // Make the app loop forever at the configured TPS. - app.insert_resource(ScheduleRunnerSettings::run_loop(tick_period)) - .add_plugin(ScheduleRunnerPlugin); + app.add_plugin(ScheduleRunnerPlugin::run_loop(tick_period)); fn increment_tick_counter(mut server: ResMut) { server.current_tick += 1; } - app.add_systems( - (increment_tick_counter, despawn_marked_entities).in_base_set(CoreSet::Last), - ); + app.add_systems(Last, (increment_tick_counter, despawn_marked_entities)); } } diff --git a/crates/valence_dimension/src/lib.rs b/crates/valence_dimension/src/lib.rs index 579ec7ab3..9c352e128 100644 --- a/crates/valence_dimension/src/lib.rs +++ b/crates/valence_dimension/src/lib.rs @@ -34,11 +34,10 @@ pub struct DimensionPlugin; impl Plugin for DimensionPlugin { fn build(&self, app: &mut App) { app.init_resource::() - .add_startup_system(load_default_dimension_types.in_base_set(StartupSet::PreStartup)) - .add_system( - update_dimension_type_registry - .in_base_set(CoreSet::PostUpdate) - .before(RegistrySet), + .add_systems(PreStartup, load_default_dimension_types) + .add_systems( + PostUpdate, + update_dimension_type_registry.before(RegistrySet), ); } } diff --git a/crates/valence_entity/build.rs b/crates/valence_entity/build.rs index 80ae7d68f..967627708 100644 --- a/crates/valence_entity/build.rs +++ b/crates/valence_entity/build.rs @@ -597,7 +597,8 @@ fn build() -> anyhow::Result { #systems #( - app.add_system( + app.add_systems( + PostUpdate, #system_names .in_set(UpdateTrackedDataSet) .ambiguous_with(UpdateTrackedDataSet) diff --git a/crates/valence_entity/src/hitbox.rs b/crates/valence_entity/src/hitbox.rs index ae6fc5f7b..b74dd348a 100644 --- a/crates/valence_entity/src/hitbox.rs +++ b/crates/valence_entity/src/hitbox.rs @@ -1,10 +1,7 @@ #![allow(clippy::type_complexity)] -use bevy_app::{App, CoreSet, Plugin}; -use bevy_ecs::prelude::{Component, Entity, SystemSet}; -use bevy_ecs::query::{Added, Changed, Or, With}; -use bevy_ecs::schedule::{IntoSystemConfig, IntoSystemConfigs, IntoSystemSetConfig}; -use bevy_ecs::system::{Commands, Query}; +use bevy_app::prelude::*; +use bevy_ecs::prelude::*; use glam::{DVec3, UVec3, Vec3Swizzles}; use valence_core::aabb::Aabb; use valence_core::direction::Direction; @@ -42,8 +39,9 @@ impl Default for EntityHitboxSettings { impl Plugin for HitboxPlugin { fn build(&self, app: &mut App) { app.init_resource::() - .configure_set(HitboxShapeUpdateSet.in_base_set(CoreSet::PreUpdate)) + .configure_set(PreUpdate, HitboxShapeUpdateSet) .add_systems( + PreUpdate, ( update_constant_hitbox, update_warden_hitbox, @@ -58,17 +56,15 @@ impl Plugin for HitboxPlugin { update_slime_hitbox, update_painting_hitbox, update_shulker_hitbox, - ) - .in_set(HitboxShapeUpdateSet), + ), ) - .configure_set(HitboxComponentsAddSet.in_base_set(CoreSet::PostUpdate)) - .add_system(add_hitbox_component.in_set(HitboxComponentsAddSet)) - .configure_set( - HitboxUpdateSet - .in_base_set(CoreSet::PreUpdate) - .after(HitboxShapeUpdateSet), + .configure_set(PostUpdate, HitboxComponentsAddSet) + .add_systems( + PostUpdate, + add_hitbox_component.in_set(HitboxComponentsAddSet), ) - .add_system(update_hitbox.in_set(HitboxUpdateSet)); + .configure_set(PreUpdate, HitboxUpdateSet.after(HitboxShapeUpdateSet)) + .add_systems(PreUpdate, update_hitbox.in_set(HitboxUpdateSet)); } } diff --git a/crates/valence_entity/src/lib.rs b/crates/valence_entity/src/lib.rs index da921af6f..ce55e46cc 100644 --- a/crates/valence_entity/src/lib.rs +++ b/crates/valence_entity/src/lib.rs @@ -23,7 +23,7 @@ pub mod packet; use std::num::Wrapping; use std::ops::Range; -use bevy_app::{App, CoreSet, Plugin}; +use bevy_app::prelude::*; use bevy_ecs::prelude::*; use glam::{DVec3, Vec3}; use paste::paste; @@ -45,11 +45,15 @@ pub struct EntityPlugin; /// /// Systems that need Minecraft entities to be in a valid state should run /// _after_ this set. +/// +/// This set lives in [`PostUpdate`]. #[derive(SystemSet, Copy, Clone, PartialEq, Eq, Hash, Debug)] pub struct InitEntitiesSet; /// When tracked data is written to the entity's [`TrackedData`] component. /// Systems that modify tracked data should run _before_ this. +/// +/// This set lives in [`PostUpdate`]. #[derive(SystemSet, Copy, Clone, PartialEq, Eq, Hash, Debug)] pub struct UpdateTrackedDataSet; @@ -57,26 +61,32 @@ pub struct UpdateTrackedDataSet; /// Systems that need to observe changes to entities (Such as the difference /// between [`Position`] and [`OldPosition`]) should run _before_ this set (and /// probably after [`InitEntitiesSet`]). +/// +/// This set lives in [`PostUpdate`]. #[derive(SystemSet, Copy, Clone, PartialEq, Eq, Hash, Debug)] pub struct ClearEntityChangesSet; impl Plugin for EntityPlugin { fn build(&self, app: &mut App) { app.insert_resource(EntityManager::new()) - .configure_sets(( - InitEntitiesSet.in_base_set(CoreSet::PostUpdate), - UpdateTrackedDataSet.in_base_set(CoreSet::PostUpdate), - ClearEntityChangesSet - .after(InitEntitiesSet) - .after(UpdateTrackedDataSet) - .in_base_set(CoreSet::PostUpdate), - )) + .configure_sets( + PostUpdate, + ( + InitEntitiesSet, + UpdateTrackedDataSet, + ClearEntityChangesSet + .after(InitEntitiesSet) + .after(UpdateTrackedDataSet), + ), + ) .add_systems( + PostUpdate, (init_entities, remove_despawned_from_manager) .chain() .in_set(InitEntitiesSet), ) .add_systems( + PostUpdate, ( clear_status_changes, clear_animation_changes, diff --git a/crates/valence_instance/src/lib.rs b/crates/valence_instance/src/lib.rs index 4d4301061..fe5fd96d7 100644 --- a/crates/valence_instance/src/lib.rs +++ b/crates/valence_instance/src/lib.rs @@ -66,41 +66,48 @@ pub struct InstancePlugin; /// When Minecraft entity changes are written to the packet buffers of chunks. /// Systems that modify entites should run _before_ this. Systems that read from /// the packet buffer of chunks should run _after_ this. +/// +/// This set lives in [`PostUpdate`]. #[derive(SystemSet, Copy, Clone, PartialEq, Eq, Hash, Debug)] pub struct WriteUpdatePacketsToInstancesSet; /// When instances are updated and changes from the current tick are cleared. /// Systems that read changes from instances should run _before_ this. +/// +/// This set lives in [`PostUpdate`]. #[derive(SystemSet, Copy, Clone, PartialEq, Eq, Hash, Debug)] pub struct ClearInstanceChangesSet; impl Plugin for InstancePlugin { fn build(&self, app: &mut App) { - app.configure_sets(( - WriteUpdatePacketsToInstancesSet - .in_base_set(CoreSet::PostUpdate) - .after(InitEntitiesSet) - .after(UpdateTrackedDataSet), - ClearInstanceChangesSet - .after(WriteUpdatePacketsToInstancesSet) - .in_base_set(CoreSet::PostUpdate), - )) - .add_system( + app.configure_sets( + PostUpdate, + ( + WriteUpdatePacketsToInstancesSet + .after(InitEntitiesSet) + .after(UpdateTrackedDataSet), + ClearInstanceChangesSet.after(WriteUpdatePacketsToInstancesSet), + ), + ) + .add_systems( + PostUpdate, // This can run at the same time as entity init because we're only looking at position // + location. - update_entity_cell_positions - .in_base_set(CoreSet::PostUpdate) - .before(WriteUpdatePacketsToInstancesSet), + update_entity_cell_positions.before(WriteUpdatePacketsToInstancesSet), ) - .add_system( + .add_systems( + PostUpdate, write_update_packets_to_instances .after(update_entity_cell_positions) .in_set(WriteUpdatePacketsToInstancesSet), ) - .add_system(clear_instance_changes.in_set(ClearInstanceChangesSet)); + .add_systems( + PostUpdate, + clear_instance_changes.in_set(ClearInstanceChangesSet), + ); #[cfg(debug_assertions)] - app.add_system(check_instance_invariants.in_base_set(CoreSet::PostUpdate)); + app.add_systems(PostUpdate, check_instance_invariants); } } diff --git a/crates/valence_inventory/src/lib.rs b/crates/valence_inventory/src/lib.rs index cbda36c2b..f9fecc27f 100644 --- a/crates/valence_inventory/src/lib.rs +++ b/crates/valence_inventory/src/lib.rs @@ -31,7 +31,7 @@ use packet::{ WindowType, }; use tracing::{debug, warn}; -use valence_client::event_loop::{EventLoopSchedule, EventLoopSet, PacketEvent, RunEventLoopSet}; +use valence_client::event_loop::{EventLoopPreUpdate, PacketEvent}; use valence_client::packet::{PlayerAction, PlayerActionC2s}; use valence_client::{Client, FlushPacketsSet, SpawnClientsSet}; use valence_core::game_mode::GameMode; @@ -47,37 +47,34 @@ pub struct InventoryPlugin; impl Plugin for InventoryPlugin { fn build(&self, app: &mut bevy_app::App) { - app.add_system( - init_new_client_inventories - .in_base_set(CoreSet::PreUpdate) - .after(SpawnClientsSet) - .before(RunEventLoopSet), + app.add_systems( + PreUpdate, + init_new_client_inventories.after(SpawnClientsSet), ) .add_systems( + PostUpdate, ( update_open_inventories, update_client_on_close_inventory.after(update_open_inventories), update_player_inventories, ) - .in_base_set(CoreSet::PostUpdate) .before(FlushPacketsSet), ) .add_systems( + EventLoopPreUpdate, ( handle_update_selected_slot, handle_click_slot, handle_creative_inventory_action, handle_close_handled_screen, handle_player_actions, - ) - .in_base_set(EventLoopSet::PreUpdate) - .in_schedule(EventLoopSchedule), + ), ) .init_resource::() - .add_event::() - .add_event::() - .add_event::() - .add_event::(); + .add_event::() + .add_event::() + .add_event::() + .add_event::(); } } @@ -745,8 +742,8 @@ fn update_client_on_close_inventory( } // TODO: make this event user friendly. -#[derive(Clone, Debug)] -pub struct ClickSlot { +#[derive(Event, Clone, Debug)] +pub struct ClickSlotEvent { pub client: Entity, pub window_id: u8, pub state_id: i32, @@ -757,8 +754,8 @@ pub struct ClickSlot { pub carried_item: Option, } -#[derive(Clone, Debug)] -pub struct DropItemStack { +#[derive(Event, Clone, Debug)] +pub struct DropItemStackEvent { pub client: Entity, pub from_slot: Option, pub stack: ItemStack, @@ -774,8 +771,8 @@ fn handle_click_slot( &mut CursorItem, )>, mut inventories: Query<&mut Inventory, Without>, - mut drop_item_stack_events: EventWriter, - mut click_slot_events: EventWriter, + mut drop_item_stack_events: EventWriter, + mut click_slot_events: EventWriter, ) { for packet in packets.iter() { let Some(pkt) = packet.decode::() else { @@ -829,7 +826,7 @@ fn handle_click_slot( // The client is dropping the cursor item by clicking outside the window. if let Some(stack) = cursor_item.0.take() { - drop_item_stack_events.send(DropItemStack { + drop_item_stack_events.send(DropItemStackEvent { client: packet.client, from_slot: None, stack, @@ -885,7 +882,7 @@ fn handle_click_slot( } .expect("dropped item should exist"); // we already checked that the slot was not empty - drop_item_stack_events.send(DropItemStack { + drop_item_stack_events.send(DropItemStackEvent { client: packet.client, from_slot: Some(pkt.slot_idx as u16), stack: dropped, @@ -909,7 +906,7 @@ fn handle_click_slot( } .expect("dropped item should exist"); // we already checked that the slot was not empty - drop_item_stack_events.send(DropItemStack { + drop_item_stack_events.send(DropItemStackEvent { client: packet.client, from_slot: Some(slot_id), stack: dropped, @@ -934,7 +931,7 @@ fn handle_click_slot( } .expect("dropped item should exist"); // we already checked that the slot was not empty - drop_item_stack_events.send(DropItemStack { + drop_item_stack_events.send(DropItemStackEvent { client: packet.client, from_slot: Some(pkt.slot_idx as u16), stack: dropped, @@ -1033,7 +1030,7 @@ fn handle_click_slot( } } - click_slot_events.send(ClickSlot { + click_slot_events.send(ClickSlotEvent { client: packet.client, window_id: pkt.window_id, state_id: pkt.state_id.0, @@ -1050,7 +1047,7 @@ fn handle_click_slot( fn handle_player_actions( mut packets: EventReader, mut clients: Query<(&mut Inventory, &mut ClientInventoryState, &HeldItem)>, - mut drop_item_stack_events: EventWriter, + mut drop_item_stack_events: EventWriter, ) { for packet in packets.iter() { if let Some(pkt) = packet.decode::() { @@ -1060,7 +1057,7 @@ fn handle_player_actions( if let Some(stack) = inv.replace_slot(held.slot(), None) { inv_state.slots_changed |= 1 << held.slot(); - drop_item_stack_events.send(DropItemStack { + drop_item_stack_events.send(DropItemStackEvent { client: packet.client, from_slot: Some(held.slot()), stack, @@ -1082,7 +1079,7 @@ fn handle_player_actions( inv_state.slots_changed |= 1 << held.slot(); - drop_item_stack_events.send(DropItemStack { + drop_item_stack_events.send(DropItemStackEvent { client: packet.client, from_slot: Some(held.slot()), stack, @@ -1100,8 +1097,8 @@ fn handle_player_actions( } // TODO: make this event user friendly. -#[derive(Clone, Debug)] -pub struct CreativeInventoryAction { +#[derive(Event, Clone, Debug)] +pub struct CreativeInventoryActionEvent { pub client: Entity, pub slot: i16, pub clicked_item: Option, @@ -1115,8 +1112,8 @@ fn handle_creative_inventory_action( &mut ClientInventoryState, &GameMode, )>, - mut inv_action_events: EventWriter, - mut drop_item_stack_events: EventWriter, + mut inv_action_events: EventWriter, + mut drop_item_stack_events: EventWriter, ) { for packet in packets.iter() { if let Some(pkt) = packet.decode::() { @@ -1131,7 +1128,7 @@ fn handle_creative_inventory_action( if pkt.slot == -1 { if let Some(stack) = pkt.clicked_item.clone() { - drop_item_stack_events.send(DropItemStack { + drop_item_stack_events.send(DropItemStackEvent { client: packet.client, from_slot: None, stack, @@ -1161,7 +1158,7 @@ fn handle_creative_inventory_action( slot_data: Cow::Borrowed(&pkt.clicked_item), }); - inv_action_events.send(CreativeInventoryAction { + inv_action_events.send(CreativeInventoryActionEvent { client: packet.client, slot: pkt.slot, clicked_item: pkt.clicked_item, @@ -1170,8 +1167,8 @@ fn handle_creative_inventory_action( } } -#[derive(Clone, Debug)] -pub struct UpdateSelectedSlot { +#[derive(Event, Clone, Debug)] +pub struct UpdateSelectedSlotEvent { pub client: Entity, pub slot: i16, } @@ -1179,7 +1176,7 @@ pub struct UpdateSelectedSlot { fn handle_update_selected_slot( mut packets: EventReader, mut clients: Query<&mut HeldItem>, - mut events: EventWriter, + mut events: EventWriter, ) { for packet in packets.iter() { if let Some(pkt) = packet.decode::() { @@ -1190,7 +1187,7 @@ fn handle_update_selected_slot( } held.held_item_slot = convert_hotbar_slot_id(pkt.slot as u16); - events.send(UpdateSelectedSlot { + events.send(UpdateSelectedSlotEvent { client: packet.client, slot: pkt.slot, }); diff --git a/crates/valence_network/src/lib.rs b/crates/valence_network/src/lib.rs index 73784629b..70e271d17 100644 --- a/crates/valence_network/src/lib.rs +++ b/crates/valence_network/src/lib.rs @@ -126,14 +126,10 @@ fn build_plugin(app: &mut App) -> anyhow::Result<()> { // Start accepting connections in `PostStartup` to allow user startup code to // run first. - app.add_system( - start_accept_loop - .in_schedule(CoreSchedule::Startup) - .in_base_set(StartupSet::PostStartup), - ); + app.add_systems(PostStartup, start_accept_loop); // Spawn new clients before the event loop starts. - app.add_system(spawn_new_clients.in_set(SpawnClientsSet)); + app.add_systems(PreUpdate, spawn_new_clients.in_set(SpawnClientsSet)); Ok(()) } diff --git a/crates/valence_player_list/src/lib.rs b/crates/valence_player_list/src/lib.rs index 0ed91ffd5..fb22ab144 100644 --- a/crates/valence_player_list/src/lib.rs +++ b/crates/valence_player_list/src/lib.rs @@ -46,24 +46,24 @@ struct PlayerListSet; impl Plugin for PlayerListPlugin { fn build(&self, app: &mut App) { app.insert_resource(PlayerList::new()) + .configure_set( + PostUpdate, + // Needs to happen before player entities are initialized. Otherwise, they will + // appear invisible. + PlayerListSet.before(WriteUpdatePacketsToInstancesSet), + ) .add_systems( + PostUpdate, ( update_header_footer, add_new_clients_to_player_list, - apply_system_buffers, // So new clients get the packets for their own entry. + apply_deferred, // So new clients get the packets for their own entry. update_entries, init_player_list_for_clients, remove_despawned_entries, write_player_list_changes, ) - .chain() - .in_set(PlayerListSet), - ) - .configure_set( - PlayerListSet - .in_base_set(CoreSet::PostUpdate) - // Needs to happen before player entities are initialized. Otherwise, they will appear invisible. - .before(WriteUpdatePacketsToInstancesSet), + .chain(), ); } } diff --git a/crates/valence_registry/src/codec.rs b/crates/valence_registry/src/codec.rs index 0627c873a..c53da1e4b 100644 --- a/crates/valence_registry/src/codec.rs +++ b/crates/valence_registry/src/codec.rs @@ -10,7 +10,7 @@ use crate::RegistrySet; pub(super) fn build(app: &mut App) { app.init_resource::() - .add_system(cache_registry_codec.in_set(RegistrySet)); + .add_systems(PostUpdate, cache_registry_codec.in_set(RegistrySet)); } /// Contains the registry codec sent to all players while joining. This contains diff --git a/crates/valence_registry/src/lib.rs b/crates/valence_registry/src/lib.rs index b0855cb5d..bff49bbea 100644 --- a/crates/valence_registry/src/lib.rs +++ b/crates/valence_registry/src/lib.rs @@ -36,12 +36,14 @@ pub struct RegistryPlugin; /// The [`SystemSet`] where the [`RegistryCodec`](codec::RegistryCodec) and /// [`TagsRegistry`](tags::TagsRegistry) caches are rebuilt. Systems that modify /// the registry codec or tags registry should run _before_ this. +/// +/// This set lives in [`PostUpdate`]. #[derive(SystemSet, Copy, Clone, PartialEq, Eq, Hash, Debug)] pub struct RegistrySet; impl Plugin for RegistryPlugin { fn build(&self, app: &mut bevy_app::App) { - app.configure_set(RegistrySet.in_base_set(CoreSet::PostUpdate)); + app.configure_set(PostUpdate, RegistrySet); codec::build(app); tags::build(app); diff --git a/crates/valence_registry/src/tags.rs b/crates/valence_registry/src/tags.rs index 631ac29c6..cfa4dccb3 100644 --- a/crates/valence_registry/src/tags.rs +++ b/crates/valence_registry/src/tags.rs @@ -13,8 +13,8 @@ use crate::RegistrySet; pub(super) fn build(app: &mut App) { app.init_resource::() - .add_startup_system(init_tags_registry) - .add_system(cache_tags_packet.in_set(RegistrySet)); + .add_systems(PreStartup, init_tags_registry) + .add_systems(PostUpdate, cache_tags_packet.in_set(RegistrySet)); } #[derive(Clone, Debug, Encode, Decode, Packet)] diff --git a/crates/valence_world_border/src/lib.rs b/crates/valence_world_border/src/lib.rs index 59b23d1e0..480f93eba 100644 --- a/crates/valence_world_border/src/lib.rs +++ b/crates/valence_world_border/src/lib.rs @@ -70,7 +70,7 @@ pub mod packet; use std::time::{Duration, Instant}; -use bevy_app::{App, CoreSet, Plugin}; +use bevy_app::prelude::*; use glam::DVec2; use packet::*; use valence_client::{Client, FlushPacketsSet}; @@ -97,30 +97,31 @@ pub struct WorldBorderPlugin; impl Plugin for WorldBorderPlugin { fn build(&self, app: &mut App) { - app.configure_set( - UpdateWorldBorderPerInstanceSet - .in_base_set(CoreSet::PostUpdate) - .before(WriteUpdatePacketsToInstancesSet), - ) - .configure_set( - UpdateWorldBorderPerClientSet - .in_base_set(CoreSet::PostUpdate) - .before(FlushPacketsSet), + app.configure_sets( + PostUpdate, + ( + UpdateWorldBorderPerInstanceSet.before(WriteUpdatePacketsToInstancesSet), + UpdateWorldBorderPerClientSet.before(FlushPacketsSet), + ), ) .add_event::() .add_systems( + PostUpdate, ( - handle_wb_size_change.before(handle_diameter_change), - handle_diameter_change, - handle_lerp_transition, - handle_center_change, - handle_warn_time_change, - handle_warn_blocks_change, - handle_portal_teleport_bounary_change, + wb_size_change.before(diameter_change), + diameter_change, + lerp_transition, + center_change, + warn_time_change, + warn_blocks_change, + portal_teleport_bounary_change, ) .in_set(UpdateWorldBorderPerInstanceSet), ) - .add_system(handle_border_for_player.in_set(UpdateWorldBorderPerClientSet)); + .add_systems( + PostUpdate, + border_for_player.in_set(UpdateWorldBorderPerClientSet), + ); } } @@ -232,6 +233,7 @@ impl MovingWorldBorder { /// }) /// } /// ``` +#[derive(Event, Clone, Debug)] pub struct SetWorldBorderSizeEvent { /// The instance to change border size. Note that this instance must contain /// the [`WorldBorderBundle`] bundle @@ -243,7 +245,7 @@ pub struct SetWorldBorderSizeEvent { pub duration: Duration, } -fn handle_wb_size_change( +fn wb_size_change( mut events: EventReader, mut instances: Query<(&WorldBorderDiameter, Option<&mut MovingWorldBorder>)>, ) { @@ -266,7 +268,7 @@ fn handle_wb_size_change( } } -fn handle_border_for_player( +fn border_for_player( mut clients: Query<(&mut Client, &Location), Changed>, wbs: Query< ( @@ -302,7 +304,7 @@ fn handle_border_for_player( } } -fn handle_diameter_change( +fn diameter_change( mut wbs: Query<(&mut Instance, &MovingWorldBorder), Changed>, ) { for (mut ins, lerping) in wbs.iter_mut() { @@ -320,7 +322,7 @@ fn handle_diameter_change( } } -fn handle_lerp_transition(mut wbs: Query<(&mut WorldBorderDiameter, &MovingWorldBorder)>) { +fn lerp_transition(mut wbs: Query<(&mut WorldBorderDiameter, &MovingWorldBorder)>) { for (mut diameter, moving_wb) in wbs.iter_mut() { if diameter.0 != moving_wb.new_diameter { diameter.0 = moving_wb.current_diameter(); @@ -328,9 +330,7 @@ fn handle_lerp_transition(mut wbs: Query<(&mut WorldBorderDiameter, &MovingWorld } } -fn handle_center_change( - mut wbs: Query<(&mut Instance, &WorldBorderCenter), Changed>, -) { +fn center_change(mut wbs: Query<(&mut Instance, &WorldBorderCenter), Changed>) { for (mut ins, center) in wbs.iter_mut() { ins.write_packet(&WorldBorderCenterChangedS2c { x_pos: center.0.x, @@ -339,7 +339,7 @@ fn handle_center_change( } } -fn handle_warn_time_change( +fn warn_time_change( mut wb_query: Query<(&mut Instance, &WorldBorderWarnTime), Changed>, ) { for (mut ins, wt) in wb_query.iter_mut() { @@ -349,7 +349,7 @@ fn handle_warn_time_change( } } -fn handle_warn_blocks_change( +fn warn_blocks_change( mut wb_query: Query<(&mut Instance, &WorldBorderWarnBlocks), Changed>, ) { for (mut ins, wb) in wb_query.iter_mut() { @@ -359,7 +359,7 @@ fn handle_warn_blocks_change( } } -fn handle_portal_teleport_bounary_change( +fn portal_teleport_bounary_change( mut wbs: Query< ( &mut Instance, diff --git a/examples/advancement.rs b/examples/advancement.rs index 436992cb9..516da2c64 100644 --- a/examples/advancement.rs +++ b/examples/advancement.rs @@ -26,17 +26,18 @@ fn main() { App::new() .add_plugins(DefaultPlugins) .init_resource::() - .add_startup_system(setup) - .add_systems(( - load_clients, - apply_system_buffers - .after(load_clients) - .before(init_advancements), - init_clients, - init_advancements, - sneak, - tab_change, - )) + .add_systems(Startup, setup) + .add_systems( + Update, + ( + load_clients, + apply_deferred.after(load_clients).before(init_advancements), + init_clients, + init_advancements, + sneak, + tab_change, + ), + ) .run(); } @@ -251,7 +252,7 @@ fn sneak( } fn tab_change( - mut tab_change: EventReader, + mut tab_change: EventReader, mut client: Query<(&mut AdvancementClientUpdate, &mut TabChangeCount)>, root2_criteria: Query>, root: Query>, diff --git a/examples/anvil_loading.rs b/examples/anvil_loading.rs index f79fdb3d2..41dd444f9 100644 --- a/examples/anvil_loading.rs +++ b/examples/anvil_loading.rs @@ -35,10 +35,15 @@ pub fn main() { App::new() .add_plugins(DefaultPlugins) .insert_resource(cli) - .add_startup_system(setup) - .add_system(despawn_disconnected_clients) - .add_systems((init_clients, handle_chunk_loads).chain()) - .add_system(display_loaded_chunk_count) + .add_systems(Startup, setup) + .add_systems( + Update, + ( + despawn_disconnected_clients, + (init_clients, handle_chunk_loads).chain(), + display_loaded_chunk_count, + ), + ) .run(); } diff --git a/examples/bench_players.rs b/examples/bench_players.rs index d337b8f2f..1e2bdf1f3 100644 --- a/examples/bench_players.rs +++ b/examples/bench_players.rs @@ -24,13 +24,10 @@ fn main() { ..Default::default() }) .add_plugins(DefaultPlugins) - .add_startup_system(setup) - .add_systems(( - record_tick_start_time.in_base_set(CoreSet::First), - print_tick_time.in_base_set(CoreSet::LastFlush), - init_clients, - despawn_disconnected_clients, - )) + .add_systems(Startup, setup) + .add_systems(First, record_tick_start_time) + .add_systems(Update, (init_clients, despawn_disconnected_clients)) + .add_systems(Last, print_tick_time) .run(); } diff --git a/examples/biomes.rs b/examples/biomes.rs index d5735e068..4b52eefc9 100644 --- a/examples/biomes.rs +++ b/examples/biomes.rs @@ -9,8 +9,8 @@ pub fn main() { App::new() .add_plugins(DefaultPlugins) - .add_startup_system(setup) - .add_systems((init_clients, despawn_disconnected_clients)) + .add_systems(Startup, setup) + .add_systems(Update, (init_clients, despawn_disconnected_clients)) .run(); } diff --git a/examples/block_entities.rs b/examples/block_entities.rs index 2e00dd94f..ec86e0241 100644 --- a/examples/block_entities.rs +++ b/examples/block_entities.rs @@ -14,8 +14,11 @@ pub fn main() { App::new() .add_plugins(DefaultPlugins) - .add_startup_system(setup) - .add_systems((event_handler, init_clients, despawn_disconnected_clients)) + .add_systems(Startup, setup) + .add_systems( + Update, + (event_handler, init_clients, despawn_disconnected_clients), + ) .run(); } diff --git a/examples/boss_bar.rs b/examples/boss_bar.rs index c851f98a0..0aee01fe5 100644 --- a/examples/boss_bar.rs +++ b/examples/boss_bar.rs @@ -13,10 +13,11 @@ pub fn main() { App::new() .add_plugins(DefaultPlugins) - .add_startup_system(setup) - .add_system(init_clients) - .add_system(despawn_disconnected_clients) - .add_system(listen_messages) + .add_systems(Startup, setup) + .add_systems( + Update, + (init_clients, despawn_disconnected_clients, listen_messages), + ) .run(); } diff --git a/examples/building.rs b/examples/building.rs index b02cce338..584c4bf67 100644 --- a/examples/building.rs +++ b/examples/building.rs @@ -12,15 +12,18 @@ pub fn main() { App::new() .add_plugins(DefaultPlugins) - .add_startup_system(setup) - .add_system(init_clients) - .add_system(despawn_disconnected_clients) - .add_systems(( - toggle_gamemode_on_sneak, - digging_creative_mode, - digging_survival_mode, - place_blocks, - )) + .add_systems(Startup, setup) + .add_systems( + Update, + ( + init_clients, + despawn_disconnected_clients, + toggle_gamemode_on_sneak, + digging_creative_mode, + digging_survival_mode, + place_blocks, + ), + ) .run(); } diff --git a/examples/chest.rs b/examples/chest.rs index 857019d52..5109d4554 100644 --- a/examples/chest.rs +++ b/examples/chest.rs @@ -11,10 +11,16 @@ pub fn main() { App::new() .add_plugins(DefaultPlugins) - .add_startup_system(setup) - .add_system(init_clients) - .add_systems((toggle_gamemode_on_sneak, open_chest)) - .add_system(despawn_disconnected_clients) + .add_systems(Startup, setup) + .add_systems( + Update, + ( + init_clients, + toggle_gamemode_on_sneak, + open_chest, + despawn_disconnected_clients, + ), + ) .run(); } diff --git a/examples/combat.rs b/examples/combat.rs index 4d839adb0..0a1b4adac 100644 --- a/examples/combat.rs +++ b/examples/combat.rs @@ -21,11 +21,16 @@ pub fn main() { App::new() .add_plugins(DefaultPlugins) - .add_startup_system(setup) - .add_system(init_clients) - .add_system(handle_combat_events.in_schedule(EventLoopSchedule)) - .add_system(despawn_disconnected_clients) - .add_system(teleport_oob_clients) + .add_systems(Startup, setup) + .add_systems(EventLoopUpdate, handle_combat_events) + .add_systems( + Update, + ( + init_clients, + despawn_disconnected_clients, + teleport_oob_clients, + ), + ) .run(); } diff --git a/examples/cow_sphere.rs b/examples/cow_sphere.rs index 8fd696bec..f3e1bd267 100644 --- a/examples/cow_sphere.rs +++ b/examples/cow_sphere.rs @@ -24,10 +24,11 @@ fn main() { App::new() .add_plugins(DefaultPlugins) - .add_startup_system(setup) - .add_system(init_clients) - .add_system(update_sphere) - .add_system(despawn_disconnected_clients) + .add_systems(Startup, setup) + .add_systems( + Update, + (init_clients, update_sphere, despawn_disconnected_clients), + ) .run(); } diff --git a/examples/death.rs b/examples/death.rs index ad0035026..90e91124b 100644 --- a/examples/death.rs +++ b/examples/death.rs @@ -11,9 +11,16 @@ pub fn main() { App::new() .add_plugins(DefaultPlugins) - .add_startup_system(setup) - .add_systems((init_clients, squat_and_die, necromancy)) - .add_system(despawn_disconnected_clients) + .add_systems(Startup, setup) + .add_systems( + Update, + ( + init_clients, + squat_and_die, + necromancy, + despawn_disconnected_clients, + ), + ) .run(); } diff --git a/examples/entity_hitbox.rs b/examples/entity_hitbox.rs index e81bb1976..d8f267ff1 100644 --- a/examples/entity_hitbox.rs +++ b/examples/entity_hitbox.rs @@ -17,9 +17,8 @@ use valence_entity::{entity, Pose}; pub fn main() { App::new() .add_plugins(DefaultPlugins) - .add_startup_system(setup) - .add_system(init_clients) - .add_systems((spawn_entity, intersections)) + .add_systems(Startup, setup) + .add_systems(Update, (init_clients, spawn_entity, intersections)) .run(); } diff --git a/examples/game_of_life.rs b/examples/game_of_life.rs index 43e21a8f0..7f101c6e5 100644 --- a/examples/game_of_life.rs +++ b/examples/game_of_life.rs @@ -25,15 +25,18 @@ pub fn main() { App::new() .add_plugins(DefaultPlugins) - .add_startup_system(setup) - .add_system(init_clients) - .add_systems(( - despawn_disconnected_clients, - toggle_cell_on_dig, - update_board, - pause_on_crouch, - reset_oob_clients, - )) + .add_systems(Startup, setup) + .add_systems( + Update, + ( + init_clients, + despawn_disconnected_clients, + toggle_cell_on_dig, + update_board, + pause_on_crouch, + reset_oob_clients, + ), + ) .run(); } diff --git a/examples/parkour.rs b/examples/parkour.rs index 0dc873140..10485cb25 100644 --- a/examples/parkour.rs +++ b/examples/parkour.rs @@ -27,13 +27,16 @@ pub fn main() { App::new() .add_plugins(DefaultPlugins) - .add_system(init_clients) - .add_systems(( - reset_clients.after(init_clients), - manage_chunks.after(reset_clients).before(manage_blocks), - manage_blocks, - despawn_disconnected_clients, - )) + .add_systems( + Update, + ( + init_clients, + reset_clients.after(init_clients), + manage_chunks.after(reset_clients).before(manage_blocks), + manage_blocks, + despawn_disconnected_clients, + ), + ) .run(); } diff --git a/examples/particles.rs b/examples/particles.rs index 432a19bb8..b7c842727 100644 --- a/examples/particles.rs +++ b/examples/particles.rs @@ -11,10 +11,11 @@ pub fn main() { App::new() .add_plugins(DefaultPlugins) - .add_startup_system(setup) - .add_system(init_clients) - .add_system(despawn_disconnected_clients) - .add_system(manage_particles) + .add_systems(Startup, setup) + .add_systems( + Update, + (init_clients, despawn_disconnected_clients, manage_particles), + ) .run(); } diff --git a/examples/player_list.rs b/examples/player_list.rs index 0b50f7f5b..e17d359ee 100644 --- a/examples/player_list.rs +++ b/examples/player_list.rs @@ -15,13 +15,16 @@ fn main() { App::new() .add_plugins(DefaultPlugins) - .add_startup_system(setup) - .add_systems(( - init_clients, - override_display_name, - update_player_list, - despawn_disconnected_clients, - )) + .add_systems(Startup, setup) + .add_systems( + Update, + ( + init_clients, + override_display_name, + update_player_list, + despawn_disconnected_clients, + ), + ) .run(); } diff --git a/examples/resource_pack.rs b/examples/resource_pack.rs index 5701d0849..c767d5cb6 100644 --- a/examples/resource_pack.rs +++ b/examples/resource_pack.rs @@ -13,9 +13,16 @@ pub fn main() { App::new() .add_plugins(DefaultPlugins) - .add_startup_system(setup) - .add_systems((init_clients, prompt_on_punch, on_resource_pack_status)) - .add_system(despawn_disconnected_clients) + .add_systems(Startup, setup) + .add_systems( + Update, + ( + init_clients, + prompt_on_punch, + on_resource_pack_status, + despawn_disconnected_clients, + ), + ) .run(); } diff --git a/examples/terrain.rs b/examples/terrain.rs index a4a978cbe..1b1f76adb 100644 --- a/examples/terrain.rs +++ b/examples/terrain.rs @@ -43,17 +43,20 @@ pub fn main() { App::new() .add_plugins(DefaultPlugins) - .add_startup_system(setup) + .add_systems(Startup, setup) .add_systems( + Update, ( - init_clients, - remove_unviewed_chunks, - update_client_views, - send_recv_chunks, - ) - .chain(), + ( + init_clients, + remove_unviewed_chunks, + update_client_views, + send_recv_chunks, + ) + .chain(), + despawn_disconnected_clients, + ), ) - .add_system(despawn_disconnected_clients) .run(); } diff --git a/examples/text.rs b/examples/text.rs index a990ecb13..0c53a1e60 100644 --- a/examples/text.rs +++ b/examples/text.rs @@ -10,9 +10,8 @@ pub fn main() { App::new() .add_plugins(DefaultPlugins) - .add_startup_system(setup) - .add_system(init_clients) - .add_system(despawn_disconnected_clients) + .add_systems(Startup, setup) + .add_systems(Update, (init_clients, despawn_disconnected_clients)) .run(); } diff --git a/examples/world_border.rs b/examples/world_border.rs index 8f908708c..14d8fcebf 100644 --- a/examples/world_border.rs +++ b/examples/world_border.rs @@ -15,12 +15,17 @@ fn main() { App::new() .add_plugins(DefaultPlugins) - .add_startup_system(setup) - .add_system(init_clients) - .add_system(despawn_disconnected_clients) - .add_system(border_center_avg) - .add_system(border_expand) - .add_system(border_controls) + .add_systems(Startup, setup) + .add_systems( + Update, + ( + init_clients, + despawn_disconnected_clients, + border_center_avg, + border_expand, + border_controls, + ), + ) .run(); } diff --git a/src/lib.rs b/src/lib.rs index 35b596622..16f24bb4a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -67,7 +67,7 @@ pub mod prelude { pub use ident::Ident; #[cfg(feature = "advancement")] pub use valence_advancement::{ - event::AdvancementTabChange, Advancement, AdvancementBundle, AdvancementClientUpdate, + event::AdvancementTabChangeEvent, Advancement, AdvancementBundle, AdvancementClientUpdate, AdvancementCriteria, AdvancementDisplay, AdvancementFrameType, AdvancementRequirements, }; pub use valence_biome::{Biome, BiomeId, BiomeRegistry}; @@ -77,7 +77,9 @@ pub mod prelude { ClientCommand, JumpWithHorseEvent, JumpWithHorseState, LeaveBedEvent, SneakEvent, SneakState, SprintEvent, SprintState, }; - pub use valence_client::event_loop::{EventLoopSchedule, EventLoopSet}; + pub use valence_client::event_loop::{ + EventLoopPostUpdate, EventLoopPreUpdate, EventLoopUpdate, + }; pub use valence_client::interact_entity::{EntityInteraction, InteractEntityEvent}; pub use valence_client::title::SetTitle as _; pub use valence_client::{ diff --git a/src/tests/inventory.rs b/src/tests/inventory.rs index f14abeb1b..e7568b1bb 100644 --- a/src/tests/inventory.rs +++ b/src/tests/inventory.rs @@ -6,7 +6,7 @@ use valence_inventory::packet::{ OpenScreenS2c, ScreenHandlerSlotUpdateS2c, SlotChange, UpdateSelectedSlotC2s, }; use valence_inventory::{ - convert_to_player_slot_id, ClientInventoryState, CursorItem, DropItemStack, HeldItem, + convert_to_player_slot_id, ClientInventoryState, CursorItem, DropItemStackEvent, HeldItem, Inventory, InventoryKind, OpenInventory, }; @@ -559,7 +559,7 @@ mod dropping_items { let events = app .world - .get_resource::>() + .get_resource::>() .expect("expected drop item stack events"); let events = events.iter_current_update_events().collect::>(); @@ -614,7 +614,7 @@ mod dropping_items { assert_eq!(inventory.slot(36), None); let events = app .world - .get_resource::>() + .get_resource::>() .expect("expected drop item stack events"); let events = events.iter_current_update_events().collect::>(); assert_eq!(events.len(), 1); @@ -647,7 +647,7 @@ mod dropping_items { // Make assertions let events = app .world - .get_resource::>() + .get_resource::>() .expect("expected drop item stack events") .iter_current_update_events() .collect::>(); @@ -703,7 +703,7 @@ mod dropping_items { let events = app .world - .get_resource::>() + .get_resource::>() .expect("expected drop item stack events"); let events = events.iter_current_update_events().collect::>(); @@ -758,7 +758,7 @@ mod dropping_items { // Make assertions let events = app .world - .get_resource::>() + .get_resource::>() .expect("expected drop item stack events"); let events = events.iter_current_update_events().collect::>(); @@ -813,7 +813,7 @@ mod dropping_items { // Make assertions let events = app .world - .get_resource::>() + .get_resource::>() .expect("expected drop item stack events"); let events = events.iter_current_update_events().collect::>(); @@ -880,7 +880,7 @@ mod dropping_items { // Make assertions let events = app .world - .get_resource::>() + .get_resource::>() .expect("expected drop item stack events"); let player_inventory = app @@ -963,7 +963,7 @@ fn should_drop_item_stack_player_open_inventory_with_dropkey() { // Make assertions let events = app .world - .get_resource::>() + .get_resource::>() .expect("expected drop item stack events"); let player_inventory = app diff --git a/tools/packet_inspector/src/app/text_viewer.rs b/tools/packet_inspector/src/app/text_viewer.rs index 1fe75f43d..6da07d594 100644 --- a/tools/packet_inspector/src/app/text_viewer.rs +++ b/tools/packet_inspector/src/app/text_viewer.rs @@ -6,6 +6,7 @@ mod utils { use valence::protocol::{Decode, Packet}; use valence::advancement::packet::*; + use valence::boss_bar::packet::*; use valence::client::action::*; use valence::client::command::*; use valence::client::custom_payload::*; @@ -29,7 +30,6 @@ mod utils { use valence::network::packet::*; use valence::particle::*; use valence::player_list::packet::*; - use valence::protocol::packet::boss_bar::*; use valence::protocol::packet::chat::*; use valence::protocol::packet::command::*; use valence::protocol::packet::map::*; diff --git a/tools/playground/src/playground.template.rs b/tools/playground/src/playground.template.rs index 1282de1f6..829c3881d 100644 --- a/tools/playground/src/playground.template.rs +++ b/tools/playground/src/playground.template.rs @@ -13,10 +13,10 @@ pub fn build_app(app: &mut App) { ..Default::default() }) .add_plugins(DefaultPlugins) - .add_startup_system(setup) - .add_system(init_clients) - .add_system(despawn_disconnected_clients) - .add_system(toggle_gamemode_on_sneak.in_schedule(EventLoopSchedule)); + .add_systems(Startup, setup) + .add_systems(EventLoopUpdate, toggle_gamemode_on_sneak) + .add_systems(Update, (init_clients, despawn_disconnected_clients)) + .run(); } fn setup(