aboutsummaryrefslogtreecommitdiff
path: root/azalea
diff options
context:
space:
mode:
authorEightFactorial <29801334+EightFactorial@users.noreply.github.com>2024-12-04 16:31:22 -0800
committerGitHub <noreply@github.com>2024-12-04 18:31:22 -0600
commit6379035b852f1b619565d27f5cee3b93042c2312 (patch)
tree30c858cfaf841d0fcc5a139f1507b9b67d768e8b /azalea
parent241c7527ce11177082dcc0ebc4152506946ee684 (diff)
downloadazalea-drasl-6379035b852f1b619565d27f5cee3b93042c2312.tar.xz
Update Bevy and migrate to workspace dependencies and package attributes (#181)
* Use workspace `Cargo.toml` for dependencies and package atributes * Fix a couple clippy warnings * Update bevy, update build script, move deps to workspace, and fix clippy warnings * Remove carrots from crate versions The default behavior is the same * Remove unused dependencies Compiles and all tests pass, so it should be fine * Update codegen to use `std::sync::LazyLock` instead of `once_cell::sync::Lazy` * Update Bevy to `0.15.0-rc.3` Surprisingly little needed to be changed * Update to bevy 0.15.0 * Fix leftover merge issues * Clarify the reason the swarm can't connect * Fix duplicate lint, remove `log` dependency
Diffstat (limited to 'azalea')
-rw-r--r--azalea/Cargo.toml12
-rw-r--r--azalea/build.rs41
-rw-r--r--azalea/src/pathfinder/mod.rs2
-rw-r--r--azalea/src/pathfinder/simulation.rs16
-rw-r--r--azalea/src/swarm/chat.rs36
-rw-r--r--azalea/src/swarm/mod.rs14
6 files changed, 68 insertions, 53 deletions
diff --git a/azalea/Cargo.toml b/azalea/Cargo.toml
index 504280cf..a658c3a8 100644
--- a/azalea/Cargo.toml
+++ b/azalea/Cargo.toml
@@ -1,10 +1,10 @@
[package]
-description = "A framework for creating Minecraft bots."
-edition = "2021"
-license = "MIT"
name = "azalea"
-repository = "https://github.com/azalea-rs/azalea/tree/main/azalea"
-version = "0.10.3+mc1.21.4"
+description = "A framework for creating Minecraft bots."
+version = { workspace = true }
+edition = { workspace = true }
+license = { workspace = true }
+repository = { workspace = true }
[package.metadata.release]
pre-release-replacements = [
@@ -30,7 +30,7 @@ azalea-world = { version = "0.10.0", path = "../azalea-world" }
bevy_app = { workspace = true }
bevy_ecs = { workspace = true }
bevy_log = { workspace = true }
-bevy_tasks = { workspace = true, features = ["multi-threaded"] }
+bevy_tasks = { workspace = true, features = ["multi_threaded"] }
#bevy_time = { workspace = true }
derive_more = { workspace = true, features = ["deref", "deref_mut"] }
futures = { workspace = true }
diff --git a/azalea/build.rs b/azalea/build.rs
index 9a503749..18300151 100644
--- a/azalea/build.rs
+++ b/azalea/build.rs
@@ -2,25 +2,30 @@ use std::env;
use std::process::Command;
fn main() {
- match env::var("RUSTUP_TOOLCHAIN") {
- Ok(rust_toolchain) if !rust_toolchain.starts_with("nightly") => {
- // stable & beta
- panic!("Azalea currently requires nightly Rust. You can use `rustup override set nightly` to set the toolchain for this directory.");
+ // If using `rustup`, check the toolchain via `RUSTUP_TOOLCHAIN`
+ if let Ok(toolchain) = env::var("RUSTUP_TOOLCHAIN") {
+ if toolchain.contains("nightly") {
+ return;
+ } else {
+ panic!("Azalea currently requires nightly Rust. You can run `rustup override set nightly` to set the toolchain for this directory.");
}
- Ok(_) => {} // nightly
- Err(_) => {
- // probably not installed via rustup, run rustc and parse its output
- let rustc_command = env::var("RUSTC")
- .or_else(|_| env::var("CARGO_BUILD_RUSTC"))
- .unwrap_or(String::from("rustc"));
- let rustc_version_output = Command::new(rustc_command).arg("-V").output().unwrap();
- if !rustc_version_output.status.success()
- || !String::from_utf8(rustc_version_output.stdout)
- .unwrap()
- .contains("nightly")
- {
- panic!("Azalea currently requires nightly Rust. It seems that you did not install Rust via rustup. Please check the documentation for your installation method, to find out how to use nightly Rust.");
- }
+ }
+
+ // Get the path to the Rust compiler, defaulting to `rustc`
+ let rustc_path = env::var("RUSTC")
+ .or_else(|_| env::var("CARGO_BUILD_RUSTC"))
+ .unwrap_or(String::from("rustc"));
+
+ // Run `rustc -V` to check the toolchain version
+ let rustc_command = Command::new(&rustc_path).arg("-V").output().unwrap();
+
+ if rustc_command.status.success() {
+ let rustc_output = String::from_utf8(rustc_command.stdout).unwrap();
+ if !rustc_output.contains("nightly") {
+ panic!("Azalea currently requires nightly Rust. Please check the documentation for your installation method and ensure you are using the nightly toolchain.");
}
+ } else {
+ let rustc_output = String::from_utf8(rustc_command.stderr).unwrap();
+ panic!("Failed to run `{rustc_path} -V` to check the toolchain version, {rustc_output}");
}
}
diff --git a/azalea/src/pathfinder/mod.rs b/azalea/src/pathfinder/mod.rs
index 88ae5da0..eab07348 100644
--- a/azalea/src/pathfinder/mod.rs
+++ b/azalea/src/pathfinder/mod.rs
@@ -875,7 +875,7 @@ mod tests {
// filter: "".to_string(),
// });
- simulation.app.world.send_event(GotoEvent {
+ simulation.app.world_mut().send_event(GotoEvent {
entity: simulation.entity,
goal: Arc::new(BlockPosGoal(end_pos)),
successors_fn: moves::default_move,
diff --git a/azalea/src/pathfinder/simulation.rs b/azalea/src/pathfinder/simulation.rs
index ae76896c..ca15fb7a 100644
--- a/azalea/src/pathfinder/simulation.rs
+++ b/azalea/src/pathfinder/simulation.rs
@@ -130,7 +130,7 @@ pub struct Simulation {
impl Simulation {
pub fn new(chunks: ChunkStorage, player: SimulatedPlayerBundle) -> Self {
let (mut app, instance) = create_simulation_instance(chunks);
- let entity = create_simulation_player(&mut app.world, instance.clone(), player);
+ let entity = create_simulation_player(app.world_mut(), instance.clone(), player);
Self {
app,
entity,
@@ -140,13 +140,13 @@ impl Simulation {
pub fn tick(&mut self) {
self.app.update();
- self.app.world.run_schedule(GameTick);
+ self.app.world_mut().run_schedule(GameTick);
}
pub fn component<T: Component + Clone>(&self) -> T {
- self.app.world.get::<T>(self.entity).unwrap().clone()
+ self.app.world().get::<T>(self.entity).unwrap().clone()
}
pub fn get_component<T: Component + Clone>(&self) -> Option<T> {
- self.app.world.get::<T>(self.entity).cloned()
+ self.app.world().get::<T>(self.entity).cloned()
}
pub fn position(&self) -> Vec3 {
*self.component::<Position>()
@@ -171,17 +171,17 @@ impl SimulationSet {
}
pub fn tick(&mut self) {
self.app.update();
- self.app.world.run_schedule(GameTick);
+ self.app.world_mut().run_schedule(GameTick);
}
pub fn spawn(&mut self, player: SimulatedPlayerBundle) -> Entity {
- create_simulation_player(&mut self.app.world, self.instance.clone(), player)
+ create_simulation_player(self.app.world_mut(), self.instance.clone(), player)
}
pub fn despawn(&mut self, entity: Entity) {
- self.app.world.despawn(entity);
+ self.app.world_mut().despawn(entity);
}
pub fn position(&self, entity: Entity) -> Vec3 {
- **self.app.world.get::<Position>(entity).unwrap()
+ **self.app.world().get::<Position>(entity).unwrap()
}
}
diff --git a/azalea/src/swarm/chat.rs b/azalea/src/swarm/chat.rs
index cf01c60b..f56c1511 100644
--- a/azalea/src/swarm/chat.rs
+++ b/azalea/src/swarm/chat.rs
@@ -188,70 +188,70 @@ mod tests {
async fn test_swarm_chat() {
let mut app = make_test_app();
- let bot0 = app.world.spawn_empty().id();
- let bot1 = app.world.spawn_empty().id();
+ let bot0 = app.world_mut().spawn_empty().id();
+ let bot1 = app.world_mut().spawn_empty().id();
- app.world.send_event(ChatReceivedEvent {
+ app.world_mut().send_event(ChatReceivedEvent {
entity: bot0,
packet: ChatPacket::new("a"),
});
app.update();
// the swarm should get the event immediately after the bot gets it
- assert_eq!(drain_events(&mut app.world), vec![ChatPacket::new("a")]);
+ assert_eq!(drain_events(app.world_mut()), vec![ChatPacket::new("a")]);
assert_eq!(
- app.world.get::<ClientChatState>(bot0).unwrap().chat_index,
+ app.world().get::<ClientChatState>(bot0).unwrap().chat_index,
1
);
// and a second bot sending the event shouldn't do anything
- app.world.send_event(ChatReceivedEvent {
+ app.world_mut().send_event(ChatReceivedEvent {
entity: bot1,
packet: ChatPacket::new("a"),
});
app.update();
- assert_eq!(drain_events(&mut app.world), vec![]);
+ assert_eq!(drain_events(app.world_mut()), vec![]);
assert_eq!(
- app.world.get::<ClientChatState>(bot1).unwrap().chat_index,
+ app.world().get::<ClientChatState>(bot1).unwrap().chat_index,
1
);
// but if the first one gets it again, it should sent it again
- app.world.send_event(ChatReceivedEvent {
+ app.world_mut().send_event(ChatReceivedEvent {
entity: bot0,
packet: ChatPacket::new("a"),
});
app.update();
- assert_eq!(drain_events(&mut app.world), vec![ChatPacket::new("a")]);
+ assert_eq!(drain_events(app.world_mut()), vec![ChatPacket::new("a")]);
// alright and now the second bot got a different chat message and it should be
// sent
- app.world.send_event(ChatReceivedEvent {
+ app.world_mut().send_event(ChatReceivedEvent {
entity: bot1,
packet: ChatPacket::new("b"),
});
app.update();
- assert_eq!(drain_events(&mut app.world), vec![ChatPacket::new("b")]);
+ assert_eq!(drain_events(app.world_mut()), vec![ChatPacket::new("b")]);
}
#[tokio::test]
async fn test_new_bot() {
let mut app = make_test_app();
- let bot0 = app.world.spawn_empty().id();
+ let bot0 = app.world_mut().spawn_empty().id();
// bot0 gets a chat message
- app.world.send_event(ChatReceivedEvent {
+ app.world_mut().send_event(ChatReceivedEvent {
entity: bot0,
packet: ChatPacket::new("a"),
});
app.update();
- assert_eq!(drain_events(&mut app.world), vec![ChatPacket::new("a")]);
- let bot1 = app.world.spawn_empty().id();
- app.world.send_event(ChatReceivedEvent {
+ assert_eq!(drain_events(app.world_mut()), vec![ChatPacket::new("a")]);
+ let bot1 = app.world_mut().spawn_empty().id();
+ app.world_mut().send_event(ChatReceivedEvent {
entity: bot1,
packet: ChatPacket::new("b"),
});
app.update();
- assert_eq!(drain_events(&mut app.world), vec![ChatPacket::new("b")]);
+ assert_eq!(drain_events(app.world_mut()), vec![ChatPacket::new("b")]);
}
}
diff --git a/azalea/src/swarm/mod.rs b/azalea/src/swarm/mod.rs
index 31f018cf..24b336fd 100644
--- a/azalea/src/swarm/mod.rs
+++ b/azalea/src/swarm/mod.rs
@@ -368,7 +368,7 @@ where
let (run_schedule_sender, run_schedule_receiver) = mpsc::unbounded_channel();
- let main_schedule_label = self.app.main_schedule_label;
+ let main_schedule_label = self.app.main().update_schedule.unwrap();
let ecs_lock =
start_ecs_runner(self.app, run_schedule_receiver, run_schedule_sender.clone());
@@ -671,7 +671,17 @@ impl Swarm {
let delay = (Duration::from_secs(5) * 2u32.pow(disconnects.min(16)))
.min(Duration::from_secs(15));
let username = account.username.clone();
- error!("Error joining as {username}: {e}. Waiting {delay:?} and trying again.");
+
+ if let JoinError::Disconnect { reason } = &e {
+ error!(
+ "Error joining as {username}, server says: \"{reason}\". Waiting {delay:?} and trying again."
+ );
+ } else {
+ error!(
+ "Error joining as {username}: {e}. Waiting {delay:?} and trying again."
+ );
+ }
+
tokio::time::sleep(delay).await;
}
}