From 3a93bb9e33524f910dc848b417fc27161c1e1782 Mon Sep 17 00:00:00 2001 From: ErrorNoInternet Date: Sat, 22 Feb 2025 14:24:02 -0500 Subject: [PATCH] feat(client): pass entity direction in find_entities --- src/lua/client/movement.rs | 4 ++-- src/lua/client/world.rs | 11 ++++++++--- src/lua/direction.rs | 10 ++++++++++ 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/lua/client/movement.rs b/src/lua/client/movement.rs index 7ad4720..e7028cc 100644 --- a/src/lua/client/movement.rs +++ b/src/lua/client/movement.rs @@ -175,8 +175,8 @@ pub fn position(_lua: &Lua, client: &Client) -> Result { Ok(Vec3::from(&client.component::())) } -pub fn set_direction(_lua: &Lua, client: &mut Client, direction: (f32, f32)) -> Result<()> { - client.set_direction(direction.0, direction.1); +pub fn set_direction(_lua: &Lua, client: &mut Client, direction: Direction) -> Result<()> { + client.set_direction(direction.y, direction.x); Ok(()) } diff --git a/src/lua/client/world.rs b/src/lua/client/world.rs index 3c07c60..0145eca 100644 --- a/src/lua/client/world.rs +++ b/src/lua/client/world.rs @@ -1,10 +1,13 @@ -use super::{Client, Vec3}; +use super::{Client, Direction, Vec3}; use azalea::{ BlockPos, auto_tool::AutoToolClientExt, blocks::{BlockState, BlockStates}, ecs::query::Without, - entity::{Dead, EntityKind, EntityUuid, Position as AzaleaPosition, metadata::CustomName}, + entity::{ + Dead, EntityKind, EntityUuid, LookDirection, Position as AzaleaPosition, + metadata::CustomName, + }, world::{InstanceName, MinecraftEntityId}, }; use mlua::{Function, Lua, Result, Table}; @@ -54,15 +57,17 @@ pub fn find_entities(lua: &Lua, client: &Client, filter_fn: Function) -> Result< &EntityUuid, &EntityKind, &AzaleaPosition, + &LookDirection, &CustomName, ), Without>(); - for (&id, uuid, kind, position, custom_name) in query.iter(&ecs) { + for (&id, uuid, kind, position, direction, custom_name) in query.iter(&ecs) { let entity = lua.create_table()?; entity.set("id", id.0)?; entity.set("uuid", uuid.to_string())?; entity.set("kind", kind.to_string())?; entity.set("position", Vec3::from(position))?; + entity.set("direction", Direction::from(direction))?; entity.set("custom_name", custom_name.as_ref().map(ToString::to_string))?; if filter_fn.call::(&entity)? { diff --git a/src/lua/direction.rs b/src/lua/direction.rs index 6f18d51..b677d9c 100644 --- a/src/lua/direction.rs +++ b/src/lua/direction.rs @@ -1,3 +1,4 @@ +use azalea::entity::LookDirection; use mlua::{FromLua, IntoLua, Lua, Result, Value}; #[derive(Clone)] @@ -6,6 +7,15 @@ pub struct Direction { pub y: f32, } +impl From<&LookDirection> for Direction { + fn from(d: &LookDirection) -> Self { + Self { + x: d.x_rot, + y: d.y_rot, + } + } +} + impl IntoLua for Direction { fn into_lua(self, lua: &Lua) -> Result { let table = lua.create_table()?;