Skip to content

Commit 0438434

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

12 files changed

Lines changed: 428 additions & 305 deletions

File tree

Cargo.lock

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

src/events.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> Result<
125125
}
126126
}
127127
Event::KeepAlive(id) => call_listeners(&state, "keep_alive", || Ok(id)).await,
128-
Event::Login => call_listeners(&state, "login", || Ok(())).await,
129128
Event::RemovePlayer(player_info) => {
130129
call_listeners(&state, "remove_player", || Ok(Player::from(player_info))).await
131130
}
@@ -201,6 +200,12 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> Result<
201200
}
202201
_ => Ok(()),
203202
},
203+
Event::Login => {
204+
#[cfg(feature = "matrix")]
205+
matrix_init(&client, state.clone());
206+
207+
call_listeners(&state, "login", || Ok(())).await
208+
}
204209
Event::Init => {
205210
debug!("received init event");
206211

@@ -212,9 +217,6 @@ pub async fn handle_event(client: Client, event: Event, state: State) -> Result<
212217
exit(0);
213218
})?;
214219

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

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: 2 additions & 5 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};
@@ -57,16 +56,14 @@ pub fn start_mining(_lua: &Lua, client: &Client, position: Vec3) -> Result<()> {
5756

5857
pub fn use_item(_lua: &Lua, client: &Client, hand: Option<u8>) -> Result<()> {
5958
let direction = client.direction();
60-
if let Err(error) = client.write_packet(ServerboundUseItem {
59+
client.write_packet(ServerboundUseItem {
6160
hand: match hand {
6261
Some(1) => InteractionHand::OffHand,
6362
_ => InteractionHand::MainHand,
6463
},
6564
sequence: 0,
6665
yaw: direction.0,
6766
pitch: direction.1,
68-
}) {
69-
error!("failed to send UseItem packet: {error:?}");
70-
}
67+
});
7168
Ok(())
7269
}

src/lua/client/movement.rs

Lines changed: 6 additions & 15 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};
@@ -121,11 +120,7 @@ pub async fn start_go_to(
121120
} else {
122121
client.start_goto(goal);
123122
}
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-
}
123+
let _ = client.get_tick_broadcaster().recv().await;
129124

130125
Ok(())
131126
}
@@ -215,17 +210,15 @@ pub fn set_position(_lua: &Lua, client: &Client, new_position: Vec3) -> Result<(
215210
}
216211

217212
pub fn set_sneaking(_lua: &Lua, client: &Client, sneaking: bool) -> Result<()> {
218-
if let Err(error) = client.write_packet(ServerboundPlayerCommand {
213+
client.write_packet(ServerboundPlayerCommand {
219214
id: client.component::<MinecraftEntityId>(),
220215
action: if sneaking {
221216
Action::PressShiftKey
222217
} else {
223218
Action::ReleaseShiftKey
224219
},
225220
data: 0,
226-
}) {
227-
error!("failed to send PlayerCommand packet: {error:?}");
228-
}
221+
});
229222
Ok(())
230223
}
231224

@@ -244,13 +237,11 @@ pub fn stop_pathfinding(_lua: &Lua, client: &Client, (): ()) -> Result<()> {
244237
}
245238

246239
pub fn stop_sleeping(_lua: &Lua, client: &Client, (): ()) -> Result<()> {
247-
if let Err(error) = client.write_packet(ServerboundPlayerCommand {
240+
client.write_packet(ServerboundPlayerCommand {
248241
id: client.component::<MinecraftEntityId>(),
249242
action: Action::StopSleeping,
250243
data: 0,
251-
}) {
252-
error!("failed to send PlayerCommand packet: {error:?}");
253-
}
244+
});
254245
Ok(())
255246
}
256247

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(

src/lua/client/world/find.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ pub fn blocks(
2828
nearest_to.z as i32,
2929
),
3030
&BlockStates {
31-
set: block_states.iter().map(|&id| BlockState { id }).collect(),
31+
set: block_states
32+
.into_iter()
33+
.flat_map(BlockState::try_from)
34+
.collect(),
3235
},
3336
)
3437
.map(Vec3::from)

src/lua/client/world/mod.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,19 @@ mod queries;
33
pub mod find;
44

55
use azalea::{BlockPos, auto_tool::AutoToolClientExt, blocks::BlockState, world::InstanceName};
6-
use mlua::{Lua, Result, Table};
6+
use mlua::{Lua, Result, Table, Value};
77

88
use super::{Client, Direction, Vec3};
99

10-
pub fn best_tool_for_block(lua: &Lua, client: &Client, block_state: u16) -> Result<Table> {
11-
let result = client.best_tool_in_hotbar_for_block(BlockState { id: block_state });
10+
pub fn best_tool_for_block(lua: &Lua, client: &Client, block_state: u16) -> Result<Value> {
11+
let Ok(block) = BlockState::try_from(block_state) else {
12+
return Ok(Value::Nil);
13+
};
14+
let result = client.best_tool_in_hotbar_for_block(block);
1215
let table = lua.create_table()?;
1316
table.set("index", result.index)?;
1417
table.set("percentage_per_tick", result.percentage_per_tick)?;
15-
Ok(table)
18+
Ok(Value::Table(table))
1619
}
1720

1821
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
2932
position.y as i32,
3033
position.z as i32,
3134
))
32-
.map(|block| block.id))
35+
.map(|block| block.id()))
3336
}
3437

3538
#[allow(clippy::cast_possible_truncation)]

0 commit comments

Comments
 (0)