build(deps)!: update azalea and fix ecs changes

This commit is contained in:
2025-04-18 00:20:55 -04:00
parent 3b154c6a35
commit 63cfc7c9c0
24 changed files with 2690 additions and 1881 deletions

3895
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -21,6 +21,7 @@ built = { git = "https://github.com/lukaslueg/built", features = ["git2"] }
[dependencies] [dependencies]
anyhow = "1" anyhow = "1"
azalea = { git = "https://github.com/azalea-rs/azalea" } azalea = { git = "https://github.com/azalea-rs/azalea" }
azalea-hax = { git = "https://github.com/azalea-rs/azalea-hax" }
bevy_app = "0" bevy_app = "0"
bevy_ecs = "0" bevy_ecs = "0"
bevy_log = "0" bevy_log = "0"
@@ -42,10 +43,13 @@ parking_lot = "0"
serde = "1" serde = "1"
serde_json = "1" serde_json = "1"
tokio = { version = "1", features = ["full"] } tokio = { version = "1", features = ["full"] }
zip = { version = "2", default-features = false, features = ["flate2"] } zip = { version = "8", default-features = false, features = [
"deflate",
], optional = true }
[features] [features]
console-subscriber = ["dep:console-subscriber"] console-subscriber = ["dep:console-subscriber"]
default = [] default = []
matrix = ["dep:dirs", "dep:matrix-sdk"] matrix = ["dep:dirs", "dep:matrix-sdk"]
mimalloc = ["dep:mimalloc"] mimalloc = ["dep:mimalloc"]
replay = ["dep:zip"]

View File

@@ -30,7 +30,7 @@ function auto_fish()
sleep(3000) sleep(3000)
end end
hold_fishing_rod() hold_fishing_rod()
client:use_item() client:start_use_item()
end end
end, "auto-fish_watch-bobber") end, "auto-fish_watch-bobber")
@@ -41,7 +41,7 @@ function auto_fish()
end)[1] end)[1]
if distance(current_bobber.position, particle.position) <= 0.75 then if distance(current_bobber.position, particle.position) <= 0.75 then
FishLastCaught = os.time() FishLastCaught = os.time()
client:use_item() client:start_use_item()
end end
end end
end, "auto-fish") end, "auto-fish")
@@ -54,11 +54,11 @@ function auto_fish()
if os.time() - FishLastCaught >= 60 then if os.time() - FishLastCaught >= 60 then
hold_fishing_rod() hold_fishing_rod()
client:use_item() client:start_use_item()
end end
end, "auto-fish_watchdog") end, "auto-fish_watchdog")
client:use_item() client:start_use_item()
end end
function stop_auto_fish() function stop_auto_fish()
@@ -71,7 +71,7 @@ function stop_auto_fish()
return e.id == FishingBobber.id return e.id == FishingBobber.id
end)[1] then end)[1] then
FishingBobber = nil FishingBobber = nil
client:use_item() client:start_use_item()
end end
end end
@@ -131,6 +131,6 @@ function check_food(hunger)
sleep(1000) sleep(1000)
LastEaten = current_time LastEaten = current_time
end end
client:use_item() client:start_use_item()
end end
end end

View File

@@ -1,4 +1,4 @@
use azalea::{brigadier::prelude::*, chat::ChatPacket, prelude::*}; use azalea::{brigadier::prelude::*, client_chat::ChatPacket, prelude::*};
use futures::lock::Mutex; use futures::lock::Mutex;
use mlua::{Error, Result, Table, UserDataRef}; use mlua::{Error, Result, Table, UserDataRef};
use ncr::{ use ncr::{

View File

@@ -1,18 +1,19 @@
use std::{net::SocketAddr, process::exit}; use std::net::SocketAddr;
use anyhow::{Context, Result}; use anyhow::Result;
use azalea::{ use azalea::{
brigadier::exceptions::BuiltInExceptions::DispatcherUnknownCommand, prelude::*, brigadier::errors::BuiltInError, prelude::*, protocol::packets::game::ClientboundGamePacket,
protocol::packets::game::ClientboundGamePacket,
}; };
use hyper::{server::conn::http1, service::service_fn}; use hyper::{server::conn::http1, service::service_fn};
use hyper_util::rt::TokioIo; use hyper_util::rt::TokioIo;
use log::{debug, error, info, trace}; use log::{debug, error, info, trace};
use mlua::{Error, Function, IntoLuaMulti, Table}; use mlua::{Function, IntoLuaMulti, Table};
use ncr::utils::trim_header; use ncr::utils::trim_header;
use tokio::net::TcpListener; use tokio::net::TcpListener;
#[cfg(feature = "matrix")] #[cfg(feature = "matrix")]
use {crate::matrix, std::time::Duration, tokio::time::sleep}; use {crate::matrix, std::time::Duration, tokio::time::sleep};
#[cfg(feature = "replay")]
use {crate::replay::recorder::Recorder, mlua::Error, std::process::exit};
use crate::{ use crate::{
State, State,
@@ -20,7 +21,6 @@ use crate::{
http::serve, http::serve,
lua::{client, direction::Direction, player::Player, vec3::Vec3}, lua::{client, direction::Direction, player::Player, vec3::Vec3},
particle, particle,
replay::recorder::Recorder,
}; };
#[allow(clippy::cognitive_complexity, clippy::too_many_lines)] #[allow(clippy::cognitive_complexity, clippy::too_many_lines)]
@@ -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 uuid = message.sender_uuid().map(|uuid| uuid.to_string());
let is_whisper = message.is_whisper(); let is_whisper = message.is_whisper();
let text = message.message(); let text = message.message();
let html_text = text.to_html();
let ansi_text = text.to_ansi(); let ansi_text = text.to_ansi();
info!("{ansi_text}"); info!("{ansi_text}");
@@ -70,7 +71,7 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> Result<
} }
.into(), .into(),
) )
&& error.type_ != DispatcherUnknownCommand && *error.kind() != BuiltInError::DispatcherUnknownCommand
{ {
CommandSource { CommandSource {
client, client,
@@ -86,6 +87,7 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> Result<
let table = state.lua.create_table()?; let table = state.lua.create_table()?;
table.set("text", text.to_string())?; table.set("text", text.to_string())?;
table.set("ansi_text", ansi_text)?; table.set("ansi_text", ansi_text)?;
table.set("html_text", html_text)?;
table.set("sender", sender)?; table.set("sender", sender)?;
table.set("content", content)?; table.set("content", content)?;
table.set("uuid", uuid)?; 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()?; let message_table = state.lua.create_table()?;
message_table.set("text", packet.message.to_string())?; message_table.set("text", packet.message.to_string())?;
message_table.set("ansi_text", packet.message.to_ansi())?; message_table.set("ansi_text", packet.message.to_ansi())?;
message_table.set("html_text", packet.message.to_html())?;
let table = state.lua.create_table()?; let table = state.lua.create_table()?;
table.set("message", message_table)?; table.set("message", message_table)?;
table.set("player_id", packet.player_id.0)?; 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()?; let table = state.lua.create_table()?;
table.set("text", message.to_string())?; table.set("text", message.to_string())?;
table.set("ansi_text", message.to_ansi())?; table.set("ansi_text", message.to_ansi())?;
table.set("html_text", message.to_html())?;
Ok(table) Ok(table)
}) })
.await .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::KeepAlive(id) => call_listeners(&state, "keep_alive", || Ok(id)).await,
Event::Login => call_listeners(&state, "login", || Ok(())).await,
Event::RemovePlayer(player_info) => { Event::RemovePlayer(player_info) => {
call_listeners(&state, "remove_player", || Ok(Player::from(player_info))).await call_listeners(&state, "remove_player", || Ok(Player::from(player_info))).await
} }
@@ -183,8 +186,11 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> Result<
ClientboundGamePacket::SetPassengers(packet) => { ClientboundGamePacket::SetPassengers(packet) => {
call_listeners(&state, "set_passengers", || { call_listeners(&state, "set_passengers", || {
let table = state.lua.create_table()?; let table = state.lua.create_table()?;
table.set("vehicle", packet.vehicle)?; table.set("vehicle", *packet.vehicle)?;
table.set("passengers", &*packet.passengers)?; table.set(
"passengers",
packet.passengers.iter().map(|id| id.0).collect::<Vec<_>>(),
)?;
Ok(table) Ok(table)
}) })
.await .await
@@ -192,28 +198,32 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> Result<
ClientboundGamePacket::SetTime(packet) => { ClientboundGamePacket::SetTime(packet) => {
call_listeners(&state, "set_time", || { call_listeners(&state, "set_time", || {
let table = state.lua.create_table()?; let table = state.lua.create_table()?;
table.set("day_time", packet.day_time)?;
table.set("game_time", packet.game_time)?; table.set("game_time", packet.game_time)?;
table.set("tick_day_time", packet.tick_day_time)?;
Ok(table) Ok(table)
}) })
.await .await
} }
_ => Ok(()), _ => Ok(()),
}, },
Event::Login => {
#[cfg(feature = "matrix")]
matrix_init(&client, state.clone());
call_listeners(&state, "login", || Ok(())).await
}
Event::Init => { Event::Init => {
debug!("received init event"); debug!("received init event");
#[cfg(feature = "replay")]
{
let ecs = client.ecs.clone(); let ecs = client.ecs.clone();
ctrlc::set_handler(move || { ctrlc::set_handler(move || {
ecs.lock() ecs.write()
.remove_resource::<Recorder>() .remove_resource::<Recorder>()
.map(Recorder::finish); .map(Recorder::finish);
exit(0); exit(0);
})?; })?;
};
#[cfg(feature = "matrix")]
matrix_init(&client, state.clone());
let globals = state.lua.globals(); let globals = state.lua.globals();
lua_init(client, &state, &globals).await?; lua_init(client, &state, &globals).await?;
@@ -262,11 +272,13 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> Result<
} }
async fn lua_init(client: Client, state: &State, globals: &Table) -> Result<()> { async fn lua_init(client: Client, state: &State, globals: &Table) -> Result<()> {
#[cfg(feature = "replay")]
{
let ecs = client.ecs.clone(); let ecs = client.ecs.clone();
globals.set( globals.set(
"finish_replay_recording", "finish_replay_recording",
state.lua.create_function_mut(move |_, (): ()| { state.lua.create_function_mut(move |_, (): ()| {
ecs.lock() ecs.write()
.remove_resource::<Recorder>() .remove_resource::<Recorder>()
.context("recording not active") .context("recording not active")
.map_err(Error::external)? .map_err(Error::external)?
@@ -274,6 +286,7 @@ async fn lua_init(client: Client, state: &State, globals: &Table) -> Result<()>
.map_err(Error::external) .map_err(Error::external)
})?, })?,
)?; )?;
}
globals.set("client", client::Client(Some(client)))?; globals.set("client", client::Client(Some(client)))?;
call_listeners(state, "init", || Ok(())).await call_listeners(state, "init", || Ok(())).await
} }

View File

@@ -1,20 +0,0 @@
use azalea::{
Vec3,
movement::{KnockbackEvent, KnockbackType},
prelude::Component,
};
use bevy_ecs::{event::EventMutator, query::With, system::Query};
#[derive(Component)]
pub struct AntiKnockback;
pub fn anti_knockback(
mut events: EventMutator<KnockbackEvent>,
entity_query: Query<(), With<AntiKnockback>>,
) {
for event in events.read() {
if entity_query.get(event.entity).is_ok() {
event.knockback = KnockbackType::Add(Vec3::default());
}
}
}

View File

@@ -1,21 +0,0 @@
#![allow(clippy::needless_pass_by_value)]
pub mod anti_knockback;
use anti_knockback::anti_knockback;
use azalea::{movement::handle_knockback, packet::game::process_packet_events};
use bevy_app::{App, Plugin, PreUpdate};
use bevy_ecs::schedule::IntoSystemConfigs;
pub struct HacksPlugin;
impl Plugin for HacksPlugin {
fn build(&self, app: &mut App) {
app.add_systems(
PreUpdate,
anti_knockback
.after(process_packet_events)
.before(handle_knockback),
);
}
}

View File

@@ -1,6 +1,6 @@
use azalea::blocks::{ use azalea::block::{
Block as AzaleaBlock, BlockState, BlockState, BlockTrait,
properties::{ChestType, Facing, LightLevel}, properties::{ChestKind, Facing, LightLevel},
}; };
use mlua::{Function, Lua, Result, Table}; use mlua::{Function, Lua, Result, Table};
@@ -21,7 +21,7 @@ pub fn get_block_from_state(lua: &Lua, state: u32) -> Result<Option<Table>> {
let Ok(state) = BlockState::try_from(state) else { let Ok(state) = BlockState::try_from(state) else {
return Ok(None); return Ok(None);
}; };
let block: Box<dyn AzaleaBlock> = state.into(); let block: Box<dyn BlockTrait> = state.into();
let behavior = block.behavior(); let behavior = block.behavior();
let table = lua.create_table()?; let table = lua.create_table()?;
@@ -46,10 +46,10 @@ pub async fn get_block_states(
for block in for block in
(u32::MIN..u32::MAX).map_while(|possible_id| BlockState::try_from(possible_id).ok()) (u32::MIN..u32::MAX).map_while(|possible_id| BlockState::try_from(possible_id).ok())
{ {
if block_name == Into::<Box<dyn AzaleaBlock>>::into(block).id() if block_name == Into::<Box<dyn BlockTrait>>::into(block).id()
&& (if let Some(filter_fn) = &filter_fn { && (if let Some(filter_fn) = &filter_fn {
let table = lua.create_table()?; let table = lua.create_table()?;
table.set("chest_type", block.property::<ChestType>().map(|v| v as u8))?; table.set("chest_kind", block.property::<ChestKind>().map(|v| v as u8))?;
table.set("facing", block.property::<Facing>().map(|v| v as u8))?; table.set("facing", block.property::<Facing>().map(|v| v as u8))?;
table.set( table.set(
"light_level", "light_level",
@@ -60,7 +60,7 @@ pub async fn get_block_states(
true true
}) })
{ {
matched.push(block.id); matched.push(block.id());
} }
} }
} }

View File

@@ -1,20 +1,19 @@
use azalea::{ use azalea::{
BlockPos, BlockPos,
inventory::{Inventory, Menu, Player, SlotList}, entity::inventory::Inventory,
prelude::ContainerClientExt, inventory::{Menu, Player, SlotList},
protocol::packets::game::ServerboundSetCarriedItem, protocol::packets::game::ServerboundSetCarriedItem,
}; };
use log::error;
use mlua::{Lua, Result, UserDataRef, Value}; use mlua::{Lua, Result, UserDataRef, Value};
use super::{Client, Container, ContainerRef, ItemStack, Vec3}; use super::{Client, Container, ContainerRef, ItemStack, Vec3};
pub fn container(_lua: &Lua, client: &Client) -> Result<Option<ContainerRef>> { pub fn container(_lua: &Lua, client: &Client) -> Result<ContainerRef> {
Ok(client.get_open_container().map(ContainerRef)) Ok(ContainerRef(client.get_inventory()))
} }
pub fn held_item(_lua: &Lua, client: &Client) -> Result<ItemStack> { pub fn held_item(_lua: &Lua, client: &Client) -> Result<ItemStack> {
Ok(ItemStack(client.component::<Inventory>().held_item())) Ok(ItemStack(client.get_held_item()))
} }
pub fn held_slot(_lua: &Lua, client: &Client) -> Result<u8> { pub fn held_slot(_lua: &Lua, client: &Client) -> Result<u8> {
@@ -117,20 +116,14 @@ pub fn set_held_slot(_lua: &Lua, client: &Client, slot: u8) -> Result<()> {
return Ok(()); return Ok(());
} }
{ client.query_self::<&mut Inventory, _>(|mut inventory| {
let mut ecs = client.ecs.lock(); if inventory.selected_hotbar_slot != slot {
let mut inventory = client.query::<&mut Inventory>(&mut ecs);
if inventory.selected_hotbar_slot == slot {
return Ok(());
}
inventory.selected_hotbar_slot = slot; inventory.selected_hotbar_slot = slot;
};
if let Err(error) = client.write_packet(ServerboundSetCarriedItem {
slot: u16::from(slot),
}) {
error!("failed to send SetCarriedItem packet: {error:?}");
} }
});
client.write_packet(ServerboundSetCarriedItem {
slot: u16::from(slot),
});
Ok(()) Ok(())
} }

View File

@@ -1,15 +1,16 @@
use azalea::{ use azalea::{
BlockPos, BotClientExt, BlockPos,
core::entity_id::MinecraftEntityId,
protocol::packets::game::{ServerboundUseItem, s_interact::InteractionHand}, protocol::packets::game::{ServerboundUseItem, s_interact::InteractionHand},
world::MinecraftEntityId,
}; };
use log::error;
use mlua::{Lua, Result, UserDataRef}; use mlua::{Lua, Result, UserDataRef};
use super::{Client, Vec3}; use super::{Client, Vec3};
pub fn attack(_lua: &Lua, client: &Client, entity_id: i32) -> Result<()> { pub fn attack(_lua: &Lua, client: &Client, entity_id: i32) -> Result<()> {
client.attack(MinecraftEntityId(entity_id)); if let Some(entity) = client.entity_id_by_minecraft_id(MinecraftEntityId(entity_id)) {
client.attack(entity);
}
Ok(()) Ok(())
} }
@@ -40,8 +41,8 @@ pub async fn mine(_lua: Lua, client: UserDataRef<Client>, position: Vec3) -> Res
Ok(()) Ok(())
} }
pub fn set_mining(_lua: &Lua, client: &Client, mining: bool) -> Result<()> { pub fn set_mining(_lua: &Lua, client: &Client, state: bool) -> Result<()> {
client.left_click_mine(mining); client.left_click_mine(state);
Ok(()) Ok(())
} }
@@ -55,18 +56,16 @@ pub fn start_mining(_lua: &Lua, client: &Client, position: Vec3) -> Result<()> {
Ok(()) Ok(())
} }
pub fn use_item(_lua: &Lua, client: &Client, hand: Option<u8>) -> Result<()> { pub fn start_use_item(_lua: &Lua, client: &Client, hand: Option<u8>) -> Result<()> {
let direction = client.direction(); let direction = client.direction();
if let Err(error) = client.write_packet(ServerboundUseItem { client.write_packet(ServerboundUseItem {
hand: match hand { hand: match hand {
Some(1) => InteractionHand::OffHand, Some(1) => InteractionHand::OffHand,
_ => InteractionHand::MainHand, _ => InteractionHand::MainHand,
}, },
sequence: 0, seq: 0,
yaw: direction.0, x_rot: direction.x_rot(),
pitch: direction.1, y_rot: direction.y_rot(),
}) { });
error!("failed to send UseItem packet: {error:?}");
}
Ok(()) Ok(())
} }

View File

@@ -8,7 +8,7 @@ mod world;
use std::ops::{Deref, DerefMut}; use std::ops::{Deref, DerefMut};
use azalea::{Client as AzaleaClient, world::MinecraftEntityId}; use azalea::{Client as AzaleaClient, core::entity_id::MinecraftEntityId};
use mlua::{Lua, Result, UserData, UserDataFields, UserDataMethods}; use mlua::{Lua, Result, UserData, UserDataFields, UserDataMethods};
use super::{ use super::{
@@ -64,14 +64,11 @@ impl UserData for Client {
m.add_async_method("find_entities", world::find::entities); m.add_async_method("find_entities", world::find::entities);
m.add_async_method("find_players", world::find::players); m.add_async_method("find_players", world::find::players);
m.add_async_method("go_to", movement::go_to); m.add_async_method("go_to", movement::go_to);
m.add_async_method(
"go_to_wait_until_reached",
movement::go_to_wait_until_reached,
);
m.add_async_method("mine", interaction::mine); m.add_async_method("mine", interaction::mine);
m.add_async_method("open_container_at", container::open_container_at); m.add_async_method("open_container_at", container::open_container_at);
m.add_async_method("set_client_information", state::set_client_information); m.add_async_method("set_client_information", state::set_client_information);
m.add_async_method("start_go_to", movement::start_go_to); m.add_async_method("start_go_to", movement::start_go_to);
m.add_async_method("wait_until_goal_reached", movement::wait_until_goal_reached);
m.add_method("attack", interaction::attack); m.add_method("attack", interaction::attack);
m.add_method("best_tool_for_block", world::best_tool_for_block); m.add_method("best_tool_for_block", world::best_tool_for_block);
m.add_method("block_interact", interaction::block_interact); m.add_method("block_interact", interaction::block_interact);
@@ -92,9 +89,9 @@ impl UserData for Client {
m.add_method("set_sneaking", movement::set_sneaking); m.add_method("set_sneaking", movement::set_sneaking);
m.add_method("sprint", movement::sprint); m.add_method("sprint", movement::sprint);
m.add_method("start_mining", interaction::start_mining); m.add_method("start_mining", interaction::start_mining);
m.add_method("start_use_item", interaction::start_use_item);
m.add_method("stop_pathfinding", movement::stop_pathfinding); m.add_method("stop_pathfinding", movement::stop_pathfinding);
m.add_method("stop_sleeping", movement::stop_sleeping); m.add_method("stop_sleeping", movement::stop_sleeping);
m.add_method("use_item", interaction::use_item);
m.add_method("walk", movement::walk); m.add_method("walk", movement::walk);
} }
} }

View File

@@ -1,15 +1,14 @@
use azalea::{ use azalea::{
BlockPos, BotClientExt, SprintDirection, WalkDirection, BlockPos, SprintDirection, WalkDirection,
core::{entity_id::MinecraftEntityId, hit_result::HitResult},
entity::Position, entity::Position,
interact::HitResultComponent, interact::pick::HitResultComponent,
pathfinder::{ pathfinder::{
ExecutingPath, GotoEvent, Pathfinder, PathfinderClientExt, ExecutingPath, Pathfinder, PathfinderClientExt, PathfinderOpts,
goals::{BlockPosGoal, Goal, InverseGoal, RadiusGoal, ReachBlockPosGoal, XZGoal, YGoal}, goals::{BlockPosGoal, Goal, RadiusGoal, ReachBlockPosGoal, XZGoal, YGoal},
}, },
protocol::packets::game::{ServerboundPlayerCommand, s_player_command::Action}, protocol::packets::game::{ServerboundPlayerCommand, s_player_command::Action},
world::MinecraftEntityId,
}; };
use log::error;
use mlua::{FromLua, Lua, Result, Table, UserDataRef, Value}; use mlua::{FromLua, Lua, Result, Table, UserDataRef, Value};
use super::{Client, Direction, Vec3}; use super::{Client, Direction, Vec3};
@@ -28,7 +27,7 @@ impl Goal for AnyGoal {
} }
#[allow(clippy::cast_possible_truncation)] #[allow(clippy::cast_possible_truncation)]
fn to_goal(lua: &Lua, client: &Client, data: Table, options: &Table, kind: u8) -> Result<AnyGoal> { fn to_goal(lua: &Lua, client: &Client, data: Table, kind: u8) -> Result<AnyGoal> {
let goal: Box<dyn Goal> = match kind { let goal: Box<dyn Goal> = match kind {
1 => { 1 => {
let pos = Vec3::from_lua(data.get("position")?, lua)?; let pos = Vec3::from_lua(data.get("position")?, lua)?;
@@ -38,11 +37,13 @@ fn to_goal(lua: &Lua, client: &Client, data: Table, options: &Table, kind: u8) -
}) })
} }
2 => { 2 => {
let distance = data.get("distance").unwrap_or(4.5);
let pos = Vec3::from_lua(Value::Table(data), lua)?; let pos = Vec3::from_lua(Value::Table(data), lua)?;
Box::new(ReachBlockPosGoal { Box::new(ReachBlockPosGoal::new_with_distance(
pos: BlockPos::new(pos.x as i32, pos.y as i32, pos.z as i32), BlockPos::new(pos.x as i32, pos.y as i32, pos.z as i32),
chunk_storage: client.world().read().chunks.clone(), distance,
}) client.world().read().chunks.clone(),
))
} }
3 => Box::new(XZGoal { 3 => Box::new(XZGoal {
x: data.get("x")?, x: data.get("x")?,
@@ -59,22 +60,14 @@ fn to_goal(lua: &Lua, client: &Client, data: Table, options: &Table, kind: u8) -
} }
}; };
Ok(AnyGoal(if options.get("inverse").unwrap_or_default() { Ok(AnyGoal(goal))
Box::new(InverseGoal(AnyGoal(goal)))
} else {
goal
}))
} }
pub fn go_to_reached(_lua: &Lua, client: &Client) -> Result<bool> { pub fn go_to_reached(_lua: &Lua, client: &Client) -> Result<bool> {
Ok(client.is_goto_target_reached()) Ok(client.is_goto_target_reached())
} }
pub async fn go_to_wait_until_reached( pub async fn wait_until_goal_reached(_lua: Lua, client: UserDataRef<Client>, (): ()) -> Result<()> {
_lua: Lua,
client: UserDataRef<Client>,
(): (),
) -> Result<()> {
client.wait_until_goto_target_reached().await; client.wait_until_goto_target_reached().await;
Ok(()) Ok(())
} }
@@ -90,11 +83,10 @@ pub async fn go_to(
&lua, &lua,
&client, &client,
data, data,
&options,
metadata.get("type").unwrap_or_default(), metadata.get("type").unwrap_or_default(),
)?; )?;
if options.get("without_mining").unwrap_or_default() { if options.get("without_mining").unwrap_or_default() {
client.start_goto_without_mining(goal); client.start_goto_with_opts(goal, PathfinderOpts::new().allow_mining(false));
client.wait_until_goto_target_reached().await; client.wait_until_goto_target_reached().await;
} else { } else {
client.goto(goal).await; client.goto(goal).await;
@@ -113,19 +105,13 @@ pub async fn start_go_to(
&lua, &lua,
&client, &client,
data, data,
&options,
metadata.get("type").unwrap_or_default(), metadata.get("type").unwrap_or_default(),
)?; )?;
if options.get("without_mining").unwrap_or_default() { client.start_goto_with_opts(
client.start_goto_without_mining(goal); goal,
} else { PathfinderOpts::new().allow_mining(options.get("without_mining").unwrap_or_default()),
client.start_goto(goal); );
} let _ = client.get_tick_broadcaster().recv().await;
while client.get_tick_broadcaster().recv().await.is_ok() {
if client.ecs.lock().get::<GotoEvent>(client.entity).is_none() {
break;
}
}
Ok(()) Ok(())
} }
@@ -133,8 +119,8 @@ pub async fn start_go_to(
pub fn direction(_lua: &Lua, client: &Client) -> Result<Direction> { pub fn direction(_lua: &Lua, client: &Client) -> Result<Direction> {
let direction = client.direction(); let direction = client.direction();
Ok(Direction { Ok(Direction {
y: direction.0, y: direction.y_rot(),
x: direction.1, x: direction.x_rot(),
}) })
} }
@@ -148,16 +134,19 @@ pub fn jump(_lua: &Lua, client: &Client, (): ()) -> Result<()> {
} }
pub fn looking_at(lua: &Lua, client: &Client) -> Result<Option<Table>> { pub fn looking_at(lua: &Lua, client: &Client) -> Result<Option<Table>> {
let result = client.component::<HitResultComponent>(); Ok(
Ok(if result.miss { if let HitResult::Block(ref result) = **client.component::<HitResultComponent>() {
None
} else {
let table = lua.create_table()?; let table = lua.create_table()?;
table.set("position", Vec3::from(result.block_pos))?; table.set("direction", Vec3::from(result.direction.normal()))?;
table.set("inside", result.inside)?; table.set("inside", result.inside)?;
table.set("location", Vec3::from(result.location))?;
table.set("position", Vec3::from(result.block_pos))?;
table.set("world_border", result.world_border)?; table.set("world_border", result.world_border)?;
Some(table) Some(table)
}) } else {
None
},
)
} }
pub fn look_at(_lua: &Lua, client: &Client, position: Vec3) -> Result<()> { pub fn look_at(_lua: &Lua, client: &Client, position: Vec3) -> Result<()> {
@@ -179,8 +168,8 @@ pub fn pathfinder(lua: &Lua, client: &Client) -> Result<Table> {
Vec3::from(pathfinder.last_reached_node), Vec3::from(pathfinder.last_reached_node),
)?; )?;
table.set( table.set(
"last_node_reach_elapsed", "ticks_since_last_node_reached",
pathfinder.last_node_reached_at.elapsed().as_millis(), pathfinder.ticks_since_last_node_reached,
)?; )?;
table.set("is_path_partial", pathfinder.is_path_partial)?; table.set("is_path_partial", pathfinder.is_path_partial)?;
true true
@@ -192,7 +181,7 @@ pub fn pathfinder(lua: &Lua, client: &Client) -> Result<Table> {
} }
pub fn position(_lua: &Lua, client: &Client) -> Result<Vec3> { pub fn position(_lua: &Lua, client: &Client) -> Result<Vec3> {
Ok(Vec3::from(&client.component::<Position>())) Ok(Vec3::from(*client.component::<Position>()))
} }
pub fn set_direction(_lua: &Lua, client: &Client, direction: Direction) -> Result<()> { pub fn set_direction(_lua: &Lua, client: &Client, direction: Direction) -> Result<()> {
@@ -205,27 +194,17 @@ pub fn set_jumping(_lua: &Lua, client: &Client, jumping: bool) -> Result<()> {
Ok(()) Ok(())
} }
pub fn set_position(_lua: &Lua, client: &Client, new_position: Vec3) -> Result<()> { pub fn set_position(_lua: &Lua, client: &Client, new_pos: Vec3) -> Result<()> {
let mut ecs = client.ecs.lock(); client.query_self::<&mut Position, _>(|mut pos| {
let mut position = client.query::<&mut Position>(&mut ecs); pos.x = new_pos.x;
position.x = new_position.x; pos.y = new_pos.y;
position.y = new_position.y; pos.z = new_pos.z;
position.z = new_position.z; });
Ok(()) Ok(())
} }
pub fn set_sneaking(_lua: &Lua, client: &Client, sneaking: bool) -> Result<()> { pub fn set_sneaking(_lua: &Lua, client: &Client, sneaking: bool) -> Result<()> {
if let Err(error) = client.write_packet(ServerboundPlayerCommand { client.set_crouching(sneaking);
id: client.component::<MinecraftEntityId>(),
action: if sneaking {
Action::PressShiftKey
} else {
Action::ReleaseShiftKey
},
data: 0,
}) {
error!("failed to send PlayerCommand packet: {error:?}");
}
Ok(()) Ok(())
} }
@@ -244,13 +223,11 @@ pub fn stop_pathfinding(_lua: &Lua, client: &Client, (): ()) -> Result<()> {
} }
pub fn stop_sleeping(_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>(), id: *client.component::<MinecraftEntityId>(),
action: Action::StopSleeping, action: Action::StopSleeping,
data: 0, data: 0,
}) { });
error!("failed to send PlayerCommand packet: {error:?}");
}
Ok(()) Ok(())
} }

View File

@@ -1,13 +1,13 @@
use azalea::{ use azalea::{
ClientInformation, ClientInformation,
entity::metadata::{AirSupply, Score}, entity::metadata::{AirSupply, Score},
pathfinder::PathfinderDebugParticles, pathfinder::debug::PathfinderDebugParticles,
protocol::common::client_information::ModelCustomization, protocol::common::client_information::ModelCustomization,
}; };
use azalea_hax::AntiKnockback;
use mlua::{Error, Lua, Result, Table, UserDataRef}; use mlua::{Error, Lua, Result, Table, UserDataRef};
use super::Client; use super::Client;
use crate::hacks::anti_knockback::AntiKnockback;
pub fn air_supply(_lua: &Lua, client: &Client) -> Result<i32> { pub fn air_supply(_lua: &Lua, client: &Client) -> Result<i32> {
Ok(client.component::<AirSupply>().0) Ok(client.component::<AirSupply>().0)
@@ -35,26 +35,25 @@ pub async fn set_client_information(
info: Table, info: Table,
) -> Result<()> { ) -> Result<()> {
let get_bool = |table: &Table, name| table.get(name).unwrap_or(true); let get_bool = |table: &Table, name| table.get(name).unwrap_or(true);
client client.set_client_information(ClientInformation {
.set_client_information(ClientInformation {
allows_listing: info.get("allows_listing")?, allows_listing: info.get("allows_listing")?,
model_customization: info model_customization: info
.get::<Table>("model_customization") .get::<Table>("model_customization")
.as_ref()
.map(|t| ModelCustomization { .map(|t| ModelCustomization {
cape: get_bool(&t, "cape"), cape: get_bool(t, "cape"),
jacket: get_bool(&t, "jacket"), jacket: get_bool(t, "jacket"),
left_sleeve: get_bool(&t, "left_sleeve"), left_sleeve: get_bool(t, "left_sleeve"),
right_sleeve: get_bool(&t, "right_sleeve"), right_sleeve: get_bool(t, "right_sleeve"),
left_pants: get_bool(&t, "left_pants"), left_pants: get_bool(t, "left_pants"),
right_pants: get_bool(&t, "right_pants"), right_pants: get_bool(t, "right_pants"),
hat: get_bool(&t, "hat"), hat: get_bool(t, "hat"),
}) })
.unwrap_or_default(), .unwrap_or_default(),
view_distance: info.get("view_distance").unwrap_or(8), view_distance: info.get("view_distance").unwrap_or(8),
..ClientInformation::default() ..ClientInformation::default()
}) });
.await Ok(())
.map_err(Error::external)
} }
pub fn set_component( pub fn set_component(
@@ -64,7 +63,7 @@ pub fn set_component(
) -> Result<()> { ) -> Result<()> {
macro_rules! set { macro_rules! set {
($name:ident) => {{ ($name:ident) => {{
let mut ecs = client.ecs.lock(); let mut ecs = client.ecs.write();
let mut entity = ecs.entity_mut(client.entity); let mut entity = ecs.entity_mut(client.entity);
if enabled.unwrap_or(true) { if enabled.unwrap_or(true) {
entity.insert($name) entity.insert($name)

View File

@@ -1,16 +1,16 @@
use azalea::{ use azalea::{
BlockPos, BlockPos,
blocks::{BlockState, BlockStates}, block::{BlockState, BlockStates},
ecs::query::{With, Without}, ecs::query::{With, Without},
entity::{ entity::{
Dead, EntityKind, EntityUuid, LookDirection, Pose, Position as AzaleaPosition, Dead, EntityKindComponent, EntityUuid, LookDirection, Pose, Position as AzaleaPosition,
metadata::{CustomName, Owneruuid, Player}, metadata::{CustomName, Owneruuid, Player},
}, },
world::MinecraftEntityId,
}; };
use mlua::{Function, Lua, Result, Table, UserDataRef}; use mlua::{Function, Lua, Result, Table, UserDataRef};
use super::{Client, Direction, Vec3}; use super::{Client, Direction, Vec3};
use crate::lua::client::MinecraftEntityId;
pub fn blocks( pub fn blocks(
_lua: &Lua, _lua: &Lua,
@@ -28,7 +28,10 @@ pub fn blocks(
nearest_to.z as i32, nearest_to.z as i32,
), ),
&BlockStates { &BlockStates {
set: block_states.iter().map(|&id| BlockState { id }).collect(), set: block_states
.into_iter()
.flat_map(BlockState::try_from)
.collect(),
}, },
) )
.map(Vec3::from) .map(Vec3::from)

View File

@@ -2,21 +2,24 @@
mod queries; mod queries;
pub mod find; pub mod find;
use azalea::{BlockPos, auto_tool::AutoToolClientExt, blocks::BlockState, world::InstanceName}; use azalea::{BlockPos, block::BlockState, world::WorldName};
use mlua::{Lua, Result, Table}; use mlua::{Lua, Result, Table, Value};
use super::{Client, Direction, Vec3}; use super::{Client, Direction, Vec3};
pub fn best_tool_for_block(lua: &Lua, client: &Client, block_state: u16) -> Result<Table> { pub fn best_tool_for_block(lua: &Lua, client: &Client, block_state: u16) -> Result<Value> {
let result = client.best_tool_in_hotbar_for_block(BlockState { id: block_state }); 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()?; let table = lua.create_table()?;
table.set("index", result.index)?; table.set("index", result.index)?;
table.set("percentage_per_tick", result.percentage_per_tick)?; table.set("percentage_per_tick", result.percentage_per_tick)?;
Ok(table) Ok(Value::Table(table))
} }
pub fn dimension(_lua: &Lua, client: &Client) -> Result<String> { pub fn dimension(_lua: &Lua, client: &Client) -> Result<String> {
Ok(client.component::<InstanceName>().to_string()) Ok(client.component::<WorldName>().to_string())
} }
pub fn get_block_state(_lua: &Lua, client: &Client, position: Vec3) -> Result<Option<u16>> { pub fn get_block_state(_lua: &Lua, client: &Client, position: Vec3) -> Result<Option<u16>> {
@@ -24,17 +27,17 @@ pub fn get_block_state(_lua: &Lua, client: &Client, position: Vec3) -> Result<Op
Ok(client Ok(client
.world() .world()
.read() .read()
.get_block_state(&BlockPos::new( .get_block_state(BlockPos::new(
position.x as i32, position.x as i32,
position.y as i32, position.y as i32,
position.z as i32, position.z as i32,
)) ))
.map(|block| block.id)) .map(|block| block.id()))
} }
#[allow(clippy::cast_possible_truncation)] #[allow(clippy::cast_possible_truncation)]
pub fn get_fluid_state(lua: &Lua, client: &Client, position: Vec3) -> Result<Option<Table>> { pub fn get_fluid_state(lua: &Lua, client: &Client, position: Vec3) -> Result<Option<Table>> {
let fluid_state = client.world().read().get_fluid_state(&BlockPos::new( let fluid_state = client.world().read().get_fluid_state(BlockPos::new(
position.x as i32, position.x as i32,
position.y as i32, position.y as i32,
position.z as i32, position.z as i32,

View File

@@ -1,11 +1,11 @@
#[macro_export] #[macro_export]
macro_rules! get_entities { macro_rules! get_entities {
($client:ident) => {{ ($client:ident) => {{
let mut ecs = $client.ecs.lock(); let mut ecs = $client.ecs.write();
ecs.query::<( ecs.query::<(
&AzaleaPosition, &AzaleaPosition,
&CustomName, &CustomName,
&EntityKind, &EntityKindComponent,
&EntityUuid, &EntityUuid,
&LookDirection, &LookDirection,
&MinecraftEntityId, &MinecraftEntityId,
@@ -16,7 +16,7 @@ macro_rules! get_entities {
.map( .map(
|(position, custom_name, kind, uuid, direction, id, owner_uuid, pose)| { |(position, custom_name, kind, uuid, direction, id, owner_uuid, pose)| {
( (
Vec3::from(position), Vec3::from(*position),
custom_name.as_ref().map(ToString::to_string), custom_name.as_ref().map(ToString::to_string),
kind.to_string(), kind.to_string(),
uuid.to_string(), uuid.to_string(),
@@ -34,11 +34,11 @@ macro_rules! get_entities {
#[macro_export] #[macro_export]
macro_rules! get_players { macro_rules! get_players {
($client:ident) => {{ ($client:ident) => {{
let mut ecs = $client.ecs.lock(); let mut ecs = $client.ecs.write();
ecs.query_filtered::<( ecs.query_filtered::<(
&MinecraftEntityId, &MinecraftEntityId,
&EntityUuid, &EntityUuid,
&EntityKind, &EntityKindComponent,
&AzaleaPosition, &AzaleaPosition,
&LookDirection, &LookDirection,
&Pose, &Pose,
@@ -49,7 +49,7 @@ macro_rules! get_players {
id.0, id.0,
uuid.to_string(), uuid.to_string(),
kind.to_string(), kind.to_string(),
Vec3::from(position), Vec3::from(*position),
Direction::from(direction), Direction::from(direction),
*pose as u8, *pose as u8,
) )

View File

@@ -1,5 +1,5 @@
use azalea::inventory::{ use azalea::inventory::{
self, self, ItemStackData,
components::{Consumable, CustomName, Damage, Food, MaxDamage}, components::{Consumable, CustomName, Damage, Food, MaxDamage},
}; };
use mlua::{UserData, UserDataFields, UserDataMethods}; use mlua::{UserData, UserDataFields, UserDataMethods};
@@ -14,8 +14,7 @@ impl UserData for ItemStack {
f.add_field_method_get("kind", |_, this| Ok(this.0.kind().to_string())); f.add_field_method_get("kind", |_, this| Ok(this.0.kind().to_string()));
f.add_field_method_get("custom_name", |_, this| { f.add_field_method_get("custom_name", |_, this| {
Ok(this.0.as_present().map(|data| { Ok(this.0.as_present().map(|data| {
data.components data.get_component::<CustomName>()
.get::<CustomName>()
.map(|c| c.name.to_string()) .map(|c| c.name.to_string())
})) }))
}); });
@@ -23,13 +22,13 @@ impl UserData for ItemStack {
Ok(this Ok(this
.0 .0
.as_present() .as_present()
.map(|data| data.components.get::<Damage>().map(|d| d.amount))) .map(|data| data.get_component::<Damage>().map(|d| d.amount)))
}); });
f.add_field_method_get("max_damage", |_, this| { f.add_field_method_get("max_damage", |_, this| {
Ok(this Ok(this
.0 .0
.as_present() .as_present()
.map(|data| data.components.get::<MaxDamage>().map(|d| d.amount))) .map(|data| data.get_component::<MaxDamage>().map(|d| d.amount)))
}); });
f.add_field_method_get("consumable", |lua, this| { f.add_field_method_get("consumable", |lua, this| {
@@ -37,7 +36,7 @@ impl UserData for ItemStack {
if let Some(consumable) = this if let Some(consumable) = this
.0 .0
.as_present() .as_present()
.and_then(|data| data.components.get::<Consumable>()) .and_then(ItemStackData::get_component::<Consumable>)
{ {
let table = lua.create_table()?; let table = lua.create_table()?;
table.set("animation", consumable.animation as u8)?; table.set("animation", consumable.animation as u8)?;
@@ -55,13 +54,12 @@ impl UserData for ItemStack {
if let Some(food) = this if let Some(food) = this
.0 .0
.as_present() .as_present()
.and_then(|data| data.components.get::<Food>()) .and_then(ItemStackData::get_component::<Food>)
{ {
let table = lua.create_table()?; let table = lua.create_table()?;
table.set("nutrition", food.nutrition)?; table.set("nutrition", food.nutrition)?;
table.set("saturation", food.saturation)?; table.set("saturation", food.saturation)?;
table.set("can_always_eat", food.can_always_eat)?; table.set("can_always_eat", food.can_always_eat)?;
table.set("eat_seconds", food.eat_seconds)?;
Some(table) Some(table)
} else { } else {
None None

View File

@@ -10,8 +10,8 @@ pub struct Direction {
impl From<&LookDirection> for Direction { impl From<&LookDirection> for Direction {
fn from(d: &LookDirection) -> Self { fn from(d: &LookDirection) -> Self {
Self { Self {
y: d.y_rot, y: d.y_rot(),
x: d.x_rot, x: d.x_rot(),
} }
} }
} }

View File

@@ -1,4 +1,4 @@
use azalea::PlayerInfo; use azalea::player::PlayerInfo;
use mlua::{IntoLua, Lua, Result, Value}; use mlua::{IntoLua, Lua, Result, Value};
#[derive(Clone)] #[derive(Clone)]

View File

@@ -28,8 +28,8 @@ impl From<azalea::Vec3> for Vec3 {
} }
} }
impl From<&Position> for Vec3 { impl From<Position> for Vec3 {
fn from(p: &Position) -> Self { fn from(p: Position) -> Self {
Self { Self {
x: p.x, x: p.x,
y: p.y, y: p.y,

View File

@@ -1,4 +1,3 @@
#![feature(if_let_guard, let_chains)]
#![warn(clippy::pedantic, clippy::nursery)] #![warn(clippy::pedantic, clippy::nursery)]
#![allow(clippy::significant_drop_tightening)] #![allow(clippy::significant_drop_tightening)]
@@ -6,15 +5,16 @@ mod arguments;
mod build_info; mod build_info;
mod commands; mod commands;
mod events; mod events;
mod hacks;
mod http; mod http;
mod lua; mod lua;
mod particle; mod particle;
mod replay;
#[cfg(feature = "matrix")] #[cfg(feature = "matrix")]
mod matrix; mod matrix;
#[cfg(feature = "replay")]
mod replay;
use std::{ use std::{
collections::HashMap, collections::HashMap,
env, env,
@@ -22,11 +22,12 @@ use std::{
sync::Arc, sync::Arc,
}; };
use anyhow::Context; use anyhow::{Context, Result, bail};
use arguments::Arguments; use arguments::Arguments;
use azalea::{ use azalea::{
DefaultBotPlugins, DefaultPlugins, brigadier::prelude::CommandDispatcher, prelude::*, DefaultPlugins, bot::DefaultBotPlugins, brigadier::prelude::CommandDispatcher, prelude::*,
}; };
use azalea_hax::HaxPlugin;
use bevy_app::PluginGroup; use bevy_app::PluginGroup;
use bevy_log::{ use bevy_log::{
LogPlugin, LogPlugin,
@@ -36,10 +37,10 @@ use clap::Parser;
use commands::{CommandSource, register}; use commands::{CommandSource, register};
use futures::lock::Mutex; use futures::lock::Mutex;
use futures_locks::RwLock; use futures_locks::RwLock;
use hacks::HacksPlugin;
use log::debug; use log::debug;
use mlua::{Function, Lua, Table}; use mlua::{Function, Lua};
use replay::{plugin::RecordPlugin, recorder::Recorder}; #[cfg(feature = "replay")]
use replay::{mlua::Table, plugin::RecordPlugin, recorder::Recorder};
#[cfg(feature = "mimalloc")] #[cfg(feature = "mimalloc")]
#[global_allocator] #[global_allocator]
@@ -55,7 +56,7 @@ struct State {
} }
#[tokio::main] #[tokio::main]
async fn main() -> anyhow::Result<()> { async fn main() -> Result<()> {
#[cfg(feature = "console-subscriber")] #[cfg(feature = "console-subscriber")]
console_subscriber::init(); console_subscriber::init();
@@ -109,7 +110,14 @@ async fn main() -> anyhow::Result<()> {
..Default::default() ..Default::default()
}) })
}; };
let record_plugin = RecordPlugin {
let builder = ClientBuilder::new_without_plugins()
.add_plugins(default_plugins)
.add_plugins(DefaultBotPlugins)
.add_plugins(HaxPlugin);
#[cfg(feature = "replay")]
let builder = builder.add_plugins(RecordPlugin {
recorder: Arc::new(parking_lot::Mutex::new( recorder: Arc::new(parking_lot::Mutex::new(
if let Ok(options) = globals.get::<Table>("ReplayRecordingOptions") if let Ok(options) = globals.get::<Table>("ReplayRecordingOptions")
&& let Ok(path) = options.get::<String>("path") && let Ok(path) = options.get::<String>("path")
@@ -125,18 +133,15 @@ async fn main() -> anyhow::Result<()> {
None None
}, },
)), )),
}; });
let account = if username.contains('@') { let account = if username.contains('@') {
Account::microsoft(&username).await? Account::microsoft(&username).await?
} else { } else {
Account::offline(&username) Account::offline(&username)
}; };
let Err(error) = ClientBuilder::new_without_plugins() if let AppExit::Error(code) = builder
.add_plugins(DefaultBotPlugins)
.add_plugins(HacksPlugin)
.add_plugins(default_plugins)
.add_plugins(record_plugin)
.set_handler(events::handle_event) .set_handler(events::handle_event)
.set_state(State { .set_state(State {
lua: Arc::new(lua), lua: Arc::new(lua),
@@ -144,8 +149,10 @@ async fn main() -> anyhow::Result<()> {
commands: Arc::new(commands), commands: Arc::new(commands),
}) })
.start(account, server) .start(account, server)
.await; .await
eprintln!("{error}"); {
bail!("azalea exited with code {code}")
}
Ok(()) Ok(())
} }

View File

@@ -1,121 +1,124 @@
use azalea::{entity::particle::Particle, registry::ParticleKind}; use azalea::{entity::particle::Particle, registry::builtin::ParticleKind};
#[allow(clippy::too_many_lines)] #[allow(clippy::too_many_lines)]
pub const fn to_kind(particle: &Particle) -> ParticleKind { pub const fn to_kind(particle: &Particle) -> ParticleKind {
match particle { match particle {
Particle::AngryVillager => ParticleKind::AngryVillager, Particle::AngryVillager => ParticleKind::AngryVillager,
Particle::Ash => ParticleKind::Ash,
Particle::Block(_) => ParticleKind::Block, Particle::Block(_) => ParticleKind::Block,
Particle::BlockCrumble => ParticleKind::BlockCrumble,
Particle::BlockMarker(_) => ParticleKind::BlockMarker, Particle::BlockMarker(_) => ParticleKind::BlockMarker,
Particle::Bubble => ParticleKind::Bubble, Particle::Bubble => ParticleKind::Bubble,
Particle::BubbleColumnUp => ParticleKind::BubbleColumnUp,
Particle::BubblePop => ParticleKind::BubblePop,
Particle::CampfireCosySmoke => ParticleKind::CampfireCosySmoke,
Particle::CampfireSignalSmoke => ParticleKind::CampfireSignalSmoke,
Particle::CherryLeaves => ParticleKind::CherryLeaves,
Particle::Cloud => ParticleKind::Cloud, Particle::Cloud => ParticleKind::Cloud,
Particle::Composter => ParticleKind::Composter,
Particle::CopperFireFlame => ParticleKind::CopperFireFlame,
Particle::CrimsonSpore => ParticleKind::CrimsonSpore,
Particle::Crit => ParticleKind::Crit, Particle::Crit => ParticleKind::Crit,
Particle::CurrentDown => ParticleKind::CurrentDown,
Particle::DamageIndicator => ParticleKind::DamageIndicator, Particle::DamageIndicator => ParticleKind::DamageIndicator,
Particle::Dolphin => ParticleKind::Dolphin,
Particle::DragonBreath => ParticleKind::DragonBreath, Particle::DragonBreath => ParticleKind::DragonBreath,
Particle::DrippingDripstoneLava => ParticleKind::DrippingDripstoneLava,
Particle::DrippingDripstoneWater => ParticleKind::DrippingDripstoneWater,
Particle::DrippingHoney => ParticleKind::DrippingHoney,
Particle::DrippingLava => ParticleKind::DrippingLava, Particle::DrippingLava => ParticleKind::DrippingLava,
Particle::FallingLava => ParticleKind::FallingLava, Particle::DrippingObsidianTear => ParticleKind::DrippingObsidianTear,
Particle::LandingLava => ParticleKind::LandingLava,
Particle::DrippingWater => ParticleKind::DrippingWater, Particle::DrippingWater => ParticleKind::DrippingWater,
Particle::FallingWater => ParticleKind::FallingWater,
Particle::Dust(_) => ParticleKind::Dust, Particle::Dust(_) => ParticleKind::Dust,
Particle::DustColorTransition(_) => ParticleKind::DustColorTransition, Particle::DustColorTransition(_) => ParticleKind::DustColorTransition,
Particle::DustPillar => ParticleKind::DustPillar,
Particle::DustPlume => ParticleKind::DustPlume,
Particle::Effect => ParticleKind::Effect, Particle::Effect => ParticleKind::Effect,
Particle::EggCrack => ParticleKind::EggCrack,
Particle::ElderGuardian => ParticleKind::ElderGuardian, Particle::ElderGuardian => ParticleKind::ElderGuardian,
Particle::EnchantedHit => ParticleKind::EnchantedHit, Particle::ElectricSpark => ParticleKind::ElectricSpark,
Particle::Enchant => ParticleKind::Enchant, Particle::Enchant => ParticleKind::Enchant,
Particle::EnchantedHit => ParticleKind::EnchantedHit,
Particle::EndRod => ParticleKind::EndRod, Particle::EndRod => ParticleKind::EndRod,
Particle::EntityEffect(_) => ParticleKind::EntityEffect, Particle::EntityEffect(_) => ParticleKind::EntityEffect,
Particle::ExplosionEmitter => ParticleKind::ExplosionEmitter,
Particle::Explosion => ParticleKind::Explosion, Particle::Explosion => ParticleKind::Explosion,
Particle::Gust => ParticleKind::Gust, Particle::ExplosionEmitter => ParticleKind::ExplosionEmitter,
Particle::SonicBoom => ParticleKind::SonicBoom, Particle::FallingDripstoneLava => ParticleKind::FallingDripstoneLava,
Particle::FallingDripstoneWater => ParticleKind::FallingDripstoneWater,
Particle::FallingDust(_) => ParticleKind::FallingDust, Particle::FallingDust(_) => ParticleKind::FallingDust,
Particle::FallingHoney => ParticleKind::FallingHoney,
Particle::FallingLava => ParticleKind::FallingLava,
Particle::FallingNectar => ParticleKind::FallingNectar,
Particle::FallingObsidianTear => ParticleKind::FallingObsidianTear,
Particle::FallingSporeBlossom => ParticleKind::FallingSporeBlossom,
Particle::FallingWater => ParticleKind::FallingWater,
Particle::Firefly => ParticleKind::Firefly,
Particle::Firework => ParticleKind::Firework, Particle::Firework => ParticleKind::Firework,
Particle::Fishing => ParticleKind::Fishing, Particle::Fishing => ParticleKind::Fishing,
Particle::Flame => ParticleKind::Flame, Particle::Flame => ParticleKind::Flame,
Particle::CherryLeaves => ParticleKind::CherryLeaves,
Particle::PaleOakLeaves => ParticleKind::PaleOakLeaves,
Particle::TintedLeaves => ParticleKind::TintedLeaves,
Particle::SculkSoul => ParticleKind::SculkSoul,
Particle::SculkCharge(_) => ParticleKind::SculkCharge,
Particle::SculkChargePop => ParticleKind::SculkChargePop,
Particle::SoulFireFlame => ParticleKind::SoulFireFlame,
Particle::Soul => ParticleKind::Soul,
Particle::Flash => ParticleKind::Flash, Particle::Flash => ParticleKind::Flash,
Particle::Glow => ParticleKind::Glow,
Particle::GlowSquidInk => ParticleKind::GlowSquidInk,
Particle::Gust => ParticleKind::Gust,
Particle::GustEmitterLarge => ParticleKind::GustEmitterLarge,
Particle::GustEmitterSmall => ParticleKind::GustEmitterSmall,
Particle::HappyVillager => ParticleKind::HappyVillager, Particle::HappyVillager => ParticleKind::HappyVillager,
Particle::Composter => ParticleKind::Composter,
Particle::Heart => ParticleKind::Heart, Particle::Heart => ParticleKind::Heart,
Particle::Infested => ParticleKind::Infested,
Particle::InstantEffect => ParticleKind::InstantEffect, Particle::InstantEffect => ParticleKind::InstantEffect,
Particle::Item(_) => ParticleKind::Item, Particle::Item(_) => ParticleKind::Item,
Particle::Vibration(_) => ParticleKind::Vibration, Particle::ItemCobweb => ParticleKind::ItemCobweb,
Particle::ItemSlime => ParticleKind::ItemSlime, Particle::ItemSlime => ParticleKind::ItemSlime,
Particle::ItemSnowball => ParticleKind::ItemSnowball, Particle::ItemSnowball => ParticleKind::ItemSnowball,
Particle::LandingHoney => ParticleKind::LandingHoney,
Particle::LandingLava => ParticleKind::LandingLava,
Particle::LandingObsidianTear => ParticleKind::LandingObsidianTear,
Particle::LargeSmoke => ParticleKind::LargeSmoke, Particle::LargeSmoke => ParticleKind::LargeSmoke,
Particle::Lava => ParticleKind::Lava, Particle::Lava => ParticleKind::Lava,
Particle::Mycelium => ParticleKind::Mycelium, Particle::Mycelium => ParticleKind::Mycelium,
Particle::Nautilus => ParticleKind::Nautilus,
Particle::Note => ParticleKind::Note, Particle::Note => ParticleKind::Note,
Particle::OminousSpawning => ParticleKind::OminousSpawning,
Particle::PaleOakLeaves => ParticleKind::PaleOakLeaves,
Particle::PauseMobGrowth => ParticleKind::PauseMobGrowth,
Particle::Poof => ParticleKind::Poof, Particle::Poof => ParticleKind::Poof,
Particle::Portal => ParticleKind::Portal, Particle::Portal => ParticleKind::Portal,
Particle::RaidOmen => ParticleKind::RaidOmen,
Particle::Rain => ParticleKind::Rain, Particle::Rain => ParticleKind::Rain,
Particle::ResetMobGrowth => ParticleKind::ResetMobGrowth,
Particle::ReversePortal => ParticleKind::ReversePortal,
Particle::Scrape => ParticleKind::Scrape,
Particle::SculkCharge(_) => ParticleKind::SculkCharge,
Particle::SculkChargePop => ParticleKind::SculkChargePop,
Particle::SculkSoul => ParticleKind::SculkSoul,
Particle::Shriek(_) => ParticleKind::Shriek,
Particle::SmallFlame => ParticleKind::SmallFlame,
Particle::SmallGust => ParticleKind::SmallGust,
Particle::Smoke => ParticleKind::Smoke, Particle::Smoke => ParticleKind::Smoke,
Particle::WhiteSmoke => ParticleKind::WhiteSmoke,
Particle::Sneeze => ParticleKind::Sneeze, Particle::Sneeze => ParticleKind::Sneeze,
Particle::Snowflake => ParticleKind::Snowflake,
Particle::SonicBoom => ParticleKind::SonicBoom,
Particle::Soul => ParticleKind::Soul,
Particle::SoulFireFlame => ParticleKind::SoulFireFlame,
Particle::Spit => ParticleKind::Spit, Particle::Spit => ParticleKind::Spit,
Particle::Splash => ParticleKind::Splash,
Particle::SporeBlossomAir => ParticleKind::SporeBlossomAir,
Particle::SquidInk => ParticleKind::SquidInk, Particle::SquidInk => ParticleKind::SquidInk,
Particle::SweepAttack => ParticleKind::SweepAttack, Particle::SweepAttack => ParticleKind::SweepAttack,
Particle::TintedLeaves => ParticleKind::TintedLeaves,
Particle::TotemOfUndying => ParticleKind::TotemOfUndying, Particle::TotemOfUndying => ParticleKind::TotemOfUndying,
Particle::Underwater => ParticleKind::Underwater, Particle::Trail => ParticleKind::Trail,
Particle::Splash => ParticleKind::Splash, Particle::TrialOmen => ParticleKind::TrialOmen,
Particle::Witch => ParticleKind::Witch,
Particle::BubblePop => ParticleKind::BubblePop,
Particle::CurrentDown => ParticleKind::CurrentDown,
Particle::BubbleColumnUp => ParticleKind::BubbleColumnUp,
Particle::Nautilus => ParticleKind::Nautilus,
Particle::Dolphin => ParticleKind::Dolphin,
Particle::CampfireCosySmoke => ParticleKind::CampfireCosySmoke,
Particle::CampfireSignalSmoke => ParticleKind::CampfireSignalSmoke,
Particle::DrippingHoney => ParticleKind::DrippingHoney,
Particle::FallingHoney => ParticleKind::FallingHoney,
Particle::LandingHoney => ParticleKind::LandingHoney,
Particle::FallingNectar => ParticleKind::FallingNectar,
Particle::FallingSporeBlossom => ParticleKind::FallingSporeBlossom,
Particle::Ash => ParticleKind::Ash,
Particle::CrimsonSpore => ParticleKind::CrimsonSpore,
Particle::WarpedSpore => ParticleKind::WarpedSpore,
Particle::SporeBlossomAir => ParticleKind::SporeBlossomAir,
Particle::DrippingObsidianTear => ParticleKind::DrippingObsidianTear,
Particle::FallingObsidianTear => ParticleKind::FallingObsidianTear,
Particle::LandingObsidianTear => ParticleKind::LandingObsidianTear,
Particle::ReversePortal => ParticleKind::ReversePortal,
Particle::WhiteAsh => ParticleKind::WhiteAsh,
Particle::SmallFlame => ParticleKind::SmallFlame,
Particle::Snowflake => ParticleKind::Snowflake,
Particle::DrippingDripstoneLava => ParticleKind::DrippingDripstoneLava,
Particle::FallingDripstoneLava => ParticleKind::FallingDripstoneLava,
Particle::DrippingDripstoneWater => ParticleKind::DrippingDripstoneWater,
Particle::FallingDripstoneWater => ParticleKind::FallingDripstoneWater,
Particle::GlowSquidInk => ParticleKind::GlowSquidInk,
Particle::Glow => ParticleKind::Glow,
Particle::WaxOn => ParticleKind::WaxOn,
Particle::WaxOff => ParticleKind::WaxOff,
Particle::ElectricSpark => ParticleKind::ElectricSpark,
Particle::Scrape => ParticleKind::Scrape,
Particle::Shriek(_) => ParticleKind::Shriek,
Particle::EggCrack => ParticleKind::EggCrack,
Particle::DustPlume => ParticleKind::DustPlume,
Particle::SmallGust => ParticleKind::SmallGust,
Particle::GustEmitterLarge => ParticleKind::GustEmitterLarge,
Particle::GustEmitterSmall => ParticleKind::GustEmitterSmall,
Particle::Infested => ParticleKind::Infested,
Particle::ItemCobweb => ParticleKind::ItemCobweb,
Particle::TrialSpawnerDetection => ParticleKind::TrialSpawnerDetection, Particle::TrialSpawnerDetection => ParticleKind::TrialSpawnerDetection,
Particle::TrialSpawnerDetectionOminous => ParticleKind::TrialSpawnerDetectionOminous, Particle::TrialSpawnerDetectionOminous => ParticleKind::TrialSpawnerDetectionOminous,
Particle::Underwater => ParticleKind::Underwater,
Particle::VaultConnection => ParticleKind::VaultConnection, Particle::VaultConnection => ParticleKind::VaultConnection,
Particle::DustPillar => ParticleKind::DustPillar, Particle::Vibration(_) => ParticleKind::Vibration,
Particle::OminousSpawning => ParticleKind::OminousSpawning, Particle::WarpedSpore => ParticleKind::WarpedSpore,
Particle::RaidOmen => ParticleKind::RaidOmen, Particle::WaxOff => ParticleKind::WaxOff,
Particle::TrialOmen => ParticleKind::TrialOmen, Particle::WaxOn => ParticleKind::WaxOn,
Particle::Trail => ParticleKind::Trail, Particle::WhiteAsh => ParticleKind::WhiteAsh,
Particle::BlockCrumble => ParticleKind::BlockCrumble, Particle::WhiteSmoke => ParticleKind::WhiteSmoke,
Particle::Firefly => ParticleKind::Firefly, Particle::Witch => ParticleKind::Witch,
} }
} }

View File

@@ -3,17 +3,15 @@
use std::sync::Arc; use std::sync::Arc;
use azalea::{ use azalea::{
ecs::{event::EventReader, system::Query}, ecs::event::EventReader,
packet::{ packet::{
config::ReceiveConfigPacketEvent, config::ReceiveConfigPacketEvent, game::ReceiveGamePacketEvent,
game::emit_receive_packet_events, login::ReceiveLoginPacketEvent,
login::{LoginPacketEvent, process_packet_events},
}, },
protocol::packets::login::ClientboundLoginPacket, protocol::packets::login::ClientboundLoginPacket,
raw_connection::RawConnection,
}; };
use bevy_app::{App, First, Plugin}; use bevy_app::{App, First, Plugin};
use bevy_ecs::{schedule::IntoSystemConfigs, system::ResMut}; use bevy_ecs::system::ResMut;
use log::error; use log::error;
use parking_lot::Mutex; use parking_lot::Mutex;
@@ -28,19 +26,16 @@ impl Plugin for RecordPlugin {
let recorder = self.recorder.lock().take(); let recorder = self.recorder.lock().take();
if let Some(recorder) = recorder { if let Some(recorder) = recorder {
app.insert_resource(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_configuration_packets)
.add_systems( .add_systems(First, record_game_packets);
First,
record_game_packets.before(emit_receive_packet_events),
);
} }
} }
} }
fn record_login_packets( fn record_login_packets(
recorder: Option<ResMut<Recorder>>, recorder: Option<ResMut<Recorder>>,
mut events: EventReader<LoginPacketEvent>, mut events: EventReader<ReceiveLoginPacketEvent>,
) { ) {
if let Some(mut recorder) = recorder { if let Some(mut recorder) = recorder {
for event in events.read() { for event in events.read() {
@@ -63,20 +58,20 @@ fn record_configuration_packets(
) { ) {
if let Some(mut recorder) = recorder { if let Some(mut recorder) = recorder {
for event in events.read() { 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:?}"); error!("failed to record configuration packet: {error:?}");
} }
} }
} }
} }
fn record_game_packets(recorder: Option<ResMut<Recorder>>, query: Query<&RawConnection>) { fn record_game_packets(
if let Some(mut recorder) = recorder recorder: Option<ResMut<Recorder>>,
&& let Ok(raw_conn) = query.get_single() mut events: EventReader<ReceiveGamePacketEvent>,
{ ) {
let queue = raw_conn.incoming_packet_queue(); if let Some(mut recorder) = recorder {
for raw_packet in queue.lock().iter() { for event in events.read() {
if let Err(error) = recorder.save_raw_packet(raw_packet) { if let Err(error) = recorder.save_packet(event.packet.as_ref()) {
error!("failed to record game packet: {error:?}"); error!("failed to record game packet: {error:?}");
} }
} }

View File

@@ -6,7 +6,7 @@ use std::{
use anyhow::Result; use anyhow::Result;
use azalea::{ use azalea::{
buf::AzaleaWriteVar, buf::AzBufVar,
prelude::Resource, prelude::Resource,
protocol::packets::{PROTOCOL_VERSION, ProtocolPacket, VERSION_NAME}, protocol::packets::{PROTOCOL_VERSION, ProtocolPacket, VERSION_NAME},
}; };