From 5ec14d979d2e8199b91751376ef5df509032e751 Mon Sep 17 00:00:00 2001 From: ErrorNoInternet Date: Thu, 13 Mar 2025 20:38:40 -0400 Subject: [PATCH] feat(client): add set_component method --- src/lua/client/mod.rs | 1 + src/lua/client/state.rs | 27 ++++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/lua/client/mod.rs b/src/lua/client/mod.rs index 21d7b5f..e5d2b85 100644 --- a/src/lua/client/mod.rs +++ b/src/lua/client/mod.rs @@ -70,6 +70,7 @@ impl UserData for Client { m.add_method("find_blocks", world::find_blocks); m.add_method("get_block_state", world::get_block_state); m.add_method("get_fluid_state", world::get_fluid_state); + m.add_method("set_component", state::set_component); m.add_method("set_held_slot", container::set_held_slot); m.add_method("set_mining", interaction::set_mining); m.add_method("set_position", movement::set_position); diff --git a/src/lua/client/state.rs b/src/lua/client/state.rs index 3c2fb0b..0b66e1d 100644 --- a/src/lua/client/state.rs +++ b/src/lua/client/state.rs @@ -2,10 +2,11 @@ use super::Client; use azalea::{ ClientInformation, entity::metadata::{AirSupply, Score}, + pathfinder::PathfinderDebugParticles, protocol::common::client_information::ModelCustomization, }; use log::error; -use mlua::{Lua, Result, Table, UserDataRef}; +use mlua::{Error, Lua, Result, Table, UserDataRef}; pub fn air_supply(_lua: &Lua, client: &Client) -> Result { Ok(client.component::().0) @@ -59,3 +60,27 @@ pub async fn set_client_information( } Ok(()) } + +pub fn set_component( + _lua: &Lua, + client: &Client, + (name, enabled): (String, Option), +) -> Result<()> { + macro_rules! set { + ($name:ident) => {{ + let mut ecs = client.ecs.lock(); + let mut entity = ecs.entity_mut(client.entity); + if enabled.unwrap_or(true) { + entity.insert($name) + } else { + entity.remove::<$name>() + }; + Ok(()) + }}; + } + + match name.as_str() { + "PathfinderDebugParticles" => set!(PathfinderDebugParticles), + _ => Err(Error::external("invalid component")), + } +}