aboutsummaryrefslogtreecommitdiff
path: root/azalea/src
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2023-05-12 23:20:23 -0500
committermat <git@matdoes.dev>2023-05-12 23:20:23 -0500
commite977391b0413aaa62ea725a53e4a78c287844f4c (patch)
tree8ca64948b685610b81ae7f3f95153acf8a25c003 /azalea/src
parent741a1f65d669c83710e8c33082b120c189b28f1d (diff)
downloadazalea-drasl-e977391b0413aaa62ea725a53e4a78c287844f4c.tar.xz
auto respawn
Diffstat (limited to 'azalea/src')
-rw-r--r--azalea/src/auto_respawn.rs24
-rw-r--r--azalea/src/bot.rs2
-rw-r--r--azalea/src/lib.rs1
3 files changed, 27 insertions, 0 deletions
diff --git a/azalea/src/auto_respawn.rs b/azalea/src/auto_respawn.rs
new file mode 100644
index 00000000..c5dd12a4
--- /dev/null
+++ b/azalea/src/auto_respawn.rs
@@ -0,0 +1,24 @@
+use crate::app::{App, Plugin};
+use azalea_client::packet_handling::DeathEvent;
+use azalea_client::respawn::PerformRespawnEvent;
+use bevy_ecs::prelude::*;
+
+/// A plugin that makes [`DeathEvent`]s send [`PerformRespawnEvent`]s.
+#[derive(Clone, Default)]
+pub struct AutoRespawnPlugin;
+impl Plugin for AutoRespawnPlugin {
+ fn build(&self, app: &mut App) {
+ app.add_system(auto_respawn);
+ }
+}
+
+fn auto_respawn(
+ mut events: EventReader<DeathEvent>,
+ mut perform_respawn_events: EventWriter<PerformRespawnEvent>,
+) {
+ for event in events.iter() {
+ perform_respawn_events.send(PerformRespawnEvent {
+ entity: event.entity,
+ });
+ }
+}
diff --git a/azalea/src/bot.rs b/azalea/src/bot.rs
index e5ea4c28..13b33bb0 100644
--- a/azalea/src/bot.rs
+++ b/azalea/src/bot.rs
@@ -1,4 +1,5 @@
use crate::app::{App, CoreSchedule, IntoSystemAppConfig, Plugin, PluginGroup, PluginGroupBuilder};
+use crate::auto_respawn::AutoRespawnPlugin;
use crate::container::ContainerPlugin;
use crate::ecs::{
component::Component,
@@ -135,5 +136,6 @@ impl PluginGroup for DefaultBotPlugins {
.add(BotPlugin)
.add(PathfinderPlugin)
.add(ContainerPlugin)
+ .add(AutoRespawnPlugin)
}
}
diff --git a/azalea/src/lib.rs b/azalea/src/lib.rs
index bde94634..604961f4 100644
--- a/azalea/src/lib.rs
+++ b/azalea/src/lib.rs
@@ -3,6 +3,7 @@
#![allow(incomplete_features)]
#![feature(async_fn_in_trait)]
+mod auto_respawn;
mod bot;
mod container;
pub mod pathfinder;