refactor: impl From for Vec3

This commit is contained in:
2025-02-21 22:09:58 -05:00
parent 6f0f3938a7
commit ea7a370715
3 changed files with 41 additions and 45 deletions

View File

@@ -1,3 +1,4 @@
use azalea::{BlockPos, entity::Position};
use mlua::{FromLua, IntoLua, Lua, Result, Value};
#[derive(Clone)]
@@ -17,6 +18,36 @@ impl IntoLua for Vec3 {
}
}
impl From<azalea::Vec3> for Vec3 {
fn from(v: azalea::Vec3) -> Self {
Self {
x: v.x,
y: v.y,
z: v.z,
}
}
}
impl From<&Position> for Vec3 {
fn from(p: &Position) -> Self {
Self {
x: p.x,
y: p.y,
z: p.z,
}
}
}
impl From<BlockPos> for Vec3 {
fn from(p: BlockPos) -> Self {
Vec3 {
x: f64::from(p.x),
y: f64::from(p.y),
z: f64::from(p.z),
}
}
}
impl FromLua for Vec3 {
fn from_lua(value: Value, _lua: &Lua) -> Result<Self> {
match value {