feat(client): add set_position method

This commit is contained in:
Ryan 2025-02-22 14:02:32 -05:00
parent aaad1fe78a
commit 3236c4c32e
Signed by: ErrorNoInternet
GPG Key ID: 2486BFB7B1E6A4A3
2 changed files with 10 additions and 0 deletions

View File

@ -72,6 +72,7 @@ impl UserData for Client {
m.add_method("get_fluid_state", world::get_fluid_state);
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);
m.add_method("set_sneaking", movement::set_sneaking);
m.add_method("stop_pathfinding", movement::stop_pathfinding);
m.add_method("stop_sleeping", movement::stop_sleeping);

View File

@ -185,6 +185,15 @@ pub fn set_jumping(_lua: &Lua, client: &mut Client, jumping: bool) -> Result<()>
Ok(())
}
pub fn set_position(_lua: &Lua, client: &Client, new_position: Vec3) -> Result<()> {
let mut ecs = client.ecs.lock();
let mut position = client.query::<&mut Position>(&mut ecs);
position.x = new_position.x;
position.y = new_position.y;
position.z = new_position.z;
Ok(())
}
pub fn set_sneaking(_lua: &Lua, client: &Client, sneaking: bool) -> Result<()> {
if let Err(error) = client.write_packet(ServerboundPlayerCommand {
id: client.component::<MinecraftEntityId>(),