Skip to content

Commit b3b2252

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

14 files changed

Lines changed: 651 additions & 554 deletions

File tree

Cargo.lock

Lines changed: 548 additions & 436 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: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use azalea::{
2-
BlockPos, BotClientExt,
3-
protocol::packets::game::{ServerboundUseItem, s_interact::InteractionHand},
4-
world::MinecraftEntityId,
2+
BlockPos, BotClientExt, interact::StartUseItemEvent,
3+
protocol::packets::game::s_interact::InteractionHand, world::MinecraftEntityId,
54
};
6-
use log::error;
75
use mlua::{Lua, Result, UserDataRef};
86

97
use super::{Client, Vec3};
@@ -40,8 +38,8 @@ pub async fn mine(_lua: Lua, client: UserDataRef<Client>, position: Vec3) -> Res
4038
Ok(())
4139
}
4240

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

@@ -55,18 +53,14 @@ pub fn start_mining(_lua: &Lua, client: &Client, position: Vec3) -> Result<()> {
5553
Ok(())
5654
}
5755

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 {
56+
pub fn start_use_item(_lua: &Lua, client: &Client, hand: Option<u8>) -> Result<()> {
57+
client.ecs.lock().send_event(StartUseItemEvent {
58+
entity: client.entity,
6159
hand: match hand {
6260
Some(1) => InteractionHand::OffHand,
6361
_ => InteractionHand::MainHand,
6462
},
65-
sequence: 0,
66-
yaw: direction.0,
67-
pitch: direction.1,
68-
}) {
69-
error!("failed to send UseItem packet: {error:?}");
70-
}
63+
force_block: None,
64+
});
7165
Ok(())
7266
}

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: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
use azalea::{
22
BlockPos, BotClientExt, SprintDirection, WalkDirection,
3+
core::hit_result::HitResult,
34
entity::Position,
45
interact::HitResultComponent,
56
pathfinder::{
6-
ExecutingPath, GotoEvent, Pathfinder, PathfinderClientExt,
7+
ExecutingPath, Pathfinder, PathfinderClientExt,
78
goals::{BlockPosGoal, Goal, InverseGoal, RadiusGoal, ReachBlockPosGoal, XZGoal, YGoal},
89
},
910
protocol::packets::game::{ServerboundPlayerCommand, s_player_command::Action},
1011
world::MinecraftEntityId,
1112
};
12-
use log::error;
1313
use mlua::{FromLua, Lua, Result, Table, UserDataRef, Value};
1414

1515
use super::{Client, Direction, Vec3};
@@ -38,11 +38,13 @@ fn to_goal(lua: &Lua, client: &Client, data: Table, options: &Table, kind: u8) -
3838
})
3939
}
4040
2 => {
41+
let distance = data.get("distance").unwrap_or(4.5);
4142
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-
})
43+
Box::new(ReachBlockPosGoal::new_with_distance(
44+
BlockPos::new(pos.x as i32, pos.y as i32, pos.z as i32),
45+
distance,
46+
client.world().read().chunks.clone(),
47+
))
4648
}
4749
3 => Box::new(XZGoal {
4850
x: data.get("x")?,
@@ -70,11 +72,7 @@ pub fn go_to_reached(_lua: &Lua, client: &Client) -> Result<bool> {
7072
Ok(client.is_goto_target_reached())
7173
}
7274

73-
pub async fn go_to_wait_until_reached(
74-
_lua: Lua,
75-
client: UserDataRef<Client>,
76-
(): (),
77-
) -> Result<()> {
75+
pub async fn wait_until_goal_reached(_lua: Lua, client: UserDataRef<Client>, (): ()) -> Result<()> {
7876
client.wait_until_goto_target_reached().await;
7977
Ok(())
8078
}
@@ -121,11 +119,7 @@ pub async fn start_go_to(
121119
} else {
122120
client.start_goto(goal);
123121
}
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-
}
122+
let _ = client.get_tick_broadcaster().recv().await;
129123

130124
Ok(())
131125
}
@@ -148,16 +142,19 @@ pub fn jump(_lua: &Lua, client: &Client, (): ()) -> Result<()> {
148142
}
149143

150144
pub fn looking_at(lua: &Lua, client: &Client) -> Result<Option<Table>> {
151-
let result = client.component::<HitResultComponent>();
152-
Ok(if result.miss {
153-
None
154-
} else {
155-
let table = lua.create_table()?;
156-
table.set("position", Vec3::from(result.block_pos))?;
157-
table.set("inside", result.inside)?;
158-
table.set("world_border", result.world_border)?;
159-
Some(table)
160-
})
145+
Ok(
146+
if let HitResult::Block(ref result) = *client.component::<HitResultComponent>() {
147+
let table = lua.create_table()?;
148+
table.set("direction", Vec3::from(result.direction.normal()))?;
149+
table.set("inside", result.inside)?;
150+
table.set("location", Vec3::from(result.location))?;
151+
table.set("position", Vec3::from(result.block_pos))?;
152+
table.set("world_border", result.world_border)?;
153+
Some(table)
154+
} else {
155+
None
156+
},
157+
)
161158
}
162159

163160
pub fn look_at(_lua: &Lua, client: &Client, position: Vec3) -> Result<()> {
@@ -215,17 +212,15 @@ pub fn set_position(_lua: &Lua, client: &Client, new_position: Vec3) -> Result<(
215212
}
216213

217214
pub fn set_sneaking(_lua: &Lua, client: &Client, sneaking: bool) -> Result<()> {
218-
if let Err(error) = client.write_packet(ServerboundPlayerCommand {
215+
client.write_packet(ServerboundPlayerCommand {
219216
id: client.component::<MinecraftEntityId>(),
220217
action: if sneaking {
221218
Action::PressShiftKey
222219
} else {
223220
Action::ReleaseShiftKey
224221
},
225222
data: 0,
226-
}) {
227-
error!("failed to send PlayerCommand packet: {error:?}");
228-
}
223+
});
229224
Ok(())
230225
}
231226

@@ -244,13 +239,11 @@ pub fn stop_pathfinding(_lua: &Lua, client: &Client, (): ()) -> Result<()> {
244239
}
245240

246241
pub fn stop_sleeping(_lua: &Lua, client: &Client, (): ()) -> Result<()> {
247-
if let Err(error) = client.write_packet(ServerboundPlayerCommand {
242+
client.write_packet(ServerboundPlayerCommand {
248243
id: client.component::<MinecraftEntityId>(),
249244
action: Action::StopSleeping,
250245
data: 0,
251-
}) {
252-
error!("failed to send PlayerCommand packet: {error:?}");
253-
}
246+
});
254247
Ok(())
255248
}
256249

0 commit comments

Comments
 (0)