diff options
Diffstat (limited to 'src/player.rs')
-rw-r--r-- | src/player.rs | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/player.rs b/src/player.rs new file mode 100644 index 0000000..7b99c16 --- /dev/null +++ b/src/player.rs @@ -0,0 +1,48 @@ +use anyhow::Result; +use mcproto_rs::types::Vec3; +use mcproto_rs::v1_19_3::{Packet761, SynchronizePlayerPositionSpec}; + +use crate::connect::MinecraftClient; + +pub struct Player { + pub client: MinecraftClient, + pub name: String, + pub position: Vec3<f64>, + pub yaw: f32, + pub pitch: f32, +} + + +impl Player { + pub fn create_teleport_packet(&self) -> Packet761 { + Packet761::SynchronizePlayerPosition(SynchronizePlayerPositionSpec { + position: self.position.clone(), + yaw: self.yaw, + pitch: self.pitch, + flags: Default::default(), + teleport_id: 0.into(), // TODO: teleport id ack + dismount_vehicle: false, + }) + } + + pub async fn teleport(&mut self, position: Vec3<f64>, yaw: f32, pitch: f32) -> Result<()> { + self.position = position; + self.yaw = yaw; + self.pitch = pitch; + self.send_packet(self.create_teleport_packet())?; + Ok(()) + } + + pub fn send_packet(&self, packet: Packet761) -> Result<()> { + self.client.send_packet(packet) + } + pub fn send_all_packets(&self, packets: Vec<Packet761>) -> Result<(), anyhow::Error> { + self.client.send_all_packets(packets) + } +} + + + + + + |