1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
use azalea_client::{
InConfigState,
chunks::handle_chunk_batch_finished_event,
client_information::send_client_information,
inventory::InventorySystems,
packet::{
config::SendConfigPacketEvent,
death_event_on_0_health,
game::{ResourcePackEvent, SendGamePacketEvent},
},
respawn::perform_respawn,
};
use azalea_protocol::packets::{
config,
game::s_resource_pack::{self, ServerboundResourcePack},
};
use bevy_app::Update;
use bevy_ecs::prelude::*;
use crate::app::{App, Plugin};
/// A plugin that makes it so bots automatically accept resource packs.
#[derive(Clone, Default)]
pub struct AcceptResourcePacksPlugin;
impl Plugin for AcceptResourcePacksPlugin {
fn build(&self, app: &mut App) {
app.add_systems(
Update,
accept_resource_pack
.before(perform_respawn)
.after(death_event_on_0_health)
.after(handle_chunk_batch_finished_event)
.after(InventorySystems)
.after(send_client_information),
);
}
}
fn accept_resource_pack(
mut events: MessageReader<ResourcePackEvent>,
mut commands: Commands,
query_in_config_state: Query<Option<&InConfigState>>,
) {
for event in events.read() {
let Ok(in_config_state_option) = query_in_config_state.get(event.entity) else {
continue;
};
if in_config_state_option.is_some() {
commands.trigger(SendConfigPacketEvent::new(
event.entity,
config::ServerboundResourcePack {
id: event.id,
action: config::s_resource_pack::Action::Accepted,
},
));
commands.trigger(SendConfigPacketEvent::new(
event.entity,
config::ServerboundResourcePack {
id: event.id,
action: config::s_resource_pack::Action::SuccessfullyLoaded,
},
));
} else {
commands.trigger(SendGamePacketEvent::new(
event.entity,
ServerboundResourcePack {
id: event.id,
action: s_resource_pack::Action::Accepted,
},
));
commands.trigger(SendGamePacketEvent::new(
event.entity,
ServerboundResourcePack {
id: event.id,
action: s_resource_pack::Action::SuccessfullyLoaded,
},
));
}
}
}
|