build(deps)!: update azalea and fix ecs changes
This commit is contained in:
parent
505b1a26af
commit
f01d89b681
635
Cargo.lock
generated
635
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -23,7 +23,7 @@ use crate::{
|
||||
replay::recorder::Recorder,
|
||||
};
|
||||
|
||||
#[allow(clippy::too_many_lines)]
|
||||
#[allow(clippy::cognitive_complexity, clippy::too_many_lines)]
|
||||
pub async fn handle_event(client: Client, event: Event, state: State) -> Result<()> {
|
||||
match event {
|
||||
Event::AddPlayer(player_info) => {
|
||||
@ -35,6 +35,7 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> Result<
|
||||
let uuid = message.sender_uuid().map(|uuid| uuid.to_string());
|
||||
let is_whisper = message.is_whisper();
|
||||
let text = message.message();
|
||||
let html_text = text.to_html();
|
||||
let ansi_text = text.to_ansi();
|
||||
info!("{ansi_text}");
|
||||
|
||||
@ -86,6 +87,7 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> Result<
|
||||
let table = state.lua.create_table()?;
|
||||
table.set("text", text.to_string())?;
|
||||
table.set("ansi_text", ansi_text)?;
|
||||
table.set("html_text", html_text)?;
|
||||
table.set("sender", sender)?;
|
||||
table.set("content", content)?;
|
||||
table.set("uuid", uuid)?;
|
||||
@ -101,6 +103,7 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> Result<
|
||||
let message_table = state.lua.create_table()?;
|
||||
message_table.set("text", packet.message.to_string())?;
|
||||
message_table.set("ansi_text", packet.message.to_ansi())?;
|
||||
message_table.set("html_text", packet.message.to_html())?;
|
||||
let table = state.lua.create_table()?;
|
||||
table.set("message", message_table)?;
|
||||
table.set("player_id", packet.player_id.0)?;
|
||||
@ -117,6 +120,7 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> Result<
|
||||
let table = state.lua.create_table()?;
|
||||
table.set("text", message.to_string())?;
|
||||
table.set("ansi_text", message.to_ansi())?;
|
||||
table.set("html_text", message.to_html())?;
|
||||
Ok(table)
|
||||
})
|
||||
.await
|
||||
@ -125,7 +129,6 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> Result<
|
||||
}
|
||||
}
|
||||
Event::KeepAlive(id) => call_listeners(&state, "keep_alive", || Ok(id)).await,
|
||||
Event::Login => call_listeners(&state, "login", || Ok(())).await,
|
||||
Event::RemovePlayer(player_info) => {
|
||||
call_listeners(&state, "remove_player", || Ok(Player::from(player_info))).await
|
||||
}
|
||||
@ -201,6 +204,12 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> Result<
|
||||
}
|
||||
_ => Ok(()),
|
||||
},
|
||||
Event::Login => {
|
||||
#[cfg(feature = "matrix")]
|
||||
matrix_init(&client, state.clone());
|
||||
|
||||
call_listeners(&state, "login", || Ok(())).await
|
||||
}
|
||||
Event::Init => {
|
||||
debug!("received init event");
|
||||
|
||||
@ -212,9 +221,6 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> Result<
|
||||
exit(0);
|
||||
})?;
|
||||
|
||||
#[cfg(feature = "matrix")]
|
||||
matrix_init(&client, state.clone());
|
||||
|
||||
let globals = state.lua.globals();
|
||||
lua_init(client, &state, &globals).await?;
|
||||
|
||||
|
@ -3,9 +3,9 @@
|
||||
pub mod anti_knockback;
|
||||
|
||||
use anti_knockback::anti_knockback;
|
||||
use azalea::{movement::handle_knockback, packet::game::process_packet_events};
|
||||
use azalea::{connection::read_packets, movement::handle_knockback};
|
||||
use bevy_app::{App, Plugin, PreUpdate};
|
||||
use bevy_ecs::schedule::IntoSystemConfigs;
|
||||
use bevy_ecs::schedule::IntoScheduleConfigs;
|
||||
|
||||
pub struct HacksPlugin;
|
||||
|
||||
@ -13,9 +13,7 @@ impl Plugin for HacksPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(
|
||||
PreUpdate,
|
||||
anti_knockback
|
||||
.after(process_packet_events)
|
||||
.before(handle_knockback),
|
||||
anti_knockback.after(read_packets).before(handle_knockback),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ pub async fn get_block_states(
|
||||
true
|
||||
})
|
||||
{
|
||||
matched.push(block.id);
|
||||
matched.push(block.id());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ use azalea::{
|
||||
prelude::ContainerClientExt,
|
||||
protocol::packets::game::ServerboundSetCarriedItem,
|
||||
};
|
||||
use log::error;
|
||||
use mlua::{Lua, Result, UserDataRef, Value};
|
||||
|
||||
use super::{Client, Container, ContainerRef, ItemStack, Vec3};
|
||||
@ -126,11 +125,8 @@ pub fn set_held_slot(_lua: &Lua, client: &Client, slot: u8) -> Result<()> {
|
||||
inventory.selected_hotbar_slot = slot;
|
||||
};
|
||||
|
||||
if let Err(error) = client.write_packet(ServerboundSetCarriedItem {
|
||||
client.write_packet(ServerboundSetCarriedItem {
|
||||
slot: u16::from(slot),
|
||||
}) {
|
||||
error!("failed to send SetCarriedItem packet: {error:?}");
|
||||
}
|
||||
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ use azalea::{
|
||||
protocol::packets::game::{ServerboundUseItem, s_interact::InteractionHand},
|
||||
world::MinecraftEntityId,
|
||||
};
|
||||
use log::error;
|
||||
use mlua::{Lua, Result, UserDataRef};
|
||||
|
||||
use super::{Client, Vec3};
|
||||
@ -57,7 +56,7 @@ pub fn start_mining(_lua: &Lua, client: &Client, position: Vec3) -> Result<()> {
|
||||
|
||||
pub fn use_item(_lua: &Lua, client: &Client, hand: Option<u8>) -> Result<()> {
|
||||
let direction = client.direction();
|
||||
if let Err(error) = client.write_packet(ServerboundUseItem {
|
||||
client.write_packet(ServerboundUseItem {
|
||||
hand: match hand {
|
||||
Some(1) => InteractionHand::OffHand,
|
||||
_ => InteractionHand::MainHand,
|
||||
@ -65,8 +64,6 @@ pub fn use_item(_lua: &Lua, client: &Client, hand: Option<u8>) -> Result<()> {
|
||||
sequence: 0,
|
||||
yaw: direction.0,
|
||||
pitch: direction.1,
|
||||
}) {
|
||||
error!("failed to send UseItem packet: {error:?}");
|
||||
}
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
|
@ -3,13 +3,12 @@ use azalea::{
|
||||
entity::Position,
|
||||
interact::HitResultComponent,
|
||||
pathfinder::{
|
||||
ExecutingPath, GotoEvent, Pathfinder, PathfinderClientExt,
|
||||
ExecutingPath, Pathfinder, PathfinderClientExt,
|
||||
goals::{BlockPosGoal, Goal, InverseGoal, RadiusGoal, ReachBlockPosGoal, XZGoal, YGoal},
|
||||
},
|
||||
protocol::packets::game::{ServerboundPlayerCommand, s_player_command::Action},
|
||||
world::MinecraftEntityId,
|
||||
};
|
||||
use log::error;
|
||||
use mlua::{FromLua, Lua, Result, Table, UserDataRef, Value};
|
||||
|
||||
use super::{Client, Direction, Vec3};
|
||||
@ -121,11 +120,7 @@ pub async fn start_go_to(
|
||||
} else {
|
||||
client.start_goto(goal);
|
||||
}
|
||||
while client.get_tick_broadcaster().recv().await.is_ok() {
|
||||
if client.ecs.lock().get::<GotoEvent>(client.entity).is_none() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
let _ = client.get_tick_broadcaster().recv().await;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@ -215,7 +210,7 @@ pub fn set_position(_lua: &Lua, client: &Client, new_position: Vec3) -> Result<(
|
||||
}
|
||||
|
||||
pub fn set_sneaking(_lua: &Lua, client: &Client, sneaking: bool) -> Result<()> {
|
||||
if let Err(error) = client.write_packet(ServerboundPlayerCommand {
|
||||
client.write_packet(ServerboundPlayerCommand {
|
||||
id: client.component::<MinecraftEntityId>(),
|
||||
action: if sneaking {
|
||||
Action::PressShiftKey
|
||||
@ -223,9 +218,7 @@ pub fn set_sneaking(_lua: &Lua, client: &Client, sneaking: bool) -> Result<()> {
|
||||
Action::ReleaseShiftKey
|
||||
},
|
||||
data: 0,
|
||||
}) {
|
||||
error!("failed to send PlayerCommand packet: {error:?}");
|
||||
}
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -244,13 +237,11 @@ pub fn stop_pathfinding(_lua: &Lua, client: &Client, (): ()) -> Result<()> {
|
||||
}
|
||||
|
||||
pub fn stop_sleeping(_lua: &Lua, client: &Client, (): ()) -> Result<()> {
|
||||
if let Err(error) = client.write_packet(ServerboundPlayerCommand {
|
||||
client.write_packet(ServerboundPlayerCommand {
|
||||
id: client.component::<MinecraftEntityId>(),
|
||||
action: Action::StopSleeping,
|
||||
data: 0,
|
||||
}) {
|
||||
error!("failed to send PlayerCommand packet: {error:?}");
|
||||
}
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
use azalea::{
|
||||
ClientInformation,
|
||||
entity::metadata::{AirSupply, Score},
|
||||
pathfinder::PathfinderDebugParticles,
|
||||
pathfinder::debug::PathfinderDebugParticles,
|
||||
protocol::common::client_information::ModelCustomization,
|
||||
};
|
||||
use mlua::{Error, Lua, Result, Table, UserDataRef};
|
||||
@ -40,21 +40,22 @@ pub async fn set_client_information(
|
||||
allows_listing: info.get("allows_listing")?,
|
||||
model_customization: info
|
||||
.get::<Table>("model_customization")
|
||||
.as_ref()
|
||||
.map(|t| ModelCustomization {
|
||||
cape: get_bool(&t, "cape"),
|
||||
jacket: get_bool(&t, "jacket"),
|
||||
left_sleeve: get_bool(&t, "left_sleeve"),
|
||||
right_sleeve: get_bool(&t, "right_sleeve"),
|
||||
left_pants: get_bool(&t, "left_pants"),
|
||||
right_pants: get_bool(&t, "right_pants"),
|
||||
hat: get_bool(&t, "hat"),
|
||||
cape: get_bool(t, "cape"),
|
||||
jacket: get_bool(t, "jacket"),
|
||||
left_sleeve: get_bool(t, "left_sleeve"),
|
||||
right_sleeve: get_bool(t, "right_sleeve"),
|
||||
left_pants: get_bool(t, "left_pants"),
|
||||
right_pants: get_bool(t, "right_pants"),
|
||||
hat: get_bool(t, "hat"),
|
||||
})
|
||||
.unwrap_or_default(),
|
||||
view_distance: info.get("view_distance").unwrap_or(8),
|
||||
..ClientInformation::default()
|
||||
})
|
||||
.await
|
||||
.map_err(Error::external)
|
||||
.await;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn set_component(
|
||||
|
@ -28,7 +28,10 @@ pub fn blocks(
|
||||
nearest_to.z as i32,
|
||||
),
|
||||
&BlockStates {
|
||||
set: block_states.iter().map(|&id| BlockState { id }).collect(),
|
||||
set: block_states
|
||||
.into_iter()
|
||||
.flat_map(BlockState::try_from)
|
||||
.collect(),
|
||||
},
|
||||
)
|
||||
.map(Vec3::from)
|
||||
|
@ -3,16 +3,19 @@ mod queries;
|
||||
pub mod find;
|
||||
|
||||
use azalea::{BlockPos, auto_tool::AutoToolClientExt, blocks::BlockState, world::InstanceName};
|
||||
use mlua::{Lua, Result, Table};
|
||||
use mlua::{Lua, Result, Table, Value};
|
||||
|
||||
use super::{Client, Direction, Vec3};
|
||||
|
||||
pub fn best_tool_for_block(lua: &Lua, client: &Client, block_state: u16) -> Result<Table> {
|
||||
let result = client.best_tool_in_hotbar_for_block(BlockState { id: block_state });
|
||||
pub fn best_tool_for_block(lua: &Lua, client: &Client, block_state: u16) -> Result<Value> {
|
||||
let Ok(block) = BlockState::try_from(block_state) else {
|
||||
return Ok(Value::Nil);
|
||||
};
|
||||
let result = client.best_tool_in_hotbar_for_block(block);
|
||||
let table = lua.create_table()?;
|
||||
table.set("index", result.index)?;
|
||||
table.set("percentage_per_tick", result.percentage_per_tick)?;
|
||||
Ok(table)
|
||||
Ok(Value::Table(table))
|
||||
}
|
||||
|
||||
pub fn dimension(_lua: &Lua, client: &Client) -> Result<String> {
|
||||
@ -29,7 +32,7 @@ pub fn get_block_state(_lua: &Lua, client: &Client, position: Vec3) -> Result<Op
|
||||
position.y as i32,
|
||||
position.z as i32,
|
||||
))
|
||||
.map(|block| block.id))
|
||||
.map(|block| block.id()))
|
||||
}
|
||||
|
||||
#[allow(clippy::cast_possible_truncation)]
|
||||
|
@ -22,7 +22,7 @@ use std::{
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
use anyhow::Context;
|
||||
use anyhow::{Context, Result};
|
||||
use arguments::Arguments;
|
||||
use azalea::{
|
||||
DefaultBotPlugins, DefaultPlugins, brigadier::prelude::CommandDispatcher, prelude::*,
|
||||
@ -55,7 +55,7 @@ struct State {
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
async fn main() -> Result<()> {
|
||||
#[cfg(feature = "console-subscriber")]
|
||||
console_subscriber::init();
|
||||
|
||||
@ -131,8 +131,7 @@ async fn main() -> anyhow::Result<()> {
|
||||
} else {
|
||||
Account::offline(&username)
|
||||
};
|
||||
|
||||
let Err(error) = ClientBuilder::new_without_plugins()
|
||||
let Err(err) = ClientBuilder::new_without_plugins()
|
||||
.add_plugins(DefaultBotPlugins)
|
||||
.add_plugins(HacksPlugin)
|
||||
.add_plugins(default_plugins)
|
||||
@ -145,7 +144,7 @@ async fn main() -> anyhow::Result<()> {
|
||||
})
|
||||
.start(account, server)
|
||||
.await;
|
||||
eprintln!("{error}");
|
||||
eprintln!("{err}");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -3,17 +3,15 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use azalea::{
|
||||
ecs::{event::EventReader, system::Query},
|
||||
ecs::event::EventReader,
|
||||
packet::{
|
||||
config::ReceiveConfigPacketEvent,
|
||||
game::emit_receive_packet_events,
|
||||
login::{LoginPacketEvent, process_packet_events},
|
||||
config::ReceiveConfigPacketEvent, game::ReceiveGamePacketEvent,
|
||||
login::ReceiveLoginPacketEvent,
|
||||
},
|
||||
protocol::packets::login::ClientboundLoginPacket,
|
||||
raw_connection::RawConnection,
|
||||
};
|
||||
use bevy_app::{App, First, Plugin};
|
||||
use bevy_ecs::{schedule::IntoSystemConfigs, system::ResMut};
|
||||
use bevy_ecs::system::ResMut;
|
||||
use log::error;
|
||||
use parking_lot::Mutex;
|
||||
|
||||
@ -28,19 +26,16 @@ impl Plugin for RecordPlugin {
|
||||
let recorder = self.recorder.lock().take();
|
||||
if let Some(recorder) = recorder {
|
||||
app.insert_resource(recorder)
|
||||
.add_systems(First, record_login_packets.before(process_packet_events))
|
||||
.add_systems(First, record_login_packets)
|
||||
.add_systems(First, record_configuration_packets)
|
||||
.add_systems(
|
||||
First,
|
||||
record_game_packets.before(emit_receive_packet_events),
|
||||
);
|
||||
.add_systems(First, record_game_packets);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn record_login_packets(
|
||||
recorder: Option<ResMut<Recorder>>,
|
||||
mut events: EventReader<LoginPacketEvent>,
|
||||
mut events: EventReader<ReceiveLoginPacketEvent>,
|
||||
) {
|
||||
if let Some(mut recorder) = recorder {
|
||||
for event in events.read() {
|
||||
@ -63,20 +58,20 @@ fn record_configuration_packets(
|
||||
) {
|
||||
if let Some(mut recorder) = recorder {
|
||||
for event in events.read() {
|
||||
if let Err(error) = recorder.save_packet(&event.packet) {
|
||||
if let Err(error) = recorder.save_packet(event.packet.as_ref()) {
|
||||
error!("failed to record configuration packet: {error:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn record_game_packets(recorder: Option<ResMut<Recorder>>, query: Query<&RawConnection>) {
|
||||
if let Some(mut recorder) = recorder
|
||||
&& let Ok(raw_conn) = query.get_single()
|
||||
{
|
||||
let queue = raw_conn.incoming_packet_queue();
|
||||
for raw_packet in queue.lock().iter() {
|
||||
if let Err(error) = recorder.save_raw_packet(raw_packet) {
|
||||
fn record_game_packets(
|
||||
recorder: Option<ResMut<Recorder>>,
|
||||
mut events: EventReader<ReceiveGamePacketEvent>,
|
||||
) {
|
||||
if let Some(mut recorder) = recorder {
|
||||
for event in events.read() {
|
||||
if let Err(error) = recorder.save_packet(event.packet.as_ref()) {
|
||||
error!("failed to record game packet: {error:?}");
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user