1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 06:16:04 +00:00

auto respawn

This commit is contained in:
mat 2023-05-12 23:20:23 -05:00
parent 741a1f65d6
commit e977391b04
7 changed files with 70 additions and 7 deletions

View file

@ -11,6 +11,7 @@ use crate::{
movement::{LastSentLookDirection, PlayerMovePlugin},
packet_handling::{self, PacketHandlerPlugin, PacketReceiver},
player::retroactively_add_game_profile_component,
respawn::RespawnPlugin,
task_pool::TaskPoolPlugin,
Account, PlayerInfo,
};
@ -717,6 +718,7 @@ impl PluginGroup for DefaultPlugins {
.add(DisconnectPlugin)
.add(PlayerMovePlugin)
.add(InteractPlugin)
.add(RespawnPlugin)
.add(TickBroadcastPlugin)
}
}

View file

@ -25,6 +25,7 @@ mod movement;
pub mod packet_handling;
pub mod ping;
mod player;
pub mod respawn;
pub mod task_pool;
pub use account::{Account, AccountOpts};

View file

@ -0,0 +1,38 @@
use azalea_protocol::packets::game::serverbound_client_command_packet::{
self, ServerboundClientCommandPacket,
};
use bevy_app::{App, Plugin};
use bevy_ecs::prelude::*;
use crate::LocalPlayer;
/// Tell the server that we're respawning.
#[derive(Debug, Clone)]
pub struct PerformRespawnEvent {
pub entity: Entity,
}
/// A plugin that makes [`PerformRespawnEvent`] send the packet to respawn.
pub struct RespawnPlugin;
impl Plugin for RespawnPlugin {
fn build(&self, app: &mut App) {
app.add_event::<PerformRespawnEvent>()
.add_system(perform_respawn);
}
}
pub fn perform_respawn(
mut events: EventReader<PerformRespawnEvent>,
mut query: Query<&mut LocalPlayer>,
) {
for event in events.iter() {
if let Ok(local_player) = query.get_mut(event.entity) {
local_player.write_packet(
ServerboundClientCommandPacket {
action: serverbound_client_command_packet::Action::PerformRespawn,
}
.get(),
);
}
}
}

View file

@ -8,10 +8,10 @@ use azalea::entity::{EyeHeight, Position};
use azalea::interact::HitResultComponent;
use azalea::inventory::ItemSlot;
use azalea::pathfinder::BlockPosGoal;
use azalea::protocol::packets::game::serverbound_client_command_packet::ServerboundClientCommandPacket;
use azalea::protocol::packets::game::ClientboundGamePacket;
use azalea::{prelude::*, swarm::prelude::*, BlockPos, GameProfileComponent, WalkDirection};
use azalea::{Account, Client, Event};
use azalea_protocol::packets::game::serverbound_client_command_packet::ServerboundClientCommandPacket;
use azalea_protocol::packets::game::ClientboundGamePacket;
use std::time::Duration;
#[derive(Default, Clone, Component)]
@ -212,11 +212,6 @@ async fn handle(mut bot: Client, event: Event, _state: State) -> anyhow::Result<
}
}
}
Event::Death(_) => {
bot.write_packet(ServerboundClientCommandPacket {
action: azalea_protocol::packets::game::serverbound_client_command_packet::Action::PerformRespawn,
}.get());
}
Event::Packet(packet) => match *packet {
ClientboundGamePacket::Login(_) => {
println!("login packet");

View file

@ -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,
});
}
}

View file

@ -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)
}
}

View file

@ -3,6 +3,7 @@
#![allow(incomplete_features)]
#![feature(async_fn_in_trait)]
mod auto_respawn;
mod bot;
mod container;
pub mod pathfinder;