feat(client): pass entity direction in find_entities
This commit is contained in:
		| @@ -175,8 +175,8 @@ pub fn position(_lua: &Lua, client: &Client) -> Result<Vec3> { | ||||
|     Ok(Vec3::from(&client.component::<Position>())) | ||||
| } | ||||
|  | ||||
| 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(()) | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -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<Dead>>(); | ||||
|  | ||||
|     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::<bool>(&entity)? { | ||||
|   | ||||
| @@ -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<Value> { | ||||
|         let table = lua.create_table()?; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user