Update to Bevy 0.11 (#94)

* update to bevy 0.11

* clippy

---------

Co-authored-by: mat <git@matdoes.dev>
This commit is contained in:
mat 2023-07-09 19:11:29 -05:00 committed by GitHub
parent ea8a8fccb6
commit d1afd02aa8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
50 changed files with 588 additions and 545 deletions

507
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -11,23 +11,23 @@ version = "0.7.0"
[dependencies] [dependencies]
azalea-buf = { path = "../azalea-buf", version = "^0.7.0" } azalea-buf = { path = "../azalea-buf", version = "^0.7.0" }
azalea-crypto = { path = "../azalea-crypto", version = "^0.7.0" } azalea-crypto = { path = "../azalea-crypto", version = "^0.7.0" }
base64 = "0.21.0" base64 = "0.21.2"
chrono = { version = "0.4.24", default-features = false, features = ["serde"] } chrono = { version = "0.4.26", default-features = false, features = ["serde"] }
log = "0.4.17" log = "0.4.19"
num-bigint = "0.4.3" num-bigint = "0.4.3"
once_cell = "1.17.1" once_cell = "1.18.0"
parking_lot = "0.12.1" parking_lot = "0.12.1"
reqwest = { version = "0.11.16", default-features = false, features = [ reqwest = { version = "0.11.18", default-features = false, features = [
"json", "json",
"rustls-tls", "rustls-tls",
] } ] }
rsa = "0.9.2" rsa = "0.9.2"
serde = { version = "1.0.159", features = ["derive"] } serde = { version = "1.0.170", features = ["derive"] }
serde_json = "1.0.95" serde_json = "1.0.100"
thiserror = "1.0.40" thiserror = "1.0.43"
tokio = { version = "1.27.0", features = ["fs"] } tokio = { version = "1.29.1", features = ["fs"] }
uuid = { version = "1.3.0", features = ["serde"] } uuid = { version = "1.4.0", features = ["serde"] }
[dev-dependencies] [dev-dependencies]
env_logger = "0.10.0" env_logger = "0.10.0"
tokio = { version = "1.27.0", features = ["full"] } tokio = { version = "1.29.1", features = ["full"] }

View file

@ -12,6 +12,6 @@ proc-macro = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
proc-macro2 = "1.0.39" proc-macro2 = "1.0.64"
quote = "1.0.18" quote = "1.0.29"
syn = "1.0.95" syn = "2.0.25"

View file

@ -109,7 +109,7 @@ impl Parse for PropertyType {
} else { } else {
let content; let content;
braced!(content in input); braced!(content in input);
let variants = content.parse_terminated(Ident::parse)?; let variants = content.parse_terminated(Ident::parse, Token![,])?;
Ok(Self::Enum { Ok(Self::Enum {
type_name: keyword, type_name: keyword,
variants, variants,
@ -172,8 +172,8 @@ impl Parse for BlockDefinition {
let mut properties_and_defaults = Vec::new(); let mut properties_and_defaults = Vec::new();
// read the things comma-separated // read the things comma-separated
let property_and_default_punctuated: Punctuated<PropertyWithNameAndDefault, Token![,]> = let property_and_default_punctuated =
content.parse_terminated(PropertyWithNameAndDefault::parse)?; content.parse_terminated(PropertyWithNameAndDefault::parse, Token![,])?;
for property_and_default in property_and_default_punctuated { for property_and_default in property_and_default_punctuated {
properties_and_defaults.push(property_and_default); properties_and_defaults.push(property_and_default);
@ -191,8 +191,8 @@ impl Parse for BlockDefinitions {
fn parse(input: ParseStream) -> Result<Self> { fn parse(input: ParseStream) -> Result<Self> {
let mut blocks = Vec::new(); let mut blocks = Vec::new();
let block_definitions_punctuated: Punctuated<BlockDefinition, Token![,]> = let block_definitions_punctuated =
input.parse_terminated(BlockDefinition::parse)?; input.parse_terminated(BlockDefinition::parse, Token![,])?;
for block_definition in block_definitions_punctuated { for block_definition in block_definitions_punctuated {
blocks.push(block_definition); blocks.push(block_definition);
} }

View file

@ -105,7 +105,7 @@ impl<S> CommandDispatcher<S> {
let parse = self let parse = self
.parse_nodes(redirect, &reader, child_context) .parse_nodes(redirect, &reader, child_context)
.expect("Parsing nodes failed"); .expect("Parsing nodes failed");
context.with_child(Arc::new(parse.context)); context.with_child(Rc::new(parse.context));
return Ok(ParseResults { return Ok(ParseResults {
context, context,
reader: parse.reader, reader: parse.reader,

View file

@ -16,7 +16,7 @@ pub struct CommandContext<S> {
pub root_node: Arc<RwLock<CommandNode<S>>>, pub root_node: Arc<RwLock<CommandNode<S>>>,
pub nodes: Vec<ParsedCommandNode<S>>, pub nodes: Vec<ParsedCommandNode<S>>,
pub range: StringRange, pub range: StringRange,
pub child: Option<Arc<CommandContext<S>>>, pub child: Option<Rc<CommandContext<S>>>,
pub modifier: Option<Arc<RedirectModifier<S>>>, pub modifier: Option<Arc<RedirectModifier<S>>>,
pub forks: bool, pub forks: bool,
} }

View file

@ -9,7 +9,7 @@ use crate::{
modifier::RedirectModifier, modifier::RedirectModifier,
tree::{Command, CommandNode}, tree::{Command, CommandNode},
}; };
use std::{collections::HashMap, fmt::Debug, sync::Arc}; use std::{collections::HashMap, fmt::Debug, rc::Rc, sync::Arc};
pub struct CommandContextBuilder<'a, S> { pub struct CommandContextBuilder<'a, S> {
pub arguments: HashMap<String, ParsedArgument>, pub arguments: HashMap<String, ParsedArgument>,
@ -18,7 +18,7 @@ pub struct CommandContextBuilder<'a, S> {
pub dispatcher: &'a CommandDispatcher<S>, pub dispatcher: &'a CommandDispatcher<S>,
pub source: Arc<S>, pub source: Arc<S>,
pub command: Command<S>, pub command: Command<S>,
pub child: Option<Arc<CommandContextBuilder<'a, S>>>, pub child: Option<Rc<CommandContextBuilder<'a, S>>>,
pub range: StringRange, pub range: StringRange,
pub modifier: Option<Arc<RedirectModifier<S>>>, pub modifier: Option<Arc<RedirectModifier<S>>>,
pub forks: bool, pub forks: bool,
@ -66,7 +66,7 @@ impl<'a, S> CommandContextBuilder<'a, S> {
self.command = command.clone(); self.command = command.clone();
self self
} }
pub fn with_child(&mut self, child: Arc<CommandContextBuilder<'a, S>>) -> &Self { pub fn with_child(&mut self, child: Rc<CommandContextBuilder<'a, S>>) -> &Self {
self.child = Some(child); self.child = Some(child);
self self
} }
@ -92,7 +92,7 @@ impl<'a, S> CommandContextBuilder<'a, S> {
nodes: self.nodes.clone(), nodes: self.nodes.clone(),
source: self.source.clone(), source: self.source.clone(),
command: self.command.clone(), command: self.command.clone(),
child: self.child.clone().map(|c| Arc::new(c.build(input))), child: self.child.clone().map(|c| Rc::new(c.build(input))),
range: self.range.clone(), range: self.range.clone(),
forks: self.forks, forks: self.forks,
modifier: self.modifier.clone(), modifier: self.modifier.clone(),

View file

@ -11,10 +11,10 @@ version = "0.7.0"
[dependencies] [dependencies]
azalea-buf-macros = { path = "./azalea-buf-macros", version = "^0.7.0" } azalea-buf-macros = { path = "./azalea-buf-macros", version = "^0.7.0" }
byteorder = "^1.4.3" byteorder = "^1.4.3"
log = "0.4.17" log = "0.4.19"
serde_json = { version = "^1.0", optional = true } serde_json = { version = "^1.0", optional = true }
thiserror = "1.0.37" thiserror = "1.0.43"
uuid = "^1.1.2" uuid = "^1.4.0"
[features] [features]
serde_json = ["dep:serde_json"] serde_json = ["dep:serde_json"]

View file

@ -11,6 +11,6 @@ proc-macro = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
proc-macro2 = "^1.0.36" proc-macro2 = "^1.0.64"
quote = "^1.0.10" quote = "^1.0.29"
syn = { version = "^1.0.82", features = ["extra-traits"] } syn = { version = "^2.0.25", features = ["extra-traits"] }

View file

@ -13,7 +13,7 @@ fn read_named_fields(
// if it's a string, use buf.write_string // if it's a string, use buf.write_string
match field_type { match field_type {
syn::Type::Path(_) | syn::Type::Array(_) => { syn::Type::Path(_) | syn::Type::Array(_) => {
if f.attrs.iter().any(|a| a.path.is_ident("var")) { if f.attrs.iter().any(|a| a.path().is_ident("var")) {
quote! { quote! {
let #field_name = azalea_buf::McBufVarReadable::var_read_from(buf)?; let #field_name = azalea_buf::McBufVarReadable::var_read_from(buf)?;
} }
@ -98,7 +98,7 @@ pub fn create_impl_mcbufreadable(ident: &Ident, data: &Data) -> proc_macro2::Tok
syn::Fields::Unnamed(fields) => { syn::Fields::Unnamed(fields) => {
let mut reader_code = quote! {}; let mut reader_code = quote! {};
for f in &fields.unnamed { for f in &fields.unnamed {
if f.attrs.iter().any(|attr| attr.path.is_ident("var")) { if f.attrs.iter().any(|attr| attr.path().is_ident("var")) {
reader_code.extend(quote! { reader_code.extend(quote! {
Self::#variant_name(azalea_buf::McBufVarReadable::var_read_from(buf)?), Self::#variant_name(azalea_buf::McBufVarReadable::var_read_from(buf)?),
}); });

View file

@ -17,7 +17,7 @@ fn write_named_fields(
// if it's a string, use buf.write_string // if it's a string, use buf.write_string
match field_type { match field_type {
syn::Type::Path(_) | syn::Type::Array(_) => { syn::Type::Path(_) | syn::Type::Array(_) => {
if f.attrs.iter().any(|attr| attr.path.is_ident("var")) { if f.attrs.iter().any(|attr| attr.path().is_ident("var")) {
quote! { quote! {
azalea_buf::McBufVarWritable::var_write_into(#ident_dot_field, buf)?; azalea_buf::McBufVarWritable::var_write_into(#ident_dot_field, buf)?;
} }
@ -133,7 +133,7 @@ pub fn create_impl_mcbufwritable(ident: &Ident, data: &Data) -> proc_macro2::Tok
for (i, f) in fields.unnamed.iter().enumerate() { for (i, f) in fields.unnamed.iter().enumerate() {
let param_ident = Ident::new(&format!("data{i}"), Span::call_site()); let param_ident = Ident::new(&format!("data{i}"), Span::call_site());
params_code.extend(quote! { #param_ident, }); params_code.extend(quote! { #param_ident, });
if f.attrs.iter().any(|attr| attr.path.is_ident("var")) { if f.attrs.iter().any(|attr| attr.path().is_ident("var")) {
writers_code.extend(quote! { writers_code.extend(quote! {
azalea_buf::McBufVarWritable::var_write_into(#param_ident, buf)?; azalea_buf::McBufVarWritable::var_write_into(#param_ident, buf)?;
}); });

View file

@ -16,7 +16,7 @@ azalea-buf = { path = "../azalea-buf", features = [
"serde_json", "serde_json",
], version = "^0.7.0", optional = true } ], version = "^0.7.0", optional = true }
azalea-language = { path = "../azalea-language", version = "^0.7.0" } azalea-language = { path = "../azalea-language", version = "^0.7.0" }
log = "0.4.17" log = "0.4.19"
once_cell = "1.16.0" once_cell = "1.18.0"
serde = { version = "^1.0", features = ["derive"] } serde = { version = "^1.0", features = ["derive"] }
serde_json = "^1.0.93" serde_json = "^1.0.100"

View file

@ -128,7 +128,7 @@ impl IntoIterator for FormattedText {
let mut v: Vec<FormattedText> = Vec::with_capacity(siblings.len() + 1); let mut v: Vec<FormattedText> = Vec::with_capacity(siblings.len() + 1);
v.push(self); v.push(self);
for sibling in siblings { for sibling in siblings {
v.extend(sibling.into_iter()); v.extend(sibling);
} }
v.into_iter() v.into_iter()

View file

@ -9,9 +9,9 @@ version = "0.7.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
reqwest = { version = "0.11.12", default-features = false } reqwest = { version = "0.11.18", default-features = false }
anyhow = "1.0.59" anyhow = "1.0.71"
async-trait = "0.1.58" async-trait = "0.1.71"
azalea-auth = { path = "../azalea-auth", version = "0.7.0" } azalea-auth = { path = "../azalea-auth", version = "0.7.0" }
azalea-block = { path = "../azalea-block", version = "0.7.0" } azalea-block = { path = "../azalea-block", version = "0.7.0" }
azalea-nbt = { path = "../azalea-nbt", version = "0.7.0" } azalea-nbt = { path = "../azalea-nbt", version = "0.7.0" }
@ -22,22 +22,22 @@ azalea-physics = { path = "../azalea-physics", version = "0.7.0" }
azalea-protocol = { path = "../azalea-protocol", version = "0.7.0" } azalea-protocol = { path = "../azalea-protocol", version = "0.7.0" }
azalea-registry = { path = "../azalea-registry", version = "0.7.0" } azalea-registry = { path = "../azalea-registry", version = "0.7.0" }
azalea-world = { path = "../azalea-world", version = "0.7.0" } azalea-world = { path = "../azalea-world", version = "0.7.0" }
bevy_app = "0.10.0" bevy_app = "0.11.0"
bevy_ecs = "0.10.0" bevy_ecs = "0.11.0"
bevy_log = "0.10.0" bevy_log = "0.11.0"
bevy_tasks = "0.10.0" bevy_tasks = "0.11.0"
bevy_time = "0.10.0" bevy_time = "0.11.0"
azalea-inventory = { path = "../azalea-inventory", version = "0.7.0" } azalea-inventory = { path = "../azalea-inventory", version = "0.7.0" }
derive_more = { version = "0.99.17", features = ["deref", "deref_mut"] } derive_more = { version = "0.99.17", features = ["deref", "deref_mut"] }
futures = "0.3.25" futures = "0.3.28"
log = "0.4.17" log = "0.4.19"
nohash-hasher = "0.2.0" nohash-hasher = "0.2.0"
once_cell = "1.16.0" once_cell = "1.18.0"
parking_lot = { version = "^0.12.1", features = ["deadlock_detection"] } parking_lot = { version = "^0.12.1", features = ["deadlock_detection"] }
regex = "1.7.0" regex = "1.9.1"
thiserror = "^1.0.34" thiserror = "^1.0.43"
tokio = { version = "^1.24.2", features = ["sync"] } tokio = { version = "^1.29.1", features = ["sync"] }
uuid = "^1.1.2" uuid = "^1.4.0"
[features] [features]
default = ["log"] default = ["log"]

View file

@ -7,11 +7,12 @@ use azalea_protocol::packets::game::{
serverbound_chat_command_packet::ServerboundChatCommandPacket, serverbound_chat_command_packet::ServerboundChatCommandPacket,
serverbound_chat_packet::{LastSeenMessagesUpdate, ServerboundChatPacket}, serverbound_chat_packet::{LastSeenMessagesUpdate, ServerboundChatPacket},
}; };
use bevy_app::{App, Plugin}; use bevy_app::{App, Plugin, Update};
use bevy_ecs::{ use bevy_ecs::{
entity::Entity, entity::Entity,
event::{EventReader, EventWriter}, event::{EventReader, EventWriter},
schedule::{IntoSystemConfig, IntoSystemConfigs}, prelude::Event,
schedule::IntoSystemConfigs,
}; };
use std::{ use std::{
sync::Arc, sync::Arc,
@ -170,6 +171,7 @@ impl Plugin for ChatPlugin {
.add_event::<SendChatKindEvent>() .add_event::<SendChatKindEvent>()
.add_event::<ChatReceivedEvent>() .add_event::<ChatReceivedEvent>()
.add_systems( .add_systems(
Update,
( (
handle_send_chat_event, handle_send_chat_event,
handle_send_chat_kind_event.after(handle_send_packet_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. /// A client received a chat message packet.
#[derive(Debug, Clone)] #[derive(Event, Debug, Clone)]
pub struct ChatReceivedEvent { pub struct ChatReceivedEvent {
pub entity: Entity, pub entity: Entity,
pub packet: ChatPacket, pub packet: ChatPacket,
} }
/// Send a chat message (or command, if it starts with a slash) to the server. /// Send a chat message (or command, if it starts with a slash) to the server.
#[derive(Event)]
pub struct SendChatEvent { pub struct SendChatEvent {
pub entity: Entity, pub entity: Entity,
pub content: String, 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 /// 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. /// preserved if multiple chat messages and commands are sent at the same time.
#[derive(Event)]
pub struct SendChatKindEvent { pub struct SendChatKindEvent {
pub entity: Entity, pub entity: Entity,
pub content: String, pub content: String,

View file

@ -45,13 +45,12 @@ use azalea_world::{
entity::{EntityPlugin, EntityUpdateSet, Local, Position, WorldName}, entity::{EntityPlugin, EntityUpdateSet, Local, Position, WorldName},
Instance, InstanceContainer, PartialInstance, 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::{ use bevy_ecs::{
bundle::Bundle, bundle::Bundle,
component::Component, component::Component,
entity::Entity, entity::Entity,
schedule::IntoSystemConfig, schedule::{IntoSystemConfigs, LogLevel, ScheduleBuildSettings, ScheduleLabel},
schedule::{LogLevel, ScheduleBuildSettings, ScheduleLabel},
system::{ResMut, Resource}, system::{ResMut, Resource},
world::World, world::World,
}; };
@ -568,20 +567,20 @@ pub struct AzaleaPlugin;
impl Plugin for AzaleaPlugin { impl Plugin for AzaleaPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
// Minecraft ticks happen every 50ms // Minecraft ticks happen every 50ms
app.insert_resource(FixedTime::new(Duration::from_millis(50))); app.insert_resource(FixedTime::new(Duration::from_millis(50)))
.add_systems(
app.add_system(update_in_loaded_chunk.after(PhysicsSet)); Update,
(
// fire the Death event when the player dies. update_in_loaded_chunk.after(PhysicsSet),
app.add_system(death_event); // fire the Death event when the player dies.
death_event,
// add GameProfileComponent when we get an AddPlayerEvent // add GameProfileComponent when we get an AddPlayerEvent
app.add_system(retroactively_add_game_profile_component.after(EntityUpdateSet::Index)); retroactively_add_game_profile_component.after(EntityUpdateSet::Index),
handle_send_packet_event,
app.add_event::<SendPacketEvent>() ),
.add_system(handle_send_packet_event); )
.add_event::<SendPacketEvent>()
app.init_resource::<InstanceContainer>(); .init_resource::<InstanceContainer>();
} }
} }
@ -591,19 +590,17 @@ impl Plugin for AzaleaPlugin {
/// [`DefaultPlugins`]. /// [`DefaultPlugins`].
#[doc(hidden)] #[doc(hidden)]
pub fn start_ecs( pub fn start_ecs(
mut app: App, app: App,
run_schedule_receiver: mpsc::UnboundedReceiver<()>, run_schedule_receiver: mpsc::UnboundedReceiver<()>,
run_schedule_sender: mpsc::UnboundedSender<()>, run_schedule_sender: mpsc::UnboundedSender<()>,
) -> Arc<Mutex<World>> { ) -> Arc<Mutex<World>> {
app.setup();
// all resources should have been added by now so we can take the ecs from the // all resources should have been added by now so we can take the ecs from the
// app // app
let ecs = Arc::new(Mutex::new(app.world)); let ecs = Arc::new(Mutex::new(app.world));
tokio::spawn(run_schedule_loop( tokio::spawn(run_schedule_loop(
ecs.clone(), ecs.clone(),
app.outer_schedule_label, app.main_schedule_label,
run_schedule_receiver, run_schedule_receiver,
)); ));
tokio::spawn(tick_run_schedule_loop(run_schedule_sender)); 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 // whenever we get an event from run_schedule_receiver, run the schedule
run_schedule_receiver.recv().await; run_schedule_receiver.recv().await;
let mut ecs = ecs.lock(); let mut ecs = ecs.lock();
ecs.run_schedule_ref(&*outer_schedule_label); ecs.run_schedule(&outer_schedule_label);
ecs.clear_trackers(); ecs.clear_trackers();
} }
} }
@ -671,14 +668,14 @@ pub struct TickBroadcastPlugin;
impl Plugin for TickBroadcastPlugin { impl Plugin for TickBroadcastPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.insert_resource(TickBroadcast(broadcast::channel(1).0)) 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; pub struct AmbiguityLoggerPlugin;
impl Plugin for AmbiguityLoggerPlugin { impl Plugin for AmbiguityLoggerPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.edit_schedule(CoreSchedule::Main, |schedule| { app.edit_schedule(Main, |schedule| {
schedule.set_build_settings(ScheduleBuildSettings { schedule.set_build_settings(ScheduleBuildSettings {
ambiguity_detection: LogLevel::Warn, ambiguity_detection: LogLevel::Warn,
..Default::default() ..Default::default()

View file

@ -1,10 +1,11 @@
//! Disconnect a client from the server. //! Disconnect a client from the server.
use bevy_app::{App, CoreSet, Plugin}; use bevy_app::{App, Plugin, PostUpdate};
use bevy_ecs::{ use bevy_ecs::{
component::Component, component::Component,
entity::Entity, entity::Entity,
event::{EventReader, EventWriter}, event::{EventReader, EventWriter},
prelude::Event,
query::Changed, query::Changed,
schedule::IntoSystemConfigs, schedule::IntoSystemConfigs,
system::{Commands, Query}, system::{Commands, Query},
@ -17,18 +18,19 @@ pub struct DisconnectPlugin;
impl Plugin for DisconnectPlugin { impl Plugin for DisconnectPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_event::<DisconnectEvent>().add_systems( app.add_event::<DisconnectEvent>().add_systems(
PostUpdate,
( (
update_read_packets_task_running_component, update_read_packets_task_running_component,
disconnect_on_read_packets_ended, disconnect_on_read_packets_ended,
remove_components_from_disconnected_players, remove_components_from_disconnected_players,
) )
.in_base_set(CoreSet::PostUpdate)
.chain(), .chain(),
); );
} }
} }
/// An event sent when a client is getting disconnected. /// An event sent when a client is getting disconnected.
#[derive(Event)]
pub struct DisconnectEvent { pub struct DisconnectEvent {
pub entity: Entity, pub entity: Entity,
} }

View file

@ -7,7 +7,7 @@ use azalea_protocol::packets::game::{
clientbound_player_combat_kill_packet::ClientboundPlayerCombatKillPacket, ClientboundGamePacket, clientbound_player_combat_kill_packet::ClientboundPlayerCombatKillPacket, ClientboundGamePacket,
}; };
use azalea_world::entity::MinecraftEntityId; 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 bevy_ecs::{component::Component, event::EventReader, query::Added, system::Query};
use derive_more::{Deref, DerefMut}; use derive_more::{Deref, DerefMut};
use tokio::sync::mpsc; use tokio::sync::mpsc;
@ -100,16 +100,21 @@ pub struct LocalPlayerEvents(pub mpsc::UnboundedSender<Event>);
pub struct EventPlugin; pub struct EventPlugin;
impl Plugin for EventPlugin { impl Plugin for EventPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_system(chat_listener) app.add_systems(
.add_system(login_listener) Update,
.add_system(init_listener) (
.add_system(packet_listener) chat_listener,
.add_system(add_player_listener) login_listener,
.add_system(update_player_listener) init_listener,
.add_system(remove_player_listener) packet_listener,
.add_system(death_listener) add_player_listener,
.add_system(keepalive_listener) update_player_listener,
.add_system(tick_listener.in_schedule(CoreSchedule::FixedUpdate)); remove_player_listener,
death_listener,
keepalive_listener,
),
)
.add_systems(FixedUpdate, tick_listener);
} }
} }

View file

@ -11,12 +11,13 @@ use azalea_world::{
entity::{clamp_look_direction, view_vector, EyeHeight, LookDirection, Position, WorldName}, entity::{clamp_look_direction, view_vector, EyeHeight, LookDirection, Position, WorldName},
Instance, InstanceContainer, Instance, InstanceContainer,
}; };
use bevy_app::{App, Plugin}; use bevy_app::{App, Plugin, Update};
use bevy_ecs::{ use bevy_ecs::{
component::Component, component::Component,
entity::Entity, entity::Entity,
event::EventReader, event::EventReader,
schedule::{IntoSystemConfig, IntoSystemConfigs}, prelude::Event,
schedule::IntoSystemConfigs,
system::{Commands, Query, Res}, system::{Commands, Query, Res},
}; };
use derive_more::{Deref, DerefMut}; use derive_more::{Deref, DerefMut};
@ -33,6 +34,7 @@ pub struct InteractPlugin;
impl Plugin for InteractPlugin { impl Plugin for InteractPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_event::<BlockInteractEvent>().add_systems( app.add_event::<BlockInteractEvent>().add_systems(
Update,
( (
update_hit_result_component.after(clamp_look_direction), update_hit_result_component.after(clamp_look_direction),
handle_block_interact_event, handle_block_interact_event,
@ -61,6 +63,7 @@ impl Client {
/// Right click a block. The behavior of this depends on the target block, /// 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 /// and it'll either place the block you're holding in your hand or use the
/// block you clicked (like toggling a lever). /// block you clicked (like toggling a lever).
#[derive(Event)]
pub struct BlockInteractEvent { pub struct BlockInteractEvent {
/// The local player entity that's opening the container. /// The local player entity that's opening the container.
pub entity: Entity, pub entity: Entity,

View file

@ -14,13 +14,13 @@ use azalea_protocol::packets::game::{
serverbound_container_close_packet::ServerboundContainerClosePacket, serverbound_container_close_packet::ServerboundContainerClosePacket,
}; };
use azalea_registry::MenuKind; use azalea_registry::MenuKind;
use bevy_app::{App, Plugin}; use bevy_app::{App, Plugin, Update};
use bevy_ecs::{ use bevy_ecs::{
component::Component, component::Component,
entity::Entity, entity::Entity,
event::EventReader, event::EventReader,
prelude::EventWriter, prelude::{Event, EventWriter},
schedule::{IntoSystemConfig, IntoSystemConfigs}, schedule::IntoSystemConfigs,
system::Query, system::Query,
}; };
use log::warn; use log::warn;
@ -36,6 +36,7 @@ impl Plugin for InventoryPlugin {
.add_event::<ContainerClickEvent>() .add_event::<ContainerClickEvent>()
.add_event::<SetContainerContentEvent>() .add_event::<SetContainerContentEvent>()
.add_systems( .add_systems(
Update,
( (
handle_menu_opened_event, handle_menu_opened_event,
handle_set_container_content_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 /// Sent from the server when a menu (like a chest or crafting table) was
/// opened by the client. /// opened by the client.
#[derive(Debug)] #[derive(Event, Debug)]
pub struct MenuOpenedEvent { pub struct MenuOpenedEvent {
pub entity: Entity, pub entity: Entity,
pub window_id: u32, 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 /// Note that this is also sent when the client closes its own inventory, even
/// though there is no packet for opening its inventory. /// though there is no packet for opening its inventory.
#[derive(Event)]
pub struct CloseContainerEvent { pub struct CloseContainerEvent {
pub entity: Entity, pub entity: Entity,
/// The ID of the container to close. 0 for the player's inventory. If this /// 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. /// Close a container without notifying the server.
/// ///
/// Note that this also gets fired when we get a [`CloseContainerEvent`]. /// Note that this also gets fired when we get a [`CloseContainerEvent`].
#[derive(Event)]
pub struct ClientSideCloseContainerEvent { pub struct ClientSideCloseContainerEvent {
pub entity: Entity, pub entity: Entity,
} }
@ -635,7 +638,7 @@ pub fn handle_client_side_close_container_event(
} }
} }
#[derive(Debug)] #[derive(Event, Debug)]
pub struct ContainerClickEvent { pub struct ContainerClickEvent {
pub entity: Entity, pub entity: Entity,
pub window_id: u8, 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 /// Sent from the server when the contents of a container are replaced. Usually
/// triggered by the `ContainerSetContent` packet. /// triggered by the `ContainerSetContent` packet.
#[derive(Event)]
pub struct SetContainerContentEvent { pub struct SetContainerContentEvent {
pub entity: Entity, pub entity: Entity,
pub slots: Vec<ItemSlot>, pub slots: Vec<ItemSlot>,

View file

@ -11,6 +11,7 @@ use bevy_ecs::{
component::Component, component::Component,
entity::Entity, entity::Entity,
event::EventReader, event::EventReader,
prelude::Event,
query::Added, query::Added,
system::{Query, Res}, system::{Query, Res},
}; };
@ -20,7 +21,7 @@ use thiserror::Error;
use tokio::{sync::mpsc, task::JoinHandle}; use tokio::{sync::mpsc, task::JoinHandle};
use crate::{ use crate::{
events::{Event, LocalPlayerEvents}, events::{Event as AzaleaEvent, LocalPlayerEvents},
ClientInformation, WalkDirection, ClientInformation, WalkDirection,
}; };
@ -155,7 +156,7 @@ pub fn update_in_loaded_chunk(
/// Send the "Death" event for [`LocalPlayer`]s that died with no reason. /// Send the "Death" event for [`LocalPlayer`]s that died with no reason.
pub fn death_event(query: Query<&LocalPlayerEvents, Added<Dead>>) { pub fn death_event(query: Query<&LocalPlayerEvents, Added<Dead>>) {
for local_player_events in &query { 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)] #[error(transparent)]
Other(#[from] anyhow::Error), Other(#[from] anyhow::Error),
#[error("{0}")] #[error("{0}")]
Send(#[from] mpsc::error::SendError<Event>), Send(#[from] mpsc::error::SendError<AzaleaEvent>),
} }
impl<T> From<std::sync::PoisonError<T>> for HandlePacketError { 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. /// Event for sending a packet to the server.
#[derive(Event)]
pub struct SendPacketEvent { pub struct SendPacketEvent {
pub entity: Entity, pub entity: Entity,
pub packet: ServerboundGamePacket, pub packet: ServerboundGamePacket,

View file

@ -1,5 +1,5 @@
use azalea_core::BlockPos; use azalea_core::BlockPos;
use bevy_app::{App, Plugin}; use bevy_app::{App, Plugin, Update};
use bevy_ecs::prelude::*; use bevy_ecs::prelude::*;
use crate::Client; use crate::Client;
@ -9,7 +9,7 @@ pub struct MinePlugin;
impl Plugin for MinePlugin { impl Plugin for MinePlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_event::<StartMiningBlockEvent>() 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 struct StartMiningBlockEvent {
pub entity: Entity, pub entity: Entity,
pub position: BlockPos, pub position: BlockPos,

View file

@ -14,14 +14,11 @@ use azalea_world::{
entity::{self, metadata::Sprinting, Attributes, Jumping, MinecraftEntityId}, entity::{self, metadata::Sprinting, Attributes, Jumping, MinecraftEntityId},
MoveEntityError, MoveEntityError,
}; };
use bevy_app::{App, CoreSchedule, IntoSystemAppConfigs, Plugin}; use bevy_app::{App, FixedUpdate, Plugin, Update};
use bevy_ecs::prelude::Event;
use bevy_ecs::{ use bevy_ecs::{
component::Component, component::Component, entity::Entity, event::EventReader, query::With,
entity::Entity, schedule::IntoSystemConfigs, system::Query,
event::EventReader,
query::With,
schedule::{IntoSystemConfig, IntoSystemConfigs},
system::Query,
}; };
use std::backtrace::Backtrace; use std::backtrace::Backtrace;
use thiserror::Error; use thiserror::Error;
@ -51,17 +48,18 @@ impl Plugin for PlayerMovePlugin {
app.add_event::<StartWalkEvent>() app.add_event::<StartWalkEvent>()
.add_event::<StartSprintEvent>() .add_event::<StartSprintEvent>()
.add_systems( .add_systems(
Update,
(sprint_listener, walk_listener) (sprint_listener, walk_listener)
.chain() .chain()
.before(force_jump_listener), .before(force_jump_listener),
) )
.add_systems( .add_systems(
FixedUpdate,
( (
local_player_ai_step.in_set(PhysicsSet), local_player_ai_step.in_set(PhysicsSet),
send_position.after(update_in_loaded_chunk), send_position.after(update_in_loaded_chunk),
) )
.chain() .chain(),
.in_schedule(CoreSchedule::FixedUpdate),
); );
} }
} }
@ -379,6 +377,7 @@ impl Client {
/// An event sent when the client starts walking. This does not get sent for /// An event sent when the client starts walking. This does not get sent for
/// non-local entities. /// non-local entities.
#[derive(Event)]
pub struct StartWalkEvent { pub struct StartWalkEvent {
pub entity: Entity, pub entity: Entity,
pub direction: WalkDirection, 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 /// An event sent when the client starts sprinting. This does not get sent for
/// non-local entities. /// non-local entities.
#[derive(Event)]
pub struct StartSprintEvent { pub struct StartSprintEvent {
pub entity: Entity, pub entity: Entity,
pub direction: SprintDirection, pub direction: SprintDirection,

View file

@ -24,12 +24,13 @@ use azalea_world::{
entity::{LoadedBy, RelativeEntityUpdate}, entity::{LoadedBy, RelativeEntityUpdate},
InstanceContainer, PartialInstance, InstanceContainer, PartialInstance,
}; };
use bevy_app::{App, CoreSet, Plugin}; use bevy_app::{App, First, Plugin, PreUpdate};
use bevy_ecs::{ use bevy_ecs::{
component::Component, component::Component,
entity::Entity, entity::Entity,
event::{EventReader, EventWriter, Events}, event::{EventReader, EventWriter, Events},
schedule::IntoSystemConfig, prelude::Event,
schedule::IntoSystemConfigs,
system::{Commands, Query, ResMut, SystemState}, system::{Commands, Query, ResMut, SystemState},
world::World, world::World,
}; };
@ -69,7 +70,7 @@ use crate::{
/// } /// }
/// } /// }
/// ``` /// ```
#[derive(Debug, Clone)] #[derive(Event, Debug, Clone)]
pub struct PacketEvent { pub struct PacketEvent {
/// The client entity that received the packet. /// The client entity that received the packet.
pub entity: Entity, pub entity: Entity,
@ -81,10 +82,10 @@ pub struct PacketHandlerPlugin;
impl Plugin for PacketHandlerPlugin { impl Plugin for PacketHandlerPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_system(send_packet_events.in_base_set(CoreSet::First)) app.add_systems(First, send_packet_events)
.add_system( .add_systems(
PreUpdate,
process_packet_events process_packet_events
.in_base_set(CoreSet::PreUpdate)
// we want to index and deindex right after // we want to index and deindex right after
.before(EntityUpdateSet::Deindex), .before(EntityUpdateSet::Deindex),
) )
@ -100,7 +101,7 @@ impl Plugin for PacketHandlerPlugin {
/// A player joined the game (or more specifically, was added to the tab /// A player joined the game (or more specifically, was added to the tab
/// list of a local player). /// list of a local player).
#[derive(Debug, Clone)] #[derive(Event, Debug, Clone)]
pub struct AddPlayerEvent { pub struct AddPlayerEvent {
/// The local player entity that received this event. /// The local player entity that received this event.
pub entity: Entity, 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 /// A player left the game (or maybe is still in the game and was just
/// removed from the tab list of a local player). /// removed from the tab list of a local player).
#[derive(Debug, Clone)] #[derive(Event, Debug, Clone)]
pub struct RemovePlayerEvent { pub struct RemovePlayerEvent {
/// The local player entity that received this event. /// The local player entity that received this event.
pub entity: Entity, pub entity: Entity,
@ -116,7 +117,7 @@ pub struct RemovePlayerEvent {
} }
/// A player was updated in the tab list of a local player (gamemode, display /// A player was updated in the tab list of a local player (gamemode, display
/// name, or latency changed). /// name, or latency changed).
#[derive(Debug, Clone)] #[derive(Event, Debug, Clone)]
pub struct UpdatePlayerEvent { pub struct UpdatePlayerEvent {
/// The local player entity that received this event. /// The local player entity that received this event.
pub entity: Entity, 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 /// 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 /// reason in the death screen, the [`ClientboundPlayerCombatKillPacket`] will
/// be included. /// be included.
#[derive(Debug, Clone)] #[derive(Event, Debug, Clone)]
pub struct DeathEvent { pub struct DeathEvent {
pub entity: Entity, pub entity: Entity,
pub packet: Option<ClientboundPlayerCombatKillPacket>, 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 /// A KeepAlive packet is sent from the server to verify that the client is
/// still connected. /// still connected.
#[derive(Debug, Clone)] #[derive(Event, Debug, Clone)]
pub struct KeepAliveEvent { pub struct KeepAliveEvent {
pub entity: Entity, pub entity: Entity,
/// The ID of the keepalive. This is an arbitrary number, but vanilla /// 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. /// Something that receives packets from the server.
#[derive(Component, Clone)] #[derive(Event, Component, Clone)]
pub struct PacketReceiver { pub struct PacketReceiver {
pub packets: Arc<Mutex<Vec<ClientboundGamePacket>>>, pub packets: Arc<Mutex<Vec<ClientboundGamePacket>>>,
pub run_schedule_sender: mpsc::UnboundedSender<()>, pub run_schedule_sender: mpsc::UnboundedSender<()>,

View file

@ -1,13 +1,13 @@
use azalea_protocol::packets::game::serverbound_client_command_packet::{ use azalea_protocol::packets::game::serverbound_client_command_packet::{
self, ServerboundClientCommandPacket, self, ServerboundClientCommandPacket,
}; };
use bevy_app::{App, Plugin}; use bevy_app::{App, Plugin, Update};
use bevy_ecs::prelude::*; use bevy_ecs::prelude::*;
use crate::local_player::{handle_send_packet_event, SendPacketEvent}; use crate::local_player::{handle_send_packet_event, SendPacketEvent};
/// Tell the server that we're respawning. /// Tell the server that we're respawning.
#[derive(Debug, Clone)] #[derive(Event, Debug, Clone)]
pub struct PerformRespawnEvent { pub struct PerformRespawnEvent {
pub entity: Entity, pub entity: Entity,
} }
@ -17,7 +17,7 @@ pub struct RespawnPlugin;
impl Plugin for RespawnPlugin { impl Plugin for RespawnPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_event::<PerformRespawnEvent>() app.add_event::<PerformRespawnEvent>()
.add_system(perform_respawn.before(handle_send_packet_event)); .add_systems(Update, perform_respawn.before(handle_send_packet_event));
} }
} }

View file

@ -2,11 +2,8 @@
use std::marker::PhantomData; use std::marker::PhantomData;
use bevy_app::{App, CoreSet, Plugin}; use bevy_app::{App, Last, Plugin};
use bevy_ecs::{ use bevy_ecs::system::{NonSend, Resource};
schedule::IntoSystemConfig,
system::{NonSend, Resource},
};
use bevy_tasks::{ use bevy_tasks::{
tick_global_task_pools_on_main_thread, AsyncComputeTaskPool, ComputeTaskPool, IoTaskPool, tick_global_task_pools_on_main_thread, AsyncComputeTaskPool, ComputeTaskPool, IoTaskPool,
TaskPoolBuilder, TaskPoolBuilder,
@ -27,7 +24,7 @@ impl Plugin for TaskPoolPlugin {
self.task_pool_options.create_default_pools(); self.task_pool_options.create_default_pools();
#[cfg(not(target_arch = "wasm32"))] #[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);
} }
} }

View file

@ -14,10 +14,10 @@ azalea-chat = { path = "../azalea-chat", version = "^0.7.0" }
azalea-inventory = { version = "0.7.0", path = "../azalea-inventory" } azalea-inventory = { version = "0.7.0", path = "../azalea-inventory" }
azalea-nbt = { path = "../azalea-nbt", version = "^0.7.0" } azalea-nbt = { path = "../azalea-nbt", version = "^0.7.0" }
azalea-registry = { path = "../azalea-registry", version = "^0.7.0" } azalea-registry = { path = "../azalea-registry", version = "^0.7.0" }
bevy_ecs = { version = "0.10.0", default-features = false, optional = true } bevy_ecs = { version = "0.11.0", default-features = false, optional = true }
num-traits = "0.2.15" num-traits = "0.2.15"
serde = { version = "^1.0", optional = true } serde = { version = "^1.0", optional = true }
uuid = "^1.1.2" uuid = "^1.4.0"
[features] [features]
bevy_ecs = ["dep:bevy_ecs"] bevy_ecs = ["dep:bevy_ecs"]

View file

@ -9,19 +9,19 @@ repository = "https://github.com/mat-1/azalea/tree/main/azalea-crypto"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
aes = "0.8.1" aes = "0.8.3"
azalea-buf = { path = "../azalea-buf", version = "^0.7.0" } azalea-buf = { path = "../azalea-buf", version = "^0.7.0" }
cfb8 = "0.8.1" cfb8 = "0.8.1"
num-bigint = "^0.4.3" num-bigint = "^0.4.3"
rand = { version = "^0.8.4", features = ["getrandom"] } rand = { version = "^0.8.5", features = ["getrandom"] }
rsa = { version = "0.9.2", features = ["sha2"] } rsa = { version = "0.9.2", features = ["sha2"] }
rsa_public_encrypt_pkcs1 = "0.4.0" rsa_public_encrypt_pkcs1 = "0.4.0"
sha-1 = "^0.10.0" sha-1 = "^0.10.1"
sha2 = "0.10.6" sha2 = "0.10.7"
uuid = "^1.1.2" uuid = "^1.4.0"
[dev-dependencies] [dev-dependencies]
criterion = { version = "^0.4.0", features = ["html_reports"] } criterion = { version = "^0.5.1", features = ["html_reports"] }
[[bench]] [[bench]]
harness = false harness = false

View file

@ -12,6 +12,6 @@ proc-macro = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
proc-macro2 = "1.0.47" proc-macro2 = "1.0.64"
quote = "1.0.21" quote = "1.0.29"
syn = "1.0.104" syn = "2.0.25"

View file

@ -39,7 +39,7 @@ impl Parse for Menu {
let content; let content;
braced!(content in input); braced!(content in input);
let fields = content let fields = content
.parse_terminated::<Field, Token![,]>(Field::parse)? .parse_terminated(Field::parse, Token![,])?
.into_iter() .into_iter()
.collect(); .collect();
@ -61,7 +61,7 @@ pub struct DeclareMenus {
impl Parse for DeclareMenus { impl Parse for DeclareMenus {
fn parse(input: ParseStream) -> Result<Self> { fn parse(input: ParseStream) -> Result<Self> {
let menus = input let menus = input
.parse_terminated::<Menu, Token![,]>(Menu::parse)? .parse_terminated(Menu::parse, Token![,])?
.into_iter() .into_iter()
.collect(); .collect();
Ok(Self { menus }) Ok(Self { menus })

View file

@ -9,7 +9,7 @@ version = "0.7.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
once_cell = "1.16.0" once_cell = "1.18.0"
serde = "^1.0" serde = "^1.0"
serde_json = "^1.0.93" serde_json = "^1.0.100"
# tokio = {version = "^1.21.2", features = ["fs"]} # tokio = {version = "^1.21.2", features = ["fs"]}

View file

@ -11,18 +11,18 @@ repository = "https://github.com/mat-1/azalea/tree/main/azalea-nbt"
[dependencies] [dependencies]
azalea-buf = { path = "../azalea-buf", version = "^0.7.0" } azalea-buf = { path = "../azalea-buf", version = "^0.7.0" }
byteorder = "^1.4.3" byteorder = "^1.4.3"
compact_str = { version = "0.7.0", features = ["serde"] } compact_str = { version = "0.7.1", features = ["serde"] }
enum-as-inner = "0.5.1" enum-as-inner = "0.6.0"
flate2 = "^1.0.25" flate2 = "^1.0.26"
log = "0.4.17" log = "0.4.19"
packed_simd_2 = "0.3.8" packed_simd_2 = "0.3.8"
serde = { version = "^1.0", features = ["derive"], optional = true } serde = { version = "^1.0", features = ["derive"], optional = true }
[dev-dependencies] [dev-dependencies]
criterion = { version = "^0.4.0", features = ["html_reports"] } criterion = { version = "^0.5.1", features = ["html_reports"] }
graphite_binary = "0.1.0" graphite_binary = "0.1.0"
valence_nbt = "0.4.0" valence_nbt = "0.4.0"
fastnbt = "2.4.3" fastnbt = "2.4.4"
[features] [features]
default = [] default = []

View file

@ -14,11 +14,11 @@ azalea-core = { path = "../azalea-core", version = "^0.7.0" }
azalea-inventory = { version = "0.7.0", path = "../azalea-inventory" } azalea-inventory = { version = "0.7.0", path = "../azalea-inventory" }
azalea-registry = { path = "../azalea-registry", version = "^0.7.0" } azalea-registry = { path = "../azalea-registry", version = "^0.7.0" }
azalea-world = { path = "../azalea-world", version = "^0.7.0" } azalea-world = { path = "../azalea-world", version = "^0.7.0" }
bevy_app = "0.10.0" bevy_app = "0.11.0"
bevy_ecs = "0.10.0" bevy_ecs = "0.11.0"
once_cell = "1.16.0" once_cell = "1.18.0"
parking_lot = "^0.12.1" parking_lot = "^0.12.1"
[dev-dependencies] [dev-dependencies]
bevy_time = "0.10.0" bevy_time = "0.11.0"
uuid = "^1.1.2" uuid = "^1.4.0"

View file

@ -13,12 +13,13 @@ use azalea_world::{
}, },
Instance, InstanceContainer, Instance, InstanceContainer,
}; };
use bevy_app::{App, CoreSchedule, IntoSystemAppConfigs, Plugin}; use bevy_app::{App, FixedUpdate, Plugin, Update};
use bevy_ecs::{ use bevy_ecs::{
entity::Entity, entity::Entity,
event::{EventReader, EventWriter}, event::{EventReader, EventWriter},
prelude::Event,
query::With, query::With,
schedule::{IntoSystemConfig, IntoSystemConfigs, SystemSet}, schedule::{IntoSystemConfigs, SystemSet},
system::{Query, Res}, system::{Query, Res},
}; };
use collision::{move_colliding, MoverType}; use collision::{move_colliding, MoverType};
@ -31,17 +32,13 @@ pub struct PhysicsPlugin;
impl Plugin for PhysicsPlugin { impl Plugin for PhysicsPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_event::<ForceJumpEvent>() app.add_event::<ForceJumpEvent>()
.add_system( .add_systems(
Update,
force_jump_listener force_jump_listener
.before(azalea_world::entity::update_bounding_box) .before(azalea_world::entity::update_bounding_box)
.after(clamp_look_direction), .after(clamp_look_direction),
) )
.add_systems( .add_systems(FixedUpdate, (ai_step, travel).chain().in_set(PhysicsSet));
(ai_step, travel)
.chain()
.in_set(PhysicsSet)
.in_schedule(CoreSchedule::FixedUpdate),
);
} }
} }
@ -170,6 +167,7 @@ pub fn ai_step(
} }
/// Jump even if we aren't on the ground. /// Jump even if we aren't on the ground.
#[derive(Event)]
pub struct ForceJumpEvent(pub Entity); pub struct ForceJumpEvent(pub Entity);
pub fn force_jump_listener( pub fn force_jump_listener(
@ -340,8 +338,7 @@ mod tests {
/// You need an app to spawn entities in the world and do updates. /// You need an app to spawn entities in the world and do updates.
fn make_test_app() -> App { fn make_test_app() -> App {
let mut app = App::new(); let mut app = App::new();
app.add_plugin(PhysicsPlugin) app.add_plugins((PhysicsPlugin, EntityPlugin))
.add_plugin(EntityPlugin)
.insert_resource(FixedTime::new(Duration::from_millis(50))) .insert_resource(FixedTime::new(Duration::from_millis(50)))
.init_resource::<InstanceContainer>(); .init_resource::<InstanceContainer>();
app app
@ -378,7 +375,7 @@ mod tests {
// y should start at 70 // y should start at 70
assert_eq!(entity_pos.y, 70.); assert_eq!(entity_pos.y, 70.);
} }
app.world.run_schedule(CoreSchedule::FixedUpdate); app.world.run_schedule(FixedUpdate);
app.update(); app.update();
{ {
let entity_pos = *app.world.get::<Position>(entity).unwrap(); let entity_pos = *app.world.get::<Position>(entity).unwrap();
@ -387,7 +384,7 @@ mod tests {
let entity_physics = app.world.get::<Physics>(entity).unwrap().clone(); let entity_physics = app.world.get::<Physics>(entity).unwrap().clone();
assert!(entity_physics.delta.y < 0.); assert!(entity_physics.delta.y < 0.);
} }
app.world.run_schedule(CoreSchedule::FixedUpdate); app.world.run_schedule(FixedUpdate);
app.update(); app.update();
{ {
let entity_pos = *app.world.get::<Position>(entity).unwrap(); let entity_pos = *app.world.get::<Position>(entity).unwrap();
@ -440,7 +437,7 @@ mod tests {
block_state.is_some(), block_state.is_some(),
"Block state should exist, if this fails that means the chunk wasn't loaded and the block didn't get placed" "Block state should exist, if this fails that means the chunk wasn't loaded and the block didn't get placed"
); );
app.world.run_schedule(CoreSchedule::FixedUpdate); app.world.run_schedule(FixedUpdate);
app.update(); app.update();
{ {
let entity_pos = *app.world.get::<Position>(entity).unwrap(); let entity_pos = *app.world.get::<Position>(entity).unwrap();
@ -449,7 +446,7 @@ mod tests {
let entity_physics = app.world.get::<Physics>(entity).unwrap().clone(); let entity_physics = app.world.get::<Physics>(entity).unwrap().clone();
assert!(entity_physics.delta.y < 0.); assert!(entity_physics.delta.y < 0.);
} }
app.world.run_schedule(CoreSchedule::FixedUpdate); app.world.run_schedule(FixedUpdate);
app.update(); app.update();
{ {
let entity_pos = *app.world.get::<Position>(entity).unwrap(); let entity_pos = *app.world.get::<Position>(entity).unwrap();
@ -505,7 +502,7 @@ mod tests {
); );
// do a few steps so we fall on the slab // do a few steps so we fall on the slab
for _ in 0..20 { for _ in 0..20 {
app.world.run_schedule(CoreSchedule::FixedUpdate); app.world.run_schedule(FixedUpdate);
app.update(); app.update();
} }
let entity_pos = app.world.get::<Position>(entity).unwrap(); let entity_pos = app.world.get::<Position>(entity).unwrap();
@ -558,7 +555,7 @@ mod tests {
); );
// do a few steps so we fall on the slab // do a few steps so we fall on the slab
for _ in 0..20 { for _ in 0..20 {
app.world.run_schedule(CoreSchedule::FixedUpdate); app.world.run_schedule(FixedUpdate);
app.update(); app.update();
} }
let entity_pos = app.world.get::<Position>(entity).unwrap(); let entity_pos = app.world.get::<Position>(entity).unwrap();
@ -615,7 +612,7 @@ mod tests {
); );
// do a few steps so we fall on the wall // do a few steps so we fall on the wall
for _ in 0..20 { for _ in 0..20 {
app.world.run_schedule(CoreSchedule::FixedUpdate); app.world.run_schedule(FixedUpdate);
app.update(); app.update();
} }
@ -677,7 +674,7 @@ mod tests {
); );
// do a few steps so we fall on the wall // do a few steps so we fall on the wall
for _ in 0..20 { for _ in 0..20 {
app.world.run_schedule(CoreSchedule::FixedUpdate); app.world.run_schedule(FixedUpdate);
app.update(); app.update();
} }

View file

@ -9,11 +9,11 @@ version = "0.7.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
async-compression = { version = "^0.3.8", features = [ async-compression = { version = "^0.4.0", features = [
"tokio", "tokio",
"zlib", "zlib",
], optional = true } ], optional = true }
async-recursion = "1.0.0" async-recursion = "1.0.4"
azalea-auth = { path = "../azalea-auth", version = "^0.7.0" } azalea-auth = { path = "../azalea-auth", version = "^0.7.0" }
azalea-block = { path = "../azalea-block", default-features = false, version = "^0.7.0" } azalea-block = { path = "../azalea-block", default-features = false, version = "^0.7.0" }
azalea-brigadier = { path = "../azalea-brigadier", version = "^0.7.0", features = [ azalea-brigadier = { path = "../azalea-brigadier", version = "^0.7.0", features = [
@ -32,22 +32,22 @@ azalea-nbt = { path = "../azalea-nbt", version = "^0.7.0", features = [
azalea-protocol-macros = { path = "./azalea-protocol-macros", version = "^0.7.0" } azalea-protocol-macros = { path = "./azalea-protocol-macros", version = "^0.7.0" }
azalea-registry = { path = "../azalea-registry", version = "^0.7.0" } azalea-registry = { path = "../azalea-registry", version = "^0.7.0" }
azalea-world = { path = "../azalea-world", version = "^0.7.0" } azalea-world = { path = "../azalea-world", version = "^0.7.0" }
bevy_ecs = { version = "0.10.0", default-features = false } bevy_ecs = { version = "0.11.0", default-features = false }
byteorder = "^1.4.3" byteorder = "^1.4.3"
bytes = "^1.1.0" bytes = "^1.4.0"
flate2 = "1.0.25" flate2 = "1.0.26"
futures = "0.3.24" futures = "0.3.28"
futures-util = "0.3.24" futures-util = "0.3.28"
log = "0.4.17" log = "0.4.19"
serde = { version = "^1.0", features = ["serde_derive"] } serde = { version = "^1.0", features = ["serde_derive"] }
serde_json = "^1.0.93" serde_json = "^1.0.100"
thiserror = "1.0.37" thiserror = "1.0.43"
tokio = { version = "^1.24.2", features = ["io-util", "net", "macros"] } tokio = { version = "^1.29.1", features = ["io-util", "net", "macros"] }
tokio-util = { version = "0.7.4", features = ["codec"] } tokio-util = { version = "0.7.8", features = ["codec"] }
trust-dns-resolver = { version = "^0.22.0", default-features = false, features = [ trust-dns-resolver = { version = "^0.22.0", default-features = false, features = [
"tokio-runtime", "tokio-runtime",
] } ] }
uuid = "1.1.2" uuid = "1.4.0"
[features] [features]
connecting = [] connecting = []
@ -56,7 +56,7 @@ packets = ["connecting", "dep:async-compression", "dep:azalea-core"]
strict_registry = ["packets"] strict_registry = ["packets"]
[dev-dependencies] [dev-dependencies]
anyhow = "^1.0.65" anyhow = "^1.0.71"
tracing = "^0.1.36" tracing = "^0.1.37"
tracing-subscriber = "^0.3.15" tracing-subscriber = "^0.3.17"
once_cell = "1.17.0" once_cell = "1.18.0"

View file

@ -11,6 +11,6 @@ proc-macro = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
proc-macro2 = "^1.0.36" proc-macro2 = "^1.0.64"
quote = "^1.0.10" quote = "^1.0.29"
syn = "^1.0.82" syn = "^2.0.25"

View file

@ -142,6 +142,7 @@ mod tests {
}), }),
criteria: HashMap::new(), criteria: HashMap::new(),
requirements: Vec::new(), requirements: Vec::new(),
sends_telemetry_event: false,
}, },
)] )]
.into_iter() .into_iter()

View file

@ -12,9 +12,9 @@ proc-macro = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
proc-macro2 = "1.0.39" proc-macro2 = "1.0.64"
quote = "1.0.18" quote = "1.0.29"
syn = "1.0.95" syn = "2.0.25"
[features] [features]
serde = [] serde = []

View file

@ -43,8 +43,8 @@ impl Parse for Registry {
let name = input.parse()?; let name = input.parse()?;
let content; let content;
braced!(content in input); braced!(content in input);
let items: Punctuated<RegistryItem, Token![,]> = let items: Punctuated<RegistryItem, _> =
content.parse_terminated(RegistryItem::parse)?; content.parse_terminated(RegistryItem::parse, Token![,])?;
Ok(Registry { Ok(Registry {
name, name,

View file

@ -18,16 +18,16 @@ azalea-core = { path = "../azalea-core", version = "^0.7.0", features = [
azalea-inventory = { version = "0.7.0", path = "../azalea-inventory" } azalea-inventory = { version = "0.7.0", path = "../azalea-inventory" }
azalea-nbt = { path = "../azalea-nbt", version = "^0.7.0" } azalea-nbt = { path = "../azalea-nbt", version = "^0.7.0" }
azalea-registry = { path = "../azalea-registry", version = "^0.7.0" } azalea-registry = { path = "../azalea-registry", version = "^0.7.0" }
bevy_app = "0.10.0" bevy_app = "0.11.0"
bevy_ecs = "0.10.0" bevy_ecs = "0.11.0"
derive_more = { version = "0.99.17", features = ["deref", "deref_mut"] } derive_more = { version = "0.99.17", features = ["deref", "deref_mut"] }
enum-as-inner = "0.5.1" enum-as-inner = "0.6.0"
log = "0.4.17" log = "0.4.19"
nohash-hasher = "0.2.0" nohash-hasher = "0.2.0"
once_cell = "1.16.0" once_cell = "1.18.0"
parking_lot = "^0.12.1" parking_lot = "^0.12.1"
thiserror = "1.0.34" thiserror = "1.0.43"
uuid = "1.1.2" uuid = "1.4.0"
[profile.release] [profile.release]
lto = true lto = true

View file

@ -9,12 +9,12 @@ use crate::{
update_entity_by_id_index, update_uuid_index, InstanceContainer, PartialInstance, update_entity_by_id_index, update_uuid_index, InstanceContainer, PartialInstance,
}; };
use azalea_core::ChunkPos; use azalea_core::ChunkPos;
use bevy_app::{App, CoreSet, Plugin}; use bevy_app::{App, Plugin, PostUpdate, PreUpdate, Update};
use bevy_ecs::{ use bevy_ecs::{
component::Component, component::Component,
entity::Entity, entity::Entity,
query::{Added, Changed, With, Without}, query::{Added, Changed, With, Without},
schedule::{IntoSystemConfig, IntoSystemConfigs, SystemSet}, schedule::{IntoSystemConfigs, SystemSet},
system::{Commands, EntityCommand, Query, Res, ResMut, Resource}, system::{Commands, EntityCommand, Query, Res, ResMut, Resource},
world::{EntityMut, World}, world::{EntityMut, World},
}; };
@ -51,32 +51,33 @@ impl Plugin for EntityPlugin {
// added to indexes during update (done by this plugin) // added to indexes during update (done by this plugin)
// modified during update // modified during update
// despawned post-update (done by this plugin) // despawned post-update (done by this plugin)
app.add_system( app.add_systems(
remove_despawned_entities_from_indexes PreUpdate,
.in_base_set(CoreSet::PreUpdate) remove_despawned_entities_from_indexes.in_set(EntityUpdateSet::Deindex),
.in_set(EntityUpdateSet::Deindex),
) )
.add_systems( .add_systems(
(deduplicate_entities, deduplicate_local_entities) PostUpdate,
.in_base_set(CoreSet::PostUpdate) (deduplicate_entities, deduplicate_local_entities).in_set(EntityUpdateSet::Deduplicate),
.in_set(EntityUpdateSet::Deduplicate),
) )
.add_systems( .add_systems(
Update,
( (
update_entity_chunk_positions, (
update_uuid_index, update_entity_chunk_positions,
update_entity_by_id_index, update_uuid_index,
) update_entity_by_id_index,
.in_set(EntityUpdateSet::Index), )
.in_set(EntityUpdateSet::Index),
(
add_updates_received,
debug_new_entity,
debug_detect_updates_received_on_local_entities,
add_dead,
update_bounding_box,
clamp_look_direction,
),
),
) )
.add_systems((
add_updates_received,
debug_new_entity,
debug_detect_updates_received_on_local_entities,
add_dead,
update_bounding_box,
clamp_look_direction,
))
.init_resource::<EntityInfos>(); .init_resource::<EntityInfos>();
} }
} }
@ -152,7 +153,7 @@ pub struct RelativeEntityUpdate {
pub update: Box<dyn FnOnce(&mut EntityMut) + Send + Sync>, pub update: Box<dyn FnOnce(&mut EntityMut) + Send + Sync>,
} }
impl EntityCommand for RelativeEntityUpdate { impl EntityCommand for RelativeEntityUpdate {
fn write(self, entity: Entity, world: &mut World) { fn apply(self, entity: Entity, world: &mut World) {
let partial_entity_infos = &mut self.partial_world.write().entity_infos; let partial_entity_infos = &mut self.partial_world.write().entity_infos;
let mut entity_mut = world.entity_mut(entity); let mut entity_mut = world.entity_mut(entity);

View file

@ -12,8 +12,8 @@ pre-release-replacements = [
] ]
[dependencies] [dependencies]
anyhow = "^1.0.65" anyhow = "^1.0.71"
async-trait = "0.1.58" async-trait = "0.1.71"
azalea-block = { version = "0.7.0", path = "../azalea-block" } azalea-block = { version = "0.7.0", path = "../azalea-block" }
azalea-chat = { version = "0.7.0", path = "../azalea-chat" } azalea-chat = { version = "0.7.0", path = "../azalea-chat" }
azalea-client = { version = "0.7.0", path = "../azalea-client" } azalea-client = { version = "0.7.0", path = "../azalea-client" }
@ -25,21 +25,21 @@ azalea-registry = { version = "0.7.0", path = "../azalea-registry" }
azalea-world = { version = "0.7.0", path = "../azalea-world" } azalea-world = { version = "0.7.0", path = "../azalea-world" }
azalea-auth = { version = "0.7.0", path = "../azalea-auth" } azalea-auth = { version = "0.7.0", path = "../azalea-auth" }
azalea-brigadier = { version = "0.7.0", path = "../azalea-brigadier" } azalea-brigadier = { version = "0.7.0", path = "../azalea-brigadier" }
bevy_app = "0.10.0" bevy_app = "0.11.0"
bevy_ecs = "0.10.0" bevy_ecs = "0.11.0"
bevy_tasks = "0.10.0" bevy_tasks = "0.11.0"
derive_more = { version = "0.99.17", features = ["deref", "deref_mut"] } derive_more = { version = "0.99.17", features = ["deref", "deref_mut"] }
futures = "0.3.25" futures = "0.3.28"
futures-lite = "1.12.0" futures-lite = "1.13.0"
log = "0.4.17" log = "0.4.19"
nohash-hasher = "0.2.0" nohash-hasher = "0.2.0"
num-traits = "0.2.15" num-traits = "0.2.15"
parking_lot = { version = "^0.12.1", features = ["deadlock_detection"] } parking_lot = { version = "^0.12.1", features = ["deadlock_detection"] }
priority-queue = "1.3.0" priority-queue = "1.3.2"
thiserror = "^1.0.37" thiserror = "^1.0.43"
tokio = "^1.24.2" tokio = "^1.29.1"
uuid = "1.2.2" uuid = "1.4.0"
bevy_log = "0.10.1" bevy_log = "0.11.0"
[features] [features]
default = ["log"] default = ["log"]

View file

@ -1,6 +1,7 @@
use crate::app::{App, Plugin}; use crate::app::{App, Plugin};
use azalea_client::packet_handling::DeathEvent; use azalea_client::packet_handling::DeathEvent;
use azalea_client::respawn::{perform_respawn, PerformRespawnEvent}; use azalea_client::respawn::{perform_respawn, PerformRespawnEvent};
use bevy_app::Update;
use bevy_ecs::prelude::*; use bevy_ecs::prelude::*;
/// A plugin that makes [`DeathEvent`]s send [`PerformRespawnEvent`]s. /// A plugin that makes [`DeathEvent`]s send [`PerformRespawnEvent`]s.
@ -8,7 +9,7 @@ use bevy_ecs::prelude::*;
pub struct AutoRespawnPlugin; pub struct AutoRespawnPlugin;
impl Plugin for AutoRespawnPlugin { impl Plugin for AutoRespawnPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_system(auto_respawn.before(perform_respawn)); app.add_systems(Update, auto_respawn.before(perform_respawn));
} }
} }

View file

@ -1,4 +1,4 @@
use crate::app::{App, CoreSchedule, IntoSystemAppConfig, Plugin, PluginGroup, PluginGroupBuilder}; use crate::app::{App, Plugin, PluginGroup, PluginGroupBuilder};
use crate::auto_respawn::AutoRespawnPlugin; use crate::auto_respawn::AutoRespawnPlugin;
use crate::container::ContainerPlugin; use crate::container::ContainerPlugin;
use crate::ecs::{ use crate::ecs::{
@ -6,13 +6,15 @@ use crate::ecs::{
entity::Entity, entity::Entity,
event::EventReader, event::EventReader,
query::{With, Without}, query::{With, Without},
schedule::IntoSystemConfig,
system::{Commands, Query}, system::{Commands, Query},
}; };
use azalea_core::Vec3; use azalea_core::Vec3;
use azalea_physics::{force_jump_listener, PhysicsSet}; use azalea_physics::{force_jump_listener, PhysicsSet};
use azalea_world::entity::{clamp_look_direction, EyeHeight, LookDirection}; use azalea_world::entity::{clamp_look_direction, EyeHeight, LookDirection};
use azalea_world::entity::{metadata::Player, Jumping, Local, Position}; use azalea_world::entity::{metadata::Player, Jumping, Local, Position};
use bevy_app::{FixedUpdate, Update};
use bevy_ecs::prelude::Event;
use bevy_ecs::schedule::IntoSystemConfigs;
use std::f64::consts::PI; use std::f64::consts::PI;
use crate::pathfinder::PathfinderPlugin; use crate::pathfinder::PathfinderPlugin;
@ -23,16 +25,17 @@ impl Plugin for BotPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_event::<LookAtEvent>() app.add_event::<LookAtEvent>()
.add_event::<JumpEvent>() .add_event::<JumpEvent>()
.add_systems(( .add_systems(
insert_bot, Update,
look_at_listener (
.before(force_jump_listener) insert_bot,
.before(clamp_look_direction), look_at_listener
jump_listener, .before(force_jump_listener)
stop_jumping .before(clamp_look_direction),
.in_schedule(CoreSchedule::FixedUpdate) jump_listener,
.after(PhysicsSet), ),
)); )
.add_systems(FixedUpdate, stop_jumping.after(PhysicsSet));
} }
} }
@ -85,6 +88,7 @@ impl BotClientExt for azalea_client::Client {
} }
/// Event to jump once. /// Event to jump once.
#[derive(Event)]
pub struct JumpEvent(pub Entity); pub struct JumpEvent(pub Entity);
fn jump_listener(mut query: Query<(&mut Jumping, &mut Bot)>, mut events: EventReader<JumpEvent>) { fn jump_listener(mut query: Query<(&mut Jumping, &mut Bot)>, mut events: EventReader<JumpEvent>) {
@ -97,6 +101,7 @@ fn jump_listener(mut query: Query<(&mut Jumping, &mut Bot)>, mut events: EventRe
} }
/// Make an entity look towards a certain position in the world. /// Make an entity look towards a certain position in the world.
#[derive(Event)]
pub struct LookAtEvent { pub struct LookAtEvent {
pub entity: Entity, pub entity: Entity,
/// The position we want the entity to be looking at. /// The position we want the entity to be looking at.

View file

@ -8,14 +8,14 @@ use azalea_client::{
use azalea_core::BlockPos; use azalea_core::BlockPos;
use azalea_inventory::{operations::ClickOperation, ItemSlot, Menu}; use azalea_inventory::{operations::ClickOperation, ItemSlot, Menu};
use azalea_protocol::packets::game::ClientboundGamePacket; use azalea_protocol::packets::game::ClientboundGamePacket;
use bevy_app::{App, Plugin}; use bevy_app::{App, Plugin, Update};
use bevy_ecs::{component::Component, prelude::EventReader, system::Commands}; use bevy_ecs::{component::Component, prelude::EventReader, system::Commands};
use std::fmt::Debug; use std::fmt::Debug;
pub struct ContainerPlugin; pub struct ContainerPlugin;
impl Plugin for ContainerPlugin { impl Plugin for ContainerPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_system(handle_menu_opened_event); app.add_systems(Update, handle_menu_opened_event);
} }
} }

View file

@ -10,7 +10,7 @@ pub mod pathfinder;
pub mod prelude; pub mod prelude;
pub mod swarm; pub mod swarm;
use app::{App, Plugin, PluginGroup}; use app::{App, Plugins};
pub use azalea_auth as auth; pub use azalea_auth as auth;
pub use azalea_block as blocks; pub use azalea_block as blocks;
pub use azalea_brigadier as brigadier; pub use azalea_brigadier as brigadier;
@ -148,16 +148,10 @@ where
self.state = state; self.state = state;
self self
} }
/// Add a plugin to the client.
#[must_use]
pub fn add_plugin<T: Plugin>(mut self, plugin: T) -> Self {
self.app.add_plugin(plugin);
self
}
/// Add a group of plugins to the client. /// Add a group of plugins to the client.
#[must_use] #[must_use]
pub fn add_plugins<T: PluginGroup>(mut self, plugin_group: T) -> Self { pub fn add_plugins<M>(mut self, plugins: impl Plugins<M>) -> Self {
self.app.add_plugins(plugin_group); self.app.add_plugins(plugins);
self self
} }

View file

@ -5,13 +5,12 @@ use crate::bot::{JumpEvent, LookAtEvent};
use crate::pathfinder::astar::a_star; use crate::pathfinder::astar::a_star;
use crate::{SprintDirection, WalkDirection}; use crate::{SprintDirection, WalkDirection};
use crate::app::{App, CoreSchedule, IntoSystemAppConfig, Plugin}; use crate::app::{App, Plugin};
use crate::ecs::{ use crate::ecs::{
component::Component, component::Component,
entity::Entity, entity::Entity,
event::{EventReader, EventWriter}, event::{EventReader, EventWriter},
query::{With, Without}, query::{With, Without},
schedule::IntoSystemConfig,
system::{Commands, Query, Res}, system::{Commands, Query, Res},
}; };
use astar::Edge; use astar::Edge;
@ -24,6 +23,9 @@ use azalea_world::{
entity::{Physics, Position, WorldName}, entity::{Physics, Position, WorldName},
InstanceContainer, InstanceContainer,
}; };
use bevy_app::{FixedUpdate, Update};
use bevy_ecs::prelude::Event;
use bevy_ecs::schedule::IntoSystemConfigs;
use bevy_tasks::{AsyncComputeTaskPool, Task}; use bevy_tasks::{AsyncComputeTaskPool, Task};
use futures_lite::future; use futures_lite::future;
use log::{debug, error}; use log::{debug, error};
@ -36,17 +38,20 @@ impl Plugin for PathfinderPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_event::<GotoEvent>() app.add_event::<GotoEvent>()
.add_event::<PathFoundEvent>() .add_event::<PathFoundEvent>()
.add_system( .add_systems(
// Adding `.in_schedule(CoreSchedule::FixedUpdate)` makes a system run every FixedUpdate,
// Minecraft tick (every 50 milliseconds). // putting systems in the FixedUpdate schedule makes them run every Minecraft tick
tick_execute_path // (every 50 milliseconds).
.in_schedule(CoreSchedule::FixedUpdate) tick_execute_path.before(PhysicsSet),
.before(PhysicsSet),
) )
.add_system(goto_listener) .add_systems(
.add_system(add_default_pathfinder) Update,
.add_system(handle_tasks.before(path_found_listener)) (
.add_system(path_found_listener); goto_listener,
add_default_pathfinder,
(handle_tasks, path_found_listener).chain(),
),
);
} }
} }
@ -84,10 +89,12 @@ impl PathfinderClientExt for azalea_client::Client {
}); });
} }
} }
#[derive(Event)]
pub struct GotoEvent { pub struct GotoEvent {
pub entity: Entity, pub entity: Entity,
pub goal: Arc<dyn Goal + Send + Sync>, pub goal: Arc<dyn Goal + Send + Sync>,
} }
#[derive(Event)]
pub struct PathFoundEvent { pub struct PathFoundEvent {
pub entity: Entity, pub entity: Entity,
pub path: VecDeque<Node>, pub path: VecDeque<Node>,

View file

@ -20,7 +20,8 @@ use crate::ecs::{
system::{Commands, Query, Res, ResMut, Resource}, system::{Commands, Query, Res, ResMut, Resource},
}; };
use azalea_client::chat::{ChatPacket, ChatReceivedEvent}; use azalea_client::chat::{ChatPacket, ChatReceivedEvent};
use bevy_app::{App, Plugin}; use bevy_app::{App, Plugin, Update};
use bevy_ecs::prelude::Event;
use std::collections::VecDeque; use std::collections::VecDeque;
use super::{Swarm, SwarmEvent}; use super::{Swarm, SwarmEvent};
@ -30,7 +31,10 @@ pub struct SwarmChatPlugin;
impl Plugin for SwarmChatPlugin { impl Plugin for SwarmChatPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_event::<NewChatMessageEvent>() app.add_event::<NewChatMessageEvent>()
.add_systems((chat_listener, update_min_index_and_shrink_queue).chain()) .add_systems(
Update,
(chat_listener, update_min_index_and_shrink_queue).chain(),
)
.insert_resource(GlobalChatState { .insert_resource(GlobalChatState {
chat_queue: VecDeque::new(), chat_queue: VecDeque::new(),
chat_min_index: 0, chat_min_index: 0,
@ -44,7 +48,7 @@ pub struct ClientChatState {
} }
/// A chat message that no other bots have seen yet was received by a bot. /// A chat message that no other bots have seen yet was received by a bot.
#[derive(Debug)] #[derive(Event, Debug)]
pub struct NewChatMessageEvent(ChatPacket); pub struct NewChatMessageEvent(ChatPacket);
#[derive(Resource)] #[derive(Resource)]
@ -160,7 +164,10 @@ mod tests {
// event mangement in drain_events // event mangement in drain_events
app.init_resource::<Events<ChatReceivedEvent>>() app.init_resource::<Events<ChatReceivedEvent>>()
.init_resource::<Events<NewChatMessageEvent>>() .init_resource::<Events<NewChatMessageEvent>>()
.add_systems((chat_listener, update_min_index_and_shrink_queue).chain()) .add_systems(
Update,
(chat_listener, update_min_index_and_shrink_queue).chain(),
)
.insert_resource(GlobalChatState { .insert_resource(GlobalChatState {
chat_queue: VecDeque::new(), chat_queue: VecDeque::new(),
chat_min_index: 0, chat_min_index: 0,

View file

@ -1,6 +1,6 @@
use azalea_client::LocalPlayer; use azalea_client::LocalPlayer;
use azalea_world::entity::MinecraftEntityId; use azalea_world::entity::MinecraftEntityId;
use bevy_app::{App, Plugin}; use bevy_app::{App, Plugin, Update};
use bevy_ecs::prelude::*; use bevy_ecs::prelude::*;
use derive_more::{Deref, DerefMut}; use derive_more::{Deref, DerefMut};
@ -8,12 +8,13 @@ pub struct SwarmPlugin;
impl Plugin for SwarmPlugin { impl Plugin for SwarmPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_event::<SwarmReadyEvent>() app.add_event::<SwarmReadyEvent>()
.add_system(check_ready) .add_systems(Update, check_ready)
.init_resource::<IsSwarmReady>(); .init_resource::<IsSwarmReady>();
} }
} }
/// All the bots from the swarm are now in the world. /// All the bots from the swarm are now in the world.
#[derive(Event)]
pub struct SwarmReadyEvent; pub struct SwarmReadyEvent;
#[derive(Default, Resource, Deref, DerefMut)] #[derive(Default, Resource, Deref, DerefMut)]

View file

@ -14,7 +14,7 @@ use azalea_protocol::{
ServerAddress, ServerAddress,
}; };
use azalea_world::InstanceContainer; use azalea_world::InstanceContainer;
use bevy_app::{App, Plugin, PluginGroup, PluginGroupBuilder}; use bevy_app::{App, PluginGroup, PluginGroupBuilder, Plugins};
use bevy_ecs::{component::Component, entity::Entity, system::Resource, world::World}; use bevy_ecs::{component::Component, entity::Entity, system::Resource, world::World};
use futures::future::join_all; use futures::future::join_all;
use log::error; use log::error;
@ -234,16 +234,10 @@ where
self self
} }
/// Add a plugin to the swarm. /// Add one or more plugins to this swarm.
#[must_use] #[must_use]
pub fn add_plugin<T: Plugin>(mut self, plugin: T) -> Self { pub fn add_plugins<M>(mut self, plugins: impl Plugins<M>) -> Self {
self.app.add_plugin(plugin); self.app.add_plugins(plugins);
self
}
/// Add a group of plugins to the swarm.
#[must_use]
pub fn add_plugins<T: PluginGroup>(mut self, plugin_group: T) -> Self {
self.app.add_plugins(plugin_group);
self self
} }