feat(client): add set_component method
This commit is contained in:
parent
34dc14d6b2
commit
5ec14d979d
@ -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);
|
||||
|
@ -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<i32> {
|
||||
Ok(client.component::<AirSupply>().0)
|
||||
@ -59,3 +60,27 @@ pub async fn set_client_information(
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn set_component(
|
||||
_lua: &Lua,
|
||||
client: &Client,
|
||||
(name, enabled): (String, Option<bool>),
|
||||
) -> 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")),
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user