feat(client): pass entity direction in find_entities
This commit is contained in:
parent
550aee5578
commit
3a93bb9e33
@ -175,8 +175,8 @@ pub fn position(_lua: &Lua, client: &Client) -> Result<Vec3> {
|
|||||||
Ok(Vec3::from(&client.component::<Position>()))
|
Ok(Vec3::from(&client.component::<Position>()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_direction(_lua: &Lua, client: &mut Client, direction: (f32, f32)) -> Result<()> {
|
pub fn set_direction(_lua: &Lua, client: &mut Client, direction: Direction) -> Result<()> {
|
||||||
client.set_direction(direction.0, direction.1);
|
client.set_direction(direction.y, direction.x);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
use super::{Client, Vec3};
|
use super::{Client, Direction, Vec3};
|
||||||
use azalea::{
|
use azalea::{
|
||||||
BlockPos,
|
BlockPos,
|
||||||
auto_tool::AutoToolClientExt,
|
auto_tool::AutoToolClientExt,
|
||||||
blocks::{BlockState, BlockStates},
|
blocks::{BlockState, BlockStates},
|
||||||
ecs::query::Without,
|
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},
|
world::{InstanceName, MinecraftEntityId},
|
||||||
};
|
};
|
||||||
use mlua::{Function, Lua, Result, Table};
|
use mlua::{Function, Lua, Result, Table};
|
||||||
@ -54,15 +57,17 @@ pub fn find_entities(lua: &Lua, client: &Client, filter_fn: Function) -> Result<
|
|||||||
&EntityUuid,
|
&EntityUuid,
|
||||||
&EntityKind,
|
&EntityKind,
|
||||||
&AzaleaPosition,
|
&AzaleaPosition,
|
||||||
|
&LookDirection,
|
||||||
&CustomName,
|
&CustomName,
|
||||||
), Without<Dead>>();
|
), 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()?;
|
let entity = lua.create_table()?;
|
||||||
entity.set("id", id.0)?;
|
entity.set("id", id.0)?;
|
||||||
entity.set("uuid", uuid.to_string())?;
|
entity.set("uuid", uuid.to_string())?;
|
||||||
entity.set("kind", kind.to_string())?;
|
entity.set("kind", kind.to_string())?;
|
||||||
entity.set("position", Vec3::from(position))?;
|
entity.set("position", Vec3::from(position))?;
|
||||||
|
entity.set("direction", Direction::from(direction))?;
|
||||||
entity.set("custom_name", custom_name.as_ref().map(ToString::to_string))?;
|
entity.set("custom_name", custom_name.as_ref().map(ToString::to_string))?;
|
||||||
|
|
||||||
if filter_fn.call::<bool>(&entity)? {
|
if filter_fn.call::<bool>(&entity)? {
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
use azalea::entity::LookDirection;
|
||||||
use mlua::{FromLua, IntoLua, Lua, Result, Value};
|
use mlua::{FromLua, IntoLua, Lua, Result, Value};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@ -6,6 +7,15 @@ pub struct Direction {
|
|||||||
pub y: f32,
|
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 {
|
impl IntoLua for Direction {
|
||||||
fn into_lua(self, lua: &Lua) -> Result<Value> {
|
fn into_lua(self, lua: &Lua) -> Result<Value> {
|
||||||
let table = lua.create_table()?;
|
let table = lua.create_table()?;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user