Skip to main content

yog_event/entity/
data.rs

1//! What mods keep on entities, and their sizes: services the runtime
2//! provides (it keeps the data and syncs it to the clients that see them).
3
4use yog_data::Schema;
5use yog_data::with::Raw;
6
7/// Bytes a mod keeps on an entity under a key.
8#[derive(Debug, Clone, PartialEq, Schema)]
9pub struct DataValue {
10    #[data(with = "Raw")]
11    pub bytes: Vec<u8>,
12}
13
14/// What the entity keeps under `key`.
15#[derive(Debug, Clone, Schema)]
16pub struct Data {
17    pub uuid: String,
18    pub key: String,
19}
20
21/// Keeps `value` under `key` (`None` forgets it), synced to the clients
22/// that see the entity; `persist` saves it with the entity.
23#[derive(Debug, Clone, Schema)]
24pub struct SetData {
25    pub uuid: String,
26    pub key: String,
27    pub value: Option<DataValue>,
28    pub persist: bool,
29}
30
31/// What the host reads as "vanilla's size again": a negative width.
32pub const VANILLA_SIZE: [f32; 3] = [-1.0, 0.0, 0.0];
33
34/// The entity's size, `[width, height, eye height]` — `None`: vanilla's —
35/// on the server and on every client that sees it.
36#[derive(Debug, Clone, Schema)]
37pub struct SetDimensions {
38    pub uuid: String,
39    pub size: Option<[f32; 3]>,
40}
41
42/// How a hanging entity hangs: on which side, how big, and the item it was
43/// placed from (what it drops) — its entity data `yog:hanging`
44/// (`yog_ids::yog::HANGING`), which the host keeps up to date.
45#[derive(Debug, Clone, PartialEq, Eq, Schema)]
46pub struct Hanging {
47    /// The way it faces, out of its wall: `north`, `south`, `west`, `east`.
48    pub facing: String,
49    /// Whole blocks of wall, wide and high.
50    pub width: u32,
51    pub height: u32,
52    /// The item it keeps: its id and custom data (SNBT, `{}` for none).
53    pub item: String,
54    pub nbt: String,
55}