yog_api/body.rs
1//! Bodies, camera and movement (`yog-body`, see its docs): pose and dress
2//! entities, disguise and morph them, move the camera, replace the local
3//! player's travel step. Register handlers with [`Registry::on_body`],
4//! [`Registry::on_camera`] and [`Registry::on_travel`]; say which entities
5//! to ask about with [`track`] and [`track_type`].
6//!
7//! [`Registry::on_body`]: crate::Registry::on_body
8//! [`Registry::on_camera`]: crate::Registry::on_camera
9//! [`Registry::on_travel`]: crate::Registry::on_travel
10
11pub use yog_body::*;
12use yog_event::client;
13use yog_event::entity::VANILLA_SIZE;
14
15use crate::call;
16
17/// Asks the body handlers about entity `uuid` each frame (`on`), or stops.
18pub fn track(uuid: &str, on: bool) {
19 call(&client::BodyTrack {
20 uuid: uuid.to_owned(),
21 on,
22 });
23}
24
25/// What this client was told entity `uuid` keeps under `key`
26/// (`entity::SetData`); body frames carry it too
27/// ([`Frame::data`]).
28pub fn entity_data(uuid: &str, key: &str) -> Option<Vec<u8>> {
29 call(&client::EntityData {
30 uuid: uuid.to_owned(),
31 key: key.to_owned(),
32 })
33 .flatten()
34 .map(|v| v.bytes)
35}
36
37/// This client's side of `entity::SetDimensions`: the
38/// entity's own hitbox (`Some((width, height, eye height))`, blocks) or
39/// vanilla's again. The mod sends who has which (its own packet); the local
40/// player moves and collides with it.
41pub fn set_dimensions(uuid: &str, size: Option<(f32, f32, f32)>) {
42 let [width, height, eye] = size.map_or(VANILLA_SIZE, |(w, h, e)| [w, h, e]);
43 call(&client::SetDimensions {
44 uuid: uuid.to_owned(),
45 width,
46 height,
47 eye,
48 });
49}
50
51/// Asks the body handlers about every entity of `entity_type` (`on`), or stops.
52pub fn track_type(entity_type: &str, on: bool) {
53 call(&client::BodyTrackType {
54 entity_type: entity_type.to_owned(),
55 on,
56 });
57}