From 8f2fbf11da3df68815afe5371c0b067f4378577f Mon Sep 17 00:00:00 2001 From: ErrorNoInternet Date: Mon, 17 Feb 2025 15:07:31 -0500 Subject: [PATCH] feat(client): add last few fields and methods --- src/lua/client/interaction.rs | 4 ++++ src/lua/client/mod.rs | 17 ++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/lua/client/interaction.rs b/src/lua/client/interaction.rs index 0deb5bc..b68c795 100644 --- a/src/lua/client/interaction.rs +++ b/src/lua/client/interaction.rs @@ -21,6 +21,10 @@ pub fn block_interact(_lua: &Lua, client: &mut Client, position: Vec3) -> Result Ok(()) } +pub fn has_attack_cooldown(_lua: &Lua, client: &Client) -> Result { + Ok(client.inner.as_ref().unwrap().has_attack_cooldown()) +} + pub async fn mine(_lua: Lua, client: UserDataRef, position: Vec3) -> Result<()> { #[allow(clippy::cast_possible_truncation)] client diff --git a/src/lua/client/mod.rs b/src/lua/client/mod.rs index 46cf497..6b60d7a 100644 --- a/src/lua/client/mod.rs +++ b/src/lua/client/mod.rs @@ -26,6 +26,7 @@ impl UserData for Client { f.add_field_method_get("air_supply", state::air_supply); f.add_field_method_get("direction", movement::direction); f.add_field_method_get("eye_position", movement::eye_position); + f.add_field_method_get("has_attack_cooldown", interaction::has_attack_cooldown); f.add_field_method_get("health", state::health); f.add_field_method_get("held_item", container::held_item); f.add_field_method_get("held_slot", container::held_slot); @@ -46,6 +47,7 @@ impl UserData for Client { m.add_method("best_tool_for_block", world::best_tool_for_block); m.add_method("block_names_to_states", world::block_names_to_states); m.add_method("chat", chat); + m.add_method("disconnect", disconnect); m.add_method("find_blocks", world::find_blocks); m.add_method("find_entities", world::find_entities); m.add_method("get_block_from_state", world::get_block_from_state); @@ -68,6 +70,16 @@ impl UserData for Client { } } +fn chat(_lua: &Lua, client: &Client, message: String) -> Result<()> { + client.inner.as_ref().unwrap().chat(&message); + Ok(()) +} + +fn disconnect(_lua: &Lua, client: &Client, _: ()) -> Result<()> { + client.inner.as_ref().unwrap().disconnect(); + Ok(()) +} + fn tab_list(lua: &Lua, client: &Client) -> Result { let tab_list = lua.create_table()?; for (uuid, player_info) in client.inner.as_ref().unwrap().tab_list() { @@ -87,8 +99,3 @@ fn tab_list(lua: &Lua, client: &Client) -> Result
{ fn uuid(_lua: &Lua, client: &Client) -> Result { Ok(client.inner.as_ref().unwrap().uuid().to_string()) } - -fn chat(_lua: &Lua, client: &Client, message: String) -> Result<()> { - client.inner.as_ref().unwrap().chat(&message); - Ok(()) -}