1use yog_core::Server;
9
10pub struct Entity<'a> {
12 server: &'a dyn Server,
13 uuid: String,
14}
15
16impl<'a> Entity<'a> {
17 pub fn new(server: &'a dyn Server, uuid: impl Into<String>) -> Self {
19 Self {
20 server,
21 uuid: uuid.into(),
22 }
23 }
24
25 pub fn uuid(&self) -> &str {
26 &self.uuid
27 }
28
29 pub fn teleport(&self, x: f64, y: f64, z: f64) -> bool {
31 self.server.entity_teleport(&self.uuid, x, y, z)
32 }
33
34 pub fn rotation(&self) -> Option<(f32, f32)> {
37 self.server.entity_rotation(&self.uuid)
38 }
39
40 pub fn look_vector(&self) -> Option<(f64, f64, f64)> {
42 let (yaw, pitch) = self.rotation()?;
43 let (yaw, pitch) = ((yaw as f64).to_radians(), (pitch as f64).to_radians());
44 let cos_p = pitch.cos();
45 Some((-yaw.sin() * cos_p, -pitch.sin(), yaw.cos() * cos_p))
46 }
47
48 pub fn position(&self) -> Option<(f64, f64, f64)> {
49 self.server.entity_position(&self.uuid)
50 }
51
52 pub fn health(&self) -> Option<f32> {
54 self.server.entity_health(&self.uuid)
55 }
56
57 pub fn set_health(&self, health: f32) -> bool {
59 self.server.entity_set_health(&self.uuid, health)
60 }
61
62 pub fn kill(&self) -> bool {
64 self.server.entity_kill(&self.uuid)
65 }
66
67 pub fn add_effect(
72 &self,
73 effect_id: &str,
74 duration_ticks: i32,
75 amplifier: u8,
76 show_particles: bool,
77 ) -> bool {
78 self.server.entity_add_effect(&self.uuid, effect_id, duration_ticks, amplifier, show_particles)
79 }
80
81 pub fn remove_effect(&self, effect_id: &str) -> bool {
83 self.server.entity_remove_effect(&self.uuid, effect_id)
84 }
85
86 pub fn clear_effects(&self) -> bool {
88 self.server.entity_clear_effects(&self.uuid)
89 }
90
91 pub fn velocity(&self) -> Option<(f64, f64, f64)> {
95 self.server.entity_velocity(&self.uuid)
96 }
97
98 pub fn set_velocity(&self, vx: f64, vy: f64, vz: f64) -> bool {
100 self.server.entity_set_velocity(&self.uuid, vx, vy, vz)
101 }
102
103 pub fn add_velocity(&self, vx: f64, vy: f64, vz: f64) -> bool {
105 self.server.entity_add_velocity(&self.uuid, vx, vy, vz)
106 }
107
108 pub fn get_nbt(&self) -> Option<String> {
112 self.server.entity_get_nbt(&self.uuid)
113 }
114
115 pub fn set_nbt(&self, snbt: &str) -> bool {
117 self.server.entity_set_nbt(&self.uuid, snbt)
118 }
119
120 pub fn attribute_get(&self, attribute_id: &str) -> Option<f64> {
124 self.server.entity_attribute_get(&self.uuid, attribute_id)
125 }
126
127 pub fn attribute_set(&self, attribute_id: &str, value: f64) -> bool {
129 self.server.entity_attribute_set(&self.uuid, attribute_id, value)
130 }
131}