Skip to content

Commit 88b5355

Browse files
build(deps)!: update azalea and fix ecs changes
1 parent 505b1a2 commit 88b5355

14 files changed

Lines changed: 563 additions & 468 deletions

File tree

Cargo.lock

Lines changed: 480 additions & 359 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/automation.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function auto_fish()
3030
sleep(3000)
3131
end
3232
hold_fishing_rod()
33-
client:use_item()
33+
client:start_use_item()
3434
end
3535
end, "auto-fish_watch-bobber")
3636

@@ -41,7 +41,7 @@ function auto_fish()
4141
end)[1]
4242
if distance(current_bobber.position, particle.position) <= 0.75 then
4343
FishLastCaught = os.time()
44-
client:use_item()
44+
client:start_use_item()
4545
end
4646
end
4747
end, "auto-fish")
@@ -54,11 +54,11 @@ function auto_fish()
5454

5555
if os.time() - FishLastCaught >= 60 then
5656
hold_fishing_rod()
57-
client:use_item()
57+
client:start_use_item()
5858
end
5959
end, "auto-fish_watchdog")
6060

61-
client:use_item()
61+
client:start_use_item()
6262
end
6363

6464
function stop_auto_fish()
@@ -71,7 +71,7 @@ function stop_auto_fish()
7171
return e.id == FishingBobber.id
7272
end)[1] then
7373
FishingBobber = nil
74-
client:use_item()
74+
client:start_use_item()
7575
end
7676
end
7777

@@ -131,6 +131,6 @@ function check_food(hunger)
131131
sleep(1000)
132132
LastEaten = current_time
133133
end
134-
client:use_item()
134+
client:start_use_item()
135135
end
136136
end

src/events.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::{
2323
replay::recorder::Recorder,
2424
};
2525

26-
#[allow(clippy::too_many_lines)]
26+
#[allow(clippy::cognitive_complexity, clippy::too_many_lines)]
2727
pub async fn handle_event(client: Client, event: Event, state: State) -> Result<()> {
2828
match event {
2929
Event::AddPlayer(player_info) => {
@@ -35,6 +35,7 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> Result<
3535
let uuid = message.sender_uuid().map(|uuid| uuid.to_string());
3636
let is_whisper = message.is_whisper();
3737
let text = message.message();
38+
let html_text = text.to_html();
3839
let ansi_text = text.to_ansi();
3940
info!("{ansi_text}");
4041

@@ -86,6 +87,7 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> Result<
8687
let table = state.lua.create_table()?;
8788
table.set("text", text.to_string())?;
8889
table.set("ansi_text", ansi_text)?;
90+
table.set("html_text", html_text)?;
8991
table.set("sender", sender)?;
9092
table.set("content", content)?;
9193
table.set("uuid", uuid)?;
@@ -101,6 +103,7 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> Result<
101103
let message_table = state.lua.create_table()?;
102104
message_table.set("text", packet.message.to_string())?;
103105
message_table.set("ansi_text", packet.message.to_ansi())?;
106+
message_table.set("html_text", packet.message.to_html())?;
104107
let table = state.lua.create_table()?;
105108
table.set("message", message_table)?;
106109
table.set("player_id", packet.player_id.0)?;
@@ -117,6 +120,7 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> Result<
117120
let table = state.lua.create_table()?;
118121
table.set("text", message.to_string())?;
119122
table.set("ansi_text", message.to_ansi())?;
123+
table.set("html_text", message.to_html())?;
120124
Ok(table)
121125
})
122126
.await
@@ -125,7 +129,6 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> Result<
125129
}
126130
}
127131
Event::KeepAlive(id) => call_listeners(&state, "keep_alive", || Ok(id)).await,
128-
Event::Login => call_listeners(&state, "login", || Ok(())).await,
129132
Event::RemovePlayer(player_info) => {
130133
call_listeners(&state, "remove_player", || Ok(Player::from(player_info))).await
131134
}
@@ -201,6 +204,12 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> Result<
201204
}
202205
_ => Ok(()),
203206
},
207+
Event::Login => {
208+
#[cfg(feature = "matrix")]
209+
matrix_init(&client, state.clone());
210+
211+
call_listeners(&state, "login", || Ok(())).await
212+
}
204213
Event::Init => {
205214
debug!("received init event");
206215

@@ -212,9 +221,6 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> Result<
212221
exit(0);
213222
})?;
214223

215-
#[cfg(feature = "matrix")]
216-
matrix_init(&client, state.clone());
217-
218224
let globals = state.lua.globals();
219225
lua_init(client, &state, &globals).await?;
220226

src/hacks/mod.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,17 @@
33
pub mod anti_knockback;
44

55
use anti_knockback::anti_knockback;
6-
use azalea::{movement::handle_knockback, packet::game::process_packet_events};
6+
use azalea::{connection::read_packets, movement::handle_knockback};
77
use bevy_app::{App, Plugin, PreUpdate};
8-
use bevy_ecs::schedule::IntoSystemConfigs;
8+
use bevy_ecs::schedule::IntoScheduleConfigs;
99

1010
pub struct HacksPlugin;
1111

1212
impl Plugin for HacksPlugin {
1313
fn build(&self, app: &mut App) {
1414
app.add_systems(
1515
PreUpdate,
16-
anti_knockback
17-
.after(process_packet_events)
18-
.before(handle_knockback),
16+
anti_knockback.after(read_packets).before(handle_knockback),
1917
);
2018
}
2119
}

src/lua/block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub async fn get_block_states(
6060
true
6161
})
6262
{
63-
matched.push(block.id);
63+
matched.push(block.id());
6464
}
6565
}
6666
}

src/lua/client/container.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use azalea::{
44
prelude::ContainerClientExt,
55
protocol::packets::game::ServerboundSetCarriedItem,
66
};
7-
use log::error;
87
use mlua::{Lua, Result, UserDataRef, Value};
98

109
use super::{Client, Container, ContainerRef, ItemStack, Vec3};
@@ -126,11 +125,8 @@ pub fn set_held_slot(_lua: &Lua, client: &Client, slot: u8) -> Result<()> {
126125
inventory.selected_hotbar_slot = slot;
127126
};
128127

129-
if let Err(error) = client.write_packet(ServerboundSetCarriedItem {
128+
client.write_packet(ServerboundSetCarriedItem {
130129
slot: u16::from(slot),
131-
}) {
132-
error!("failed to send SetCarriedItem packet: {error:?}");
133-
}
134-
130+
});
135131
Ok(())
136132
}

src/lua/client/interaction.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use azalea::{
33
protocol::packets::game::{ServerboundUseItem, s_interact::InteractionHand},
44
world::MinecraftEntityId,
55
};
6-
use log::error;
76
use mlua::{Lua, Result, UserDataRef};
87

98
use super::{Client, Vec3};
@@ -40,8 +39,8 @@ pub async fn mine(_lua: Lua, client: UserDataRef<Client>, position: Vec3) -> Res
4039
Ok(())
4140
}
4241

43-
pub fn set_mining(_lua: &Lua, client: &Client, mining: bool) -> Result<()> {
44-
client.left_click_mine(mining);
42+
pub fn set_mining(_lua: &Lua, client: &Client, state: bool) -> Result<()> {
43+
client.left_click_mine(state);
4544
Ok(())
4645
}
4746

@@ -55,18 +54,7 @@ pub fn start_mining(_lua: &Lua, client: &Client, position: Vec3) -> Result<()> {
5554
Ok(())
5655
}
5756

58-
pub fn use_item(_lua: &Lua, client: &Client, hand: Option<u8>) -> Result<()> {
59-
let direction = client.direction();
60-
if let Err(error) = client.write_packet(ServerboundUseItem {
61-
hand: match hand {
62-
Some(1) => InteractionHand::OffHand,
63-
_ => InteractionHand::MainHand,
64-
},
65-
sequence: 0,
66-
yaw: direction.0,
67-
pitch: direction.1,
68-
}) {
69-
error!("failed to send UseItem packet: {error:?}");
70-
}
57+
pub fn start_use_item(_lua: &Lua, client: &Client, hand: Option<u8>) -> Result<()> {
58+
client.start_use_item();
7159
Ok(())
7260
}

src/lua/client/mod.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,11 @@ impl UserData for Client {
6464
m.add_async_method("find_entities", world::find::entities);
6565
m.add_async_method("find_players", world::find::players);
6666
m.add_async_method("go_to", movement::go_to);
67-
m.add_async_method(
68-
"go_to_wait_until_reached",
69-
movement::go_to_wait_until_reached,
70-
);
7167
m.add_async_method("mine", interaction::mine);
7268
m.add_async_method("open_container_at", container::open_container_at);
7369
m.add_async_method("set_client_information", state::set_client_information);
7470
m.add_async_method("start_go_to", movement::start_go_to);
71+
m.add_async_method("wait_until_goal_reached", movement::wait_until_goal_reached);
7572
m.add_method("attack", interaction::attack);
7673
m.add_method("best_tool_for_block", world::best_tool_for_block);
7774
m.add_method("block_interact", interaction::block_interact);
@@ -92,9 +89,9 @@ impl UserData for Client {
9289
m.add_method("set_sneaking", movement::set_sneaking);
9390
m.add_method("sprint", movement::sprint);
9491
m.add_method("start_mining", interaction::start_mining);
92+
m.add_method("start_use_item", interaction::start_use_item);
9593
m.add_method("stop_pathfinding", movement::stop_pathfinding);
9694
m.add_method("stop_sleeping", movement::stop_sleeping);
97-
m.add_method("use_item", interaction::use_item);
9895
m.add_method("walk", movement::walk);
9996
}
10097
}

src/lua/client/movement.rs

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ use azalea::{
33
entity::Position,
44
interact::HitResultComponent,
55
pathfinder::{
6-
ExecutingPath, GotoEvent, Pathfinder, PathfinderClientExt,
6+
ExecutingPath, Pathfinder, PathfinderClientExt,
77
goals::{BlockPosGoal, Goal, InverseGoal, RadiusGoal, ReachBlockPosGoal, XZGoal, YGoal},
88
},
99
protocol::packets::game::{ServerboundPlayerCommand, s_player_command::Action},
1010
world::MinecraftEntityId,
1111
};
12-
use log::error;
1312
use mlua::{FromLua, Lua, Result, Table, UserDataRef, Value};
1413

1514
use super::{Client, Direction, Vec3};
@@ -39,10 +38,11 @@ fn to_goal(lua: &Lua, client: &Client, data: Table, options: &Table, kind: u8) -
3938
}
4039
2 => {
4140
let pos = Vec3::from_lua(Value::Table(data), lua)?;
42-
Box::new(ReachBlockPosGoal {
43-
pos: BlockPos::new(pos.x as i32, pos.y as i32, pos.z as i32),
44-
chunk_storage: client.world().read().chunks.clone(),
45-
})
41+
Box::new(ReachBlockPosGoal::new_with_distance(
42+
BlockPos::new(pos.x as i32, pos.y as i32, pos.z as i32),
43+
data.get("distance").unwrap_or(4.5),
44+
client.world().read().chunks.clone(),
45+
))
4646
}
4747
3 => Box::new(XZGoal {
4848
x: data.get("x")?,
@@ -70,11 +70,7 @@ pub fn go_to_reached(_lua: &Lua, client: &Client) -> Result<bool> {
7070
Ok(client.is_goto_target_reached())
7171
}
7272

73-
pub async fn go_to_wait_until_reached(
74-
_lua: Lua,
75-
client: UserDataRef<Client>,
76-
(): (),
77-
) -> Result<()> {
73+
pub async fn wait_until_goal_reached(_lua: Lua, client: UserDataRef<Client>, (): ()) -> Result<()> {
7874
client.wait_until_goto_target_reached().await;
7975
Ok(())
8076
}
@@ -121,11 +117,7 @@ pub async fn start_go_to(
121117
} else {
122118
client.start_goto(goal);
123119
}
124-
while client.get_tick_broadcaster().recv().await.is_ok() {
125-
if client.ecs.lock().get::<GotoEvent>(client.entity).is_none() {
126-
break;
127-
}
128-
}
120+
let _ = client.get_tick_broadcaster().recv().await;
129121

130122
Ok(())
131123
}
@@ -215,17 +207,15 @@ pub fn set_position(_lua: &Lua, client: &Client, new_position: Vec3) -> Result<(
215207
}
216208

217209
pub fn set_sneaking(_lua: &Lua, client: &Client, sneaking: bool) -> Result<()> {
218-
if let Err(error) = client.write_packet(ServerboundPlayerCommand {
210+
client.write_packet(ServerboundPlayerCommand {
219211
id: client.component::<MinecraftEntityId>(),
220212
action: if sneaking {
221213
Action::PressShiftKey
222214
} else {
223215
Action::ReleaseShiftKey
224216
},
225217
data: 0,
226-
}) {
227-
error!("failed to send PlayerCommand packet: {error:?}");
228-
}
218+
});
229219
Ok(())
230220
}
231221

@@ -244,13 +234,11 @@ pub fn stop_pathfinding(_lua: &Lua, client: &Client, (): ()) -> Result<()> {
244234
}
245235

246236
pub fn stop_sleeping(_lua: &Lua, client: &Client, (): ()) -> Result<()> {
247-
if let Err(error) = client.write_packet(ServerboundPlayerCommand {
237+
client.write_packet(ServerboundPlayerCommand {
248238
id: client.component::<MinecraftEntityId>(),
249239
action: Action::StopSleeping,
250240
data: 0,
251-
}) {
252-
error!("failed to send PlayerCommand packet: {error:?}");
253-
}
241+
});
254242
Ok(())
255243
}
256244

src/lua/client/state.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use azalea::{
22
ClientInformation,
33
entity::metadata::{AirSupply, Score},
4-
pathfinder::PathfinderDebugParticles,
4+
pathfinder::debug::PathfinderDebugParticles,
55
protocol::common::client_information::ModelCustomization,
66
};
77
use mlua::{Error, Lua, Result, Table, UserDataRef};
@@ -40,21 +40,22 @@ pub async fn set_client_information(
4040
allows_listing: info.get("allows_listing")?,
4141
model_customization: info
4242
.get::<Table>("model_customization")
43+
.as_ref()
4344
.map(|t| ModelCustomization {
44-
cape: get_bool(&t, "cape"),
45-
jacket: get_bool(&t, "jacket"),
46-
left_sleeve: get_bool(&t, "left_sleeve"),
47-
right_sleeve: get_bool(&t, "right_sleeve"),
48-
left_pants: get_bool(&t, "left_pants"),
49-
right_pants: get_bool(&t, "right_pants"),
50-
hat: get_bool(&t, "hat"),
45+
cape: get_bool(t, "cape"),
46+
jacket: get_bool(t, "jacket"),
47+
left_sleeve: get_bool(t, "left_sleeve"),
48+
right_sleeve: get_bool(t, "right_sleeve"),
49+
left_pants: get_bool(t, "left_pants"),
50+
right_pants: get_bool(t, "right_pants"),
51+
hat: get_bool(t, "hat"),
5152
})
5253
.unwrap_or_default(),
5354
view_distance: info.get("view_distance").unwrap_or(8),
5455
..ClientInformation::default()
5556
})
56-
.await
57-
.map_err(Error::external)
57+
.await;
58+
Ok(())
5859
}
5960

6061
pub fn set_component(

0 commit comments

Comments
 (0)