use yog_data::Schema;
use yog_data::with::Raw;
use crate::Arg;
#[derive(Debug, Clone, PartialEq, Schema)]
pub struct DataValue {
#[data(with = "Raw")]
pub bytes: Vec<u8>,
}
#[derive(Debug, Clone, Schema)]
pub struct Data {
pub uuid: String,
pub key: String,
}
#[derive(Debug, Clone, Schema)]
pub struct SetData {
pub uuid: String,
pub key: String,
pub value: Option<DataValue>,
pub persist: bool,
}
pub fn data(uuid: impl Arg<String>, key: impl Arg<String>) -> Option<Vec<u8>> {
crate::call(&Data {
uuid: uuid.arg(),
key: key.arg(),
})
.flatten()
.map(|v| v.bytes)
}
pub fn set_data(
uuid: impl Arg<String>,
key: impl Arg<String>,
value: Option<&[u8]>,
persist: bool,
) -> bool {
let value = value.map(|bytes| DataValue {
bytes: bytes.to_vec(),
});
let set = SetData {
uuid: uuid.arg(),
key: key.arg(),
value,
persist,
};
crate::call(&set).unwrap_or_default()
}
pub fn set_dimensions(uuid: impl Arg<String>, size: Option<[f32; 3]>) -> bool {
crate::call(&SetDimensions {
uuid: uuid.arg(),
size,
})
.unwrap_or_default()
}
pub const VANILLA_SIZE: [f32; 3] = [-1.0, 0.0, 0.0];
#[derive(Debug, Clone, Schema)]
pub struct SetDimensions {
pub uuid: String,
pub size: Option<[f32; 3]>,
}
#[derive(Debug, Clone, PartialEq, Eq, Schema)]
pub struct Hanging {
pub facing: String,
pub width: u32,
pub height: u32,
pub item: String,
pub nbt: String,
}