PatchBukkit/rust/src/java/native_callbacks/location.rs
2026-01-31 12:50:51 -07:00

39 lines
1.1 KiB
Rust

use std::ffi::c_char;
use pumpkin::command::args::entities::{EntitySelectorType, TargetSelector};
use crate::java::native_callbacks::{CALLBACK_CONTEXT, utils::get_string};
#[repr(C)]
pub struct Vec3FFI {
pub x: f64,
pub y: f64,
pub z: f64,
}
pub extern "C" fn rust_get_location(uuid_ptr: *const c_char, out: *mut Vec3FFI) -> bool {
let uuid_str = get_string(uuid_ptr);
if let Some(ctx) = CALLBACK_CONTEXT.get() {
let uuid = uuid::Uuid::parse_str(&uuid_str).unwrap();
let entity = ctx
.plugin_context
.server
.select_entities(&TargetSelector::new(EntitySelectorType::Uuid(uuid)), None);
if entity.len() == 1 {
let entity = entity.first().unwrap().get_entity();
let position =
tokio::task::block_in_place(|| ctx.runtime.block_on(async { entity.pos.load() }));
unsafe {
(*out).x = position.x;
(*out).y = position.y;
(*out).z = position.z;
}
return true;
}
}
false
}