yog_event/planes/living/entity/
data.rs1use yog_data::Schema;
5use yog_data::with::Raw;
6
7use crate::Arg;
8
9#[derive(Debug, Clone, PartialEq, Schema)]
11pub struct DataValue {
12 #[data(with = "Raw")]
13 pub bytes: Vec<u8>,
14}
15
16#[derive(Debug, Clone, Schema)]
18pub struct Data {
19 pub uuid: String,
20 pub key: String,
21}
22
23#[derive(Debug, Clone, Schema)]
26pub struct SetData {
27 pub uuid: String,
28 pub key: String,
29 pub value: Option<DataValue>,
30 pub persist: bool,
31}
32
33pub fn data(uuid: impl Arg<String>, key: impl Arg<String>) -> Option<Vec<u8>> {
35 crate::call(&Data {
36 uuid: uuid.arg(),
37 key: key.arg(),
38 })
39 .flatten()
40 .map(|v| v.bytes)
41}
42
43pub fn set_data(
46 uuid: impl Arg<String>,
47 key: impl Arg<String>,
48 value: Option<&[u8]>,
49 persist: bool,
50) -> bool {
51 let value = value.map(|bytes| DataValue {
52 bytes: bytes.to_vec(),
53 });
54 let set = SetData {
55 uuid: uuid.arg(),
56 key: key.arg(),
57 value,
58 persist,
59 };
60 crate::call(&set).unwrap_or_default()
61}
62
63pub fn set_dimensions(uuid: impl Arg<String>, size: Option<[f32; 3]>) -> bool {
66 crate::call(&SetDimensions {
67 uuid: uuid.arg(),
68 size,
69 })
70 .unwrap_or_default()
71}
72
73pub const VANILLA_SIZE: [f32; 3] = [-1.0, 0.0, 0.0];
75
76#[derive(Debug, Clone, Schema)]
79pub struct SetDimensions {
80 pub uuid: String,
81 pub size: Option<[f32; 3]>,
82}
83
84#[derive(Debug, Clone, PartialEq, Eq, Schema)]
88pub struct Hanging {
89 pub facing: String,
91 pub width: u32,
93 pub height: u32,
94 pub item: String,
96 pub nbt: String,
97}