From 8494c35d1c0c7e3c01314b8200299ce9aeb6021b Mon Sep 17 00:00:00 2001
From: ErrorNoInternet <errornointernet@envs.net>
Date: Tue, 18 Mar 2025 17:14:24 -0400
Subject: [PATCH] refactor: bring azalea-hax crate in-tree

---
 Cargo.lock                  |  9 ---------
 Cargo.toml                  |  1 -
 src/hacks/anti_knockback.rs | 20 ++++++++++++++++++++
 src/hacks/mod.rs            | 21 +++++++++++++++++++++
 src/lua/client/state.rs     |  3 ++-
 src/main.rs                 |  5 +++--
 6 files changed, 46 insertions(+), 13 deletions(-)
 create mode 100644 src/hacks/anti_knockback.rs
 create mode 100644 src/hacks/mod.rs

diff --git a/Cargo.lock b/Cargo.lock
index 26b4e32..a23cf9d 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -593,14 +593,6 @@ dependencies = [
  "uuid",
 ]
 
-[[package]]
-name = "azalea-hax"
-version = "0.1.0"
-source = "git+https://github.com/azalea-rs/azalea-hax#2af9e0759aded7df01770b717f207b3c1083f942"
-dependencies = [
- "azalea",
-]
-
 [[package]]
 name = "azalea-inventory"
 version = "0.11.0+mc1.21.4"
@@ -1749,7 +1741,6 @@ version = "0.2.0"
 dependencies = [
  "anyhow",
  "azalea",
- "azalea-hax",
  "bevy_app",
  "bevy_ecs",
  "bevy_log",
diff --git a/Cargo.toml b/Cargo.toml
index 5d83ebd..5e2db8b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -21,7 +21,6 @@ built = { git = "https://github.com/lukaslueg/built", features = ["git2"] }
 [dependencies]
 anyhow = "1"
 azalea = { git = "https://github.com/azalea-rs/azalea" }
-azalea-hax = { git = "https://github.com/azalea-rs/azalea-hax" }
 bevy_app = "0"
 bevy_ecs = "0"
 bevy_log = "0"
diff --git a/src/hacks/anti_knockback.rs b/src/hacks/anti_knockback.rs
new file mode 100644
index 0000000..7075a7b
--- /dev/null
+++ b/src/hacks/anti_knockback.rs
@@ -0,0 +1,20 @@
+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());
+        }
+    }
+}
diff --git a/src/hacks/mod.rs b/src/hacks/mod.rs
new file mode 100644
index 0000000..6175cfd
--- /dev/null
+++ b/src/hacks/mod.rs
@@ -0,0 +1,21 @@
+#![allow(clippy::needless_pass_by_value)]
+
+pub mod anti_knockback;
+
+use anti_knockback::anti_knockback;
+use azalea::{movement::handle_knockback, packet_handling::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),
+        );
+    }
+}
diff --git a/src/lua/client/state.rs b/src/lua/client/state.rs
index 48e8167..249a0a6 100644
--- a/src/lua/client/state.rs
+++ b/src/lua/client/state.rs
@@ -1,3 +1,5 @@
+use crate::hacks::anti_knockback::AntiKnockback;
+
 use super::Client;
 use azalea::{
     ClientInformation,
@@ -5,7 +7,6 @@ use azalea::{
     pathfinder::PathfinderDebugParticles,
     protocol::common::client_information::ModelCustomization,
 };
-use azalea_hax::AntiKnockback;
 use mlua::{Error, Lua, Result, Table, UserDataRef};
 
 pub fn air_supply(_lua: &Lua, client: &Client) -> Result<i32> {
diff --git a/src/main.rs b/src/main.rs
index 4538797..09dadb8 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -4,6 +4,7 @@ mod arguments;
 mod build_info;
 mod commands;
 mod events;
+mod hacks;
 mod http;
 mod lua;
 mod particle;
@@ -17,7 +18,6 @@ use arguments::Arguments;
 use azalea::{
     DefaultBotPlugins, DefaultPlugins, brigadier::prelude::CommandDispatcher, prelude::*,
 };
-use azalea_hax::HaxPlugin;
 use bevy_app::PluginGroup;
 use bevy_log::{
     LogPlugin,
@@ -27,6 +27,7 @@ use clap::Parser;
 use commands::{CommandSource, register};
 use futures::lock::Mutex;
 use futures_locks::RwLock;
+use hacks::HacksPlugin;
 use log::debug;
 use mlua::{Function, Lua, Table};
 use replay::{plugin::RecordPlugin, recorder::Recorder};
@@ -130,7 +131,7 @@ async fn main() -> anyhow::Result<()> {
 
     let Err(error) = ClientBuilder::new_without_plugins()
         .add_plugins(DefaultBotPlugins)
-        .add_plugins(HaxPlugin)
+        .add_plugins(HacksPlugin)
         .add_plugins(default_plugins)
         .add_plugins(record_plugin)
         .set_handler(events::handle_event)