From 568f56d05e0e6d24f2c7fae943a59be370a80987 Mon Sep 17 00:00:00 2001 From: ya7on Date: Mon, 26 Feb 2024 21:09:11 +0300 Subject: [PATCH 1/3] Add Spawn Entity packet --- src/packets/client.rs | 2 ++ src/packets/client/spawn_entity.rs | 27 +++++++++++++++++++++++++++ src/packets/packet_ids.rs | 1 + 3 files changed, 30 insertions(+) create mode 100644 src/packets/client/spawn_entity.rs diff --git a/src/packets/client.rs b/src/packets/client.rs index fd42df0..7c6e873 100644 --- a/src/packets/client.rs +++ b/src/packets/client.rs @@ -8,6 +8,7 @@ mod play; mod player_abilities; mod registry_data; mod set_default_spawn_position; +mod spawn_entity; mod status_response; mod synchronize_player_position; @@ -19,5 +20,6 @@ pub use play::{DeathInfo, Play}; pub use player_abilities::PlayerAbilities; pub use registry_data::RegistryData; pub use set_default_spawn_position::SetDefaultSpawnPosition; +pub use spawn_entity::{EntityType, SpawnEntity}; pub use status_response::StatusResponse; pub use synchronize_player_position::SynchronizePlayerPosition; diff --git a/src/packets/client/spawn_entity.rs b/src/packets/client/spawn_entity.rs new file mode 100644 index 0000000..4300409 --- /dev/null +++ b/src/packets/client/spawn_entity.rs @@ -0,0 +1,27 @@ +use crate::packets::packet_ids::current_version; +use crate::types::{MCAngle, MCShort}; +use crate::types::{MCDouble, MCUuid, MCVarInt}; +use crate::{MCPacket, MCType}; + +pub enum EntityType { + Wolf = 118, + Zombie = 120, +} + +#[derive(MCPacket, Clone, Debug)] +#[packet(packet_id = current_version::play::client::SPAWN_ENTITY)] +pub struct SpawnEntity { + pub entity_id: MCVarInt, + pub entity_uuid: MCUuid, + pub entity_type: MCVarInt, + pub x: MCDouble, + pub y: MCDouble, + pub z: MCDouble, + pub pitch: MCAngle, + pub yaw: MCAngle, + pub head_yaw: MCAngle, + pub data: MCVarInt, + pub velocity_x: MCShort, + pub velocity_y: MCShort, + pub velocity_z: MCShort, +} diff --git a/src/packets/packet_ids.rs b/src/packets/packet_ids.rs index 97dd4a1..f44ada0 100644 --- a/src/packets/packet_ids.rs +++ b/src/packets/packet_ids.rs @@ -33,6 +33,7 @@ mod version_1_20_4 { } pub mod play { pub mod client { + pub const SPAWN_ENTITY: i32 = 0x01; pub const KEEP_ALIVE: i32 = 0x24; pub const CHUNK_DATA_AND_UPDATE_LIGHT: i32 = 0x25; pub const PLAY: i32 = 0x29; From b7e3175bf3ffe2541e1995d147e074922c1994ae Mon Sep 17 00:00:00 2001 From: ya7on Date: Mon, 26 Feb 2024 21:09:58 +0300 Subject: [PATCH 2/3] Add Teleport Entity packet --- src/packets/client.rs | 2 ++ src/packets/client/teleport_entity.rs | 15 +++++++++++++++ src/packets/packet_ids.rs | 1 + 3 files changed, 18 insertions(+) create mode 100644 src/packets/client/teleport_entity.rs diff --git a/src/packets/client.rs b/src/packets/client.rs index 7c6e873..6f6c1cd 100644 --- a/src/packets/client.rs +++ b/src/packets/client.rs @@ -11,6 +11,7 @@ mod set_default_spawn_position; mod spawn_entity; mod status_response; mod synchronize_player_position; +mod teleport_entity; pub use chunk_data_and_update_light::{BlockEntity, ChunkDataAndUpdateLight}; pub use finish_configuration::FinishConfigurationClientbound; @@ -23,3 +24,4 @@ pub use set_default_spawn_position::SetDefaultSpawnPosition; pub use spawn_entity::{EntityType, SpawnEntity}; pub use status_response::StatusResponse; pub use synchronize_player_position::SynchronizePlayerPosition; +pub use teleport_entity::TeleportEntity; diff --git a/src/packets/client/teleport_entity.rs b/src/packets/client/teleport_entity.rs new file mode 100644 index 0000000..9ee9df8 --- /dev/null +++ b/src/packets/client/teleport_entity.rs @@ -0,0 +1,15 @@ +use crate::packets::packet_ids::current_version; +use crate::types::{MCAngle, MCBoolean, MCDouble, MCVarInt}; +use crate::{MCPacket, MCType}; + +#[derive(MCPacket, Debug, Clone)] +#[packet(packet_id = current_version::play::client::TELEPORT_ENTITY)] +pub struct TeleportEntity { + pub entity_id: MCVarInt, + pub x: MCDouble, + pub y: MCDouble, + pub z: MCDouble, + pub yaw: MCAngle, + pub pitch: MCAngle, + pub on_ground: MCBoolean, +} diff --git a/src/packets/packet_ids.rs b/src/packets/packet_ids.rs index f44ada0..9361e40 100644 --- a/src/packets/packet_ids.rs +++ b/src/packets/packet_ids.rs @@ -40,6 +40,7 @@ mod version_1_20_4 { pub const PLAYER_ABILITIES: i32 = 0x36; pub const SET_DEFAULT_SPAWN_POSITION: i32 = 0x54; pub const SYNCHRONIZE_PLAYER_POSITION: i32 = 0x3E; + pub const TELEPORT_ENTITY: i32 = 0x6D; } pub mod server { pub const KEEP_ALIVE: i32 = 0x15; From 18f30e6b2c4bd0b65fe84daaa0ad55a3fe4eeeb4 Mon Sep 17 00:00:00 2001 From: ya7on Date: Mon, 26 Feb 2024 21:10:21 +0300 Subject: [PATCH 3/3] Add Update Entity Position packet --- src/packets/client.rs | 2 ++ src/packets/client/update_entity_position.rs | 13 +++++++++++++ src/packets/packet_ids.rs | 1 + 3 files changed, 16 insertions(+) create mode 100644 src/packets/client/update_entity_position.rs diff --git a/src/packets/client.rs b/src/packets/client.rs index 6f6c1cd..5764e6f 100644 --- a/src/packets/client.rs +++ b/src/packets/client.rs @@ -12,6 +12,7 @@ mod spawn_entity; mod status_response; mod synchronize_player_position; mod teleport_entity; +mod update_entity_position; pub use chunk_data_and_update_light::{BlockEntity, ChunkDataAndUpdateLight}; pub use finish_configuration::FinishConfigurationClientbound; @@ -25,3 +26,4 @@ pub use spawn_entity::{EntityType, SpawnEntity}; pub use status_response::StatusResponse; pub use synchronize_player_position::SynchronizePlayerPosition; pub use teleport_entity::TeleportEntity; +pub use update_entity_position::UpdateEntityPosition; diff --git a/src/packets/client/update_entity_position.rs b/src/packets/client/update_entity_position.rs new file mode 100644 index 0000000..4fa6f08 --- /dev/null +++ b/src/packets/client/update_entity_position.rs @@ -0,0 +1,13 @@ +use crate::packets::packet_ids::current_version; +use crate::types::{MCBoolean, MCShort, MCVarInt}; +use crate::{MCPacket, MCType}; + +#[derive(MCPacket, Debug, Clone)] +#[packet(packet_id = current_version::play::client::UPDATE_ENTITY_POSITION)] +pub struct UpdateEntityPosition { + pub entity_id: MCVarInt, + pub delta_x: MCShort, + pub delta_y: MCShort, + pub delta_z: MCShort, + pub on_ground: MCBoolean, +} diff --git a/src/packets/packet_ids.rs b/src/packets/packet_ids.rs index 9361e40..69a1ba9 100644 --- a/src/packets/packet_ids.rs +++ b/src/packets/packet_ids.rs @@ -40,6 +40,7 @@ mod version_1_20_4 { pub const PLAYER_ABILITIES: i32 = 0x36; pub const SET_DEFAULT_SPAWN_POSITION: i32 = 0x54; pub const SYNCHRONIZE_PLAYER_POSITION: i32 = 0x3E; + pub const UPDATE_ENTITY_POSITION: i32 = 0x2C; pub const TELEPORT_ENTITY: i32 = 0x6D; } pub mod server {