aboutsummaryrefslogtreecommitdiff
path: root/azalea-protocol
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2022-06-25 05:09:26 +0000
committerGitHub <noreply@github.com>2022-06-25 05:09:26 +0000
commit7d3e57763e32ac9cf94180b1c714704cfbc3034d (patch)
tree2dcfe72bf09a42f6614f9dc988dc0254162ea0bf /azalea-protocol
parent69c47eda4c496b13dadd80976bffd2fab7ea5894 (diff)
parentca7067e173129f3044ebc8c77634f06da29a086e (diff)
downloadazalea-drasl-7d3e57763e32ac9cf94180b1c714704cfbc3034d.tar.xz
Merge pull request #10 from mat-1/azalea-entity
azalea-entity
Diffstat (limited to 'azalea-protocol')
-rwxr-xr-xazalea-protocol/Cargo.toml21
-rwxr-xr-xazalea-protocol/packet-macros/src/lib.rs181
-rwxr-xr-xazalea-protocol/src/lib.rs7
-rw-r--r--azalea-protocol/src/mc_buf/definitions.rs442
-rw-r--r--azalea-protocol/src/mc_buf/mod.rs233
-rw-r--r--azalea-protocol/src/mc_buf/read.rs525
-rw-r--r--azalea-protocol/src/mc_buf/write.rs430
-rw-r--r--azalea-protocol/src/packets/game/clientbound_add_entity_packet.rs19
-rw-r--r--azalea-protocol/src/packets/game/clientbound_add_player_packet.rs22
-rw-r--r--azalea-protocol/src/packets/game/clientbound_animate_packet.rs3
-rw-r--r--azalea-protocol/src/packets/game/clientbound_block_changed_ack_packet.rs3
-rw-r--r--azalea-protocol/src/packets/game/clientbound_block_update_packet.rs3
-rwxr-xr-xazalea-protocol/src/packets/game/clientbound_change_difficulty_packet.rs5
-rw-r--r--azalea-protocol/src/packets/game/clientbound_chat_preview_packet.rs3
-rw-r--r--azalea-protocol/src/packets/game/clientbound_container_set_content_packet.rs3
-rwxr-xr-xazalea-protocol/src/packets/game/clientbound_custom_payload_packet.rs7
-rwxr-xr-xazalea-protocol/src/packets/game/clientbound_declare_commands_packet.rs15
-rw-r--r--azalea-protocol/src/packets/game/clientbound_disconnect_packet.rs3
-rw-r--r--azalea-protocol/src/packets/game/clientbound_entity_event_packet.rs3
-rw-r--r--azalea-protocol/src/packets/game/clientbound_entity_velocity_packet.rs3
-rw-r--r--azalea-protocol/src/packets/game/clientbound_game_event_packet.rs3
-rw-r--r--azalea-protocol/src/packets/game/clientbound_initialize_border_packet.rs3
-rw-r--r--azalea-protocol/src/packets/game/clientbound_keep_alive_packet.rs3
-rw-r--r--azalea-protocol/src/packets/game/clientbound_level_chunk_with_light_packet.rs3
-rw-r--r--azalea-protocol/src/packets/game/clientbound_level_event_packet.rs3
-rw-r--r--azalea-protocol/src/packets/game/clientbound_level_particles_packet.rs4
-rw-r--r--azalea-protocol/src/packets/game/clientbound_light_update_packet.rs5
-rwxr-xr-xazalea-protocol/src/packets/game/clientbound_login_packet.rs7
-rw-r--r--azalea-protocol/src/packets/game/clientbound_move_entity_pos_packet.rs10
-rw-r--r--azalea-protocol/src/packets/game/clientbound_move_entity_posrot_packet.rs11
-rw-r--r--azalea-protocol/src/packets/game/clientbound_move_entity_rot_packet.rs3
-rwxr-xr-xazalea-protocol/src/packets/game/clientbound_player_abilities_packet.rs5
-rw-r--r--azalea-protocol/src/packets/game/clientbound_player_chat_packet.rs3
-rw-r--r--azalea-protocol/src/packets/game/clientbound_player_info_packet.rs5
-rw-r--r--azalea-protocol/src/packets/game/clientbound_player_position_packet.rs7
-rw-r--r--azalea-protocol/src/packets/game/clientbound_recipe_packet.rs7
-rw-r--r--azalea-protocol/src/packets/game/clientbound_remove_entities_packet.rs3
-rw-r--r--azalea-protocol/src/packets/game/clientbound_rotate_head_packet.rs3
-rw-r--r--azalea-protocol/src/packets/game/clientbound_section_blocks_update_packet.rs5
-rw-r--r--azalea-protocol/src/packets/game/clientbound_server_data_packet.rs3
-rwxr-xr-xazalea-protocol/src/packets/game/clientbound_set_carried_item_packet.rs3
-rw-r--r--azalea-protocol/src/packets/game/clientbound_set_chunk_cache_center_packet.rs3
-rw-r--r--azalea-protocol/src/packets/game/clientbound_set_default_spawn_position_packet.rs3
-rw-r--r--azalea-protocol/src/packets/game/clientbound_set_display_chat_preview_packet.rs3
-rw-r--r--azalea-protocol/src/packets/game/clientbound_set_entity_data_packet.rs7
-rw-r--r--azalea-protocol/src/packets/game/clientbound_set_entity_link_packet.rs3
-rw-r--r--azalea-protocol/src/packets/game/clientbound_set_equipment_packet.rs5
-rw-r--r--azalea-protocol/src/packets/game/clientbound_set_experience_packet.rs3
-rw-r--r--azalea-protocol/src/packets/game/clientbound_set_health_packet.rs3
-rw-r--r--azalea-protocol/src/packets/game/clientbound_set_time_packet.rs3
-rw-r--r--azalea-protocol/src/packets/game/clientbound_sound_packet.rs3
-rw-r--r--azalea-protocol/src/packets/game/clientbound_system_chat_packet.rs3
-rw-r--r--azalea-protocol/src/packets/game/clientbound_teleport_entity_packet.rs3
-rw-r--r--azalea-protocol/src/packets/game/clientbound_update_advancements_packet.rs6
-rw-r--r--azalea-protocol/src/packets/game/clientbound_update_attributes_packet.rs7
-rw-r--r--azalea-protocol/src/packets/game/clientbound_update_mob_effect_packet.rs16
-rw-r--r--azalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs11
-rwxr-xr-xazalea-protocol/src/packets/game/clientbound_update_tags_packet.rs33
-rwxr-xr-xazalea-protocol/src/packets/game/clientbound_update_view_distance_packet.rs3
-rwxr-xr-xazalea-protocol/src/packets/game/mod.rs14
-rw-r--r--azalea-protocol/src/packets/game/serverbound_accept_teleportation_packet.rs8
-rw-r--r--azalea-protocol/src/packets/game/serverbound_chat_command_packet.rs3
-rw-r--r--azalea-protocol/src/packets/game/serverbound_chat_preview_packet.rs3
-rw-r--r--azalea-protocol/src/packets/game/serverbound_custom_payload_packet.rs7
-rw-r--r--azalea-protocol/src/packets/game/serverbound_keep_alive_packet.rs3
-rw-r--r--azalea-protocol/src/packets/game/serverbound_move_player_packet_pos.rs10
-rw-r--r--azalea-protocol/src/packets/game/serverbound_move_player_packet_pos_rot.rs12
-rw-r--r--azalea-protocol/src/packets/game/serverbound_move_player_packet_rot.rs9
-rw-r--r--azalea-protocol/src/packets/game/serverbound_move_player_packet_status_only.rs7
-rwxr-xr-xazalea-protocol/src/packets/handshake/client_intention_packet.rs3
-rwxr-xr-xazalea-protocol/src/packets/login/clientbound_custom_query_packet.rs6
-rwxr-xr-xazalea-protocol/src/packets/login/clientbound_game_profile_packet.rs4
-rwxr-xr-xazalea-protocol/src/packets/login/clientbound_hello_packet.rs2
-rwxr-xr-xazalea-protocol/src/packets/login/clientbound_login_compression_packet.rs2
-rw-r--r--azalea-protocol/src/packets/login/clientbound_login_disconnect_packet.rs3
-rwxr-xr-xazalea-protocol/src/packets/login/serverbound_hello_packet.rs3
-rw-r--r--azalea-protocol/src/packets/login/serverbound_key_packet.rs5
-rwxr-xr-xazalea-protocol/src/packets/mod.rs11
-rwxr-xr-xazalea-protocol/src/packets/status/clientbound_status_response_packet.rs2
-rwxr-xr-xazalea-protocol/src/packets/status/serverbound_status_request_packet.rs3
-rwxr-xr-xazalea-protocol/src/read.rs7
-rwxr-xr-xazalea-protocol/src/write.rs3
82 files changed, 325 insertions, 1953 deletions
diff --git a/azalea-protocol/Cargo.toml b/azalea-protocol/Cargo.toml
index e49088bc..17884a51 100755
--- a/azalea-protocol/Cargo.toml
+++ b/azalea-protocol/Cargo.toml
@@ -6,13 +6,15 @@ version = "0.1.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
-async-compression = {version = "^0.3.8", features = ["tokio", "zlib"]}
-async-recursion = "^1.0.0"
+async-compression = {version = "^0.3.8", features = ["tokio", "zlib"], optional = true}
+async-recursion = "1.0.0"
azalea-auth = {path = "../azalea-auth"}
azalea-brigadier = {path = "../azalea-brigadier"}
+azalea-buf = {path = "../azalea-buf"}
azalea-chat = {path = "../azalea-chat"}
-azalea-core = {path = "../azalea-core"}
+azalea-core = {path = "../azalea-core", optional = true}
azalea-crypto = {path = "../azalea-crypto"}
+azalea-entity = {path = "../azalea-entity"}
azalea-nbt = {path = "../azalea-nbt"}
byteorder = "^1.4.3"
bytes = "^1.1.0"
@@ -20,6 +22,13 @@ flate2 = "1.0.23"
packet-macros = {path = "./packet-macros"}
serde = {version = "1.0.130", features = ["serde_derive"]}
serde_json = "^1.0.72"
-tokio = {version = "1.19.2", features = ["io-util", "net", "macros"]}
-trust-dns-resolver = {version = "^0.21.2"}
-uuid = "^1.1.2"
+thiserror = "^1.0.30"
+tokio = {version = "^1.19.2", features = ["io-util", "net", "macros"]}
+tokio-util = "^0.6.9"
+trust-dns-resolver = "^0.20.3"
+uuid = "1.1.2"
+
+[features]
+connecting = []
+default = ["packets"]
+packets = ["connecting", "dep:async-compression", "dep:azalea-core"]
diff --git a/azalea-protocol/packet-macros/src/lib.rs b/azalea-protocol/packet-macros/src/lib.rs
index 5ea69a62..58487cdd 100755
--- a/azalea-protocol/packet-macros/src/lib.rs
+++ b/azalea-protocol/packet-macros/src/lib.rs
@@ -6,180 +6,6 @@ use syn::{
parse_macro_input, Data, DeriveInput, FieldsNamed, Ident, LitInt, Token,
};
-fn create_impl_mcbufreadable(ident: &Ident, data: &Data) -> proc_macro2::TokenStream {
- match data {
- syn::Data::Struct(syn::DataStruct { fields, .. }) => {
- let FieldsNamed { named, .. } = match fields {
- syn::Fields::Named(f) => f,
- _ => panic!("#[derive(*Packet)] can only be used on structs with named fields"),
- };
-
- let read_fields = named
- .iter()
- .map(|f| {
- let field_name = &f.ident;
- let field_type = &f.ty;
- // do a different buf.write_* for each field depending on the type
- // if it's a string, use buf.write_string
- match field_type {
- syn::Type::Path(_) => {
- if f.attrs.iter().any(|a| a.path.is_ident("var")) {
- quote! {
- let #field_name = crate::mc_buf::McBufVarReadable::var_read_into(buf)?;
- }
- } else {
- quote! {
- let #field_name = crate::mc_buf::McBufReadable::read_into(buf)?;
- }
- }
- }
- _ => panic!(
- "Error reading field {}: {}",
- field_name.clone().unwrap(),
- field_type.to_token_stream()
- ),
- }
- })
- .collect::<Vec<_>>();
- let read_field_names = named.iter().map(|f| &f.ident).collect::<Vec<_>>();
-
- quote! {
- impl crate::mc_buf::McBufReadable for #ident {
- fn read_into(buf: &mut impl std::io::Read) -> Result<Self, String> {
- #(#read_fields)*
- Ok(#ident {
- #(#read_field_names: #read_field_names),*
- })
- }
- }
- }
- }
- syn::Data::Enum(syn::DataEnum { variants, .. }) => {
- let mut match_contents = quote!();
- let mut variant_discrim: u32 = 0;
- for variant in variants {
- let variant_name = &variant.ident;
- match &variant.discriminant.as_ref() {
- Some(d) => {
- variant_discrim = match &d.1 {
- syn::Expr::Lit(e) => match &e.lit {
- syn::Lit::Int(i) => i.base10_parse().unwrap(),
- _ => panic!("Error parsing enum discriminant"),
- },
- _ => panic!("Error parsing enum discriminant"),
- }
- }
- None => {
- variant_discrim += 1;
- }
- }
- match_contents.extend(quote! {
- #variant_discrim => Ok(Self::#variant_name),
- });
- }
-
- quote! {
- impl crate::mc_buf::McBufReadable for #ident {
- fn read_into(buf: &mut impl std::io::Read) -> Result<Self, String>
- {
- let id = crate::mc_buf::McBufVarReadable::var_read_into(buf)?;
- match id {
- #match_contents
- _ => Err(format!("Unknown enum variant {}", id)),
- }
- }
- }
- }
- }
- _ => panic!("#[derive(*Packet)] can only be used on structs"),
- }
-}
-
-fn create_impl_mcbufwritable(ident: &Ident, data: &Data) -> proc_macro2::TokenStream {
- match data {
- syn::Data::Struct(syn::DataStruct { fields, .. }) => {
- let FieldsNamed { named, .. } = match fields {
- syn::Fields::Named(f) => f,
- _ => panic!("#[derive(*Packet)] can only be used on structs with named fields"),
- };
-
- let write_fields = named
- .iter()
- .map(|f| {
- let field_name = &f.ident;
- let field_type = &f.ty;
- // do a different buf.write_* for each field depending on the type
- // if it's a string, use buf.write_string
- match field_type {
- syn::Type::Path(_) => {
- if f.attrs.iter().any(|attr| attr.path.is_ident("var")) {
- quote! {
- crate::mc_buf::McBufVarWritable::var_write_into(&self.#field_name, buf)?;
- }
- } else {
- quote! {
- crate::mc_buf::McBufWritable::write_into(&self.#field_name, buf)?;
- }
- }
- }
- _ => panic!(
- "Error writing field {}: {}",
- field_name.clone().unwrap(),
- field_type.to_token_stream()
- ),
- }
- })
- .collect::<Vec<_>>();
-
- quote! {
- impl crate::mc_buf::McBufWritable for #ident {
- fn write_into(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> {
- #(#write_fields)*
- Ok(())
- }
- }
- }
- }
- syn::Data::Enum(syn::DataEnum { .. }) => {
- quote! {
- impl crate::mc_buf::McBufWritable for #ident {
- fn write_into(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> {
- crate::mc_buf::Writable::write_varint(buf, *self as i32)
- }
- }
- }
- }
- _ => panic!("#[derive(*Packet)] can only be used on structs"),
- }
-}
-
-#[proc_macro_derive(McBufReadable, attributes(var))]
-pub fn derive_mcbufreadable(input: TokenStream) -> TokenStream {
- let DeriveInput { ident, data, .. } = parse_macro_input!(input);
-
- create_impl_mcbufreadable(&ident, &data).into()
-}
-
-#[proc_macro_derive(McBufWritable, attributes(var))]
-pub fn derive_mcbufwritable(input: TokenStream) -> TokenStream {
- let DeriveInput { ident, data, .. } = parse_macro_input!(input);
-
- create_impl_mcbufwritable(&ident, &data).into()
-}
-
-#[proc_macro_derive(McBuf, attributes(var))]
-pub fn derive_mcbuf(input: TokenStream) -> TokenStream {
- let DeriveInput { ident, data, .. } = parse_macro_input!(input);
-
- let writable = create_impl_mcbufwritable(&ident, &data);
- let readable = create_impl_mcbufreadable(&ident, &data);
- quote! {
- #writable
- #readable
- }
- .into()
-}
-
fn as_packet_derive(input: TokenStream, state: proc_macro2::TokenStream) -> TokenStream {
let DeriveInput { ident, data, .. } = parse_macro_input!(input);
@@ -192,9 +18,6 @@ fn as_packet_derive(input: TokenStream, state: proc_macro2::TokenStream) -> Toke
_ => panic!("#[derive(*Packet)] can only be used on structs with named fields"),
};
- let _mcbufreadable_impl = create_impl_mcbufreadable(&ident, &data);
- let _mcbufwritable_impl = create_impl_mcbufwritable(&ident, &data);
-
let contents = quote! {
impl #ident {
pub fn get(self) -> #state {
@@ -202,13 +25,13 @@ fn as_packet_derive(input: TokenStream, state: proc_macro2::TokenStream) -> Toke
}
pub fn write(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> {
- crate::mc_buf::McBufWritable::write_into(self, buf)
+ azalea_buf::McBufWritable::write_into(self, buf)
}
pub fn read(
buf: &mut impl std::io::Read,
) -> Result<#state, String> {
- use crate::mc_buf::McBufReadable;
+ use azalea_buf::McBufReadable;
Ok(Self::read_into(buf)?.get())
}
}
diff --git a/azalea-protocol/src/lib.rs b/azalea-protocol/src/lib.rs
index d7f75f00..b1d1a9c4 100755
--- a/azalea-protocol/src/lib.rs
+++ b/azalea-protocol/src/lib.rs
@@ -1,13 +1,11 @@
//! This lib is responsible for parsing Minecraft packets.
-#![feature(min_specialization)]
-#![feature(arbitrary_enum_discriminant)]
-
use std::net::IpAddr;
use std::str::FromStr;
+#[cfg(feature = "connecting")]
pub mod connect;
-pub mod mc_buf;
+#[cfg(feature = "packets")]
pub mod packets;
pub mod read;
pub mod resolver;
@@ -43,6 +41,7 @@ impl<'a> TryFrom<&'a str> for ServerAddress {
}
}
+#[cfg(feature = "connecting")]
pub async fn connect(address: ServerAddress) -> Result<(), Box<dyn std::error::Error>> {
let resolved_address = resolver::resolve_address(&address).await;
println!("Resolved address: {:?}", resolved_address);
diff --git a/azalea-protocol/src/mc_buf/definitions.rs b/azalea-protocol/src/mc_buf/definitions.rs
deleted file mode 100644
index 3867b3fc..00000000
--- a/azalea-protocol/src/mc_buf/definitions.rs
+++ /dev/null
@@ -1,442 +0,0 @@
-use crate::mc_buf::read::{McBufReadable, Readable};
-use crate::mc_buf::write::{McBufWritable, Writable};
-use crate::mc_buf::McBufVarReadable;
-use azalea_chat::component::Component;
-use azalea_core::{BlockPos, Direction, Slot};
-use packet_macros::McBuf;
-use std::io::{Read, Write};
-use std::ops::Deref;
-use uuid::Uuid;
-
-/// A Vec<u8> that isn't prefixed by a VarInt with the size.
-#[derive(Debug, Clone, PartialEq, Eq, Hash)]
-pub struct UnsizedByteArray(Vec<u8>);
-
-impl Deref for UnsizedByteArray {
- type Target = Vec<u8>;
-
- fn deref(&self) -> &Self::Target {
- &self.0
- }
-}
-
-impl From<Vec<u8>> for UnsizedByteArray {
- fn from(vec: Vec<u8>) -> Self {
- Self(vec)
- }
-}
-
-impl From<&str> for UnsizedByteArray {
- fn from(s: &str) -> Self {
- Self(s.as_bytes().to_vec())
- }
-}
-
-/// Represents Java's BitSet, a list of bits.
-#[derive(Debug, Clone, PartialEq, Eq, Hash, McBuf)]
-pub struct BitSet {
- data: Vec<u64>,
-}
-
-// the Index trait requires us to return a reference, but we can't do that
-impl BitSet {
- pub fn index(&self, index: usize) -> bool {
- (self.data[index / 64] & (1u64 << (index % 64))) != 0
- }
-}
-
-pub type EntityMetadata = Vec<EntityDataItem>;
-
-#[derive(Clone, Debug)]
-pub struct EntityDataItem {
- // we can't identify what the index is for here because we don't know the
- // entity type
- pub index: u8,
- pub value: EntityDataValue,
-}
-
-impl McBufReadable for Vec<EntityDataItem> {
- fn read_into(buf: &mut impl Read) -> Result<Self, String> {
- let mut metadata = Vec::new();
- loop {
- let index = buf.read_byte()?;
- if index == 0xff {
- break;
- }
- let value = EntityDataValue::read_into(buf)?;
- metadata.push(EntityDataItem { index, value });
- }
- Ok(metadata)
- }
-}
-
-impl McBufWritable for Vec<EntityDataItem> {
- fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
- for item in self {
- buf.write_byte(item.index)?;
- item.value.write_into(buf)?;
- }
- buf.write_byte(0xff)?;
- Ok(())
- }
-}
-
-#[derive(Clone, Debug)]
-pub enum EntityDataValue {
- Byte(u8),
- // varint
- Int(i32),
- Float(f32),
- String(String),
- Component(Component),
- OptionalComponent(Option<Component>),
- ItemStack(Slot),
- Boolean(bool),
- Rotations { x: f32, y: f32, z: f32 },
- BlockPos(BlockPos),
- OptionalBlockPos(Option<BlockPos>),
- Direction(Direction),
- OptionalUuid(Option<Uuid>),
- // 0 for absent (implies air); otherwise, a block state ID as per the global palette
- // this is a varint
- OptionalBlockState(Option<i32>),
- CompoundTag(azalea_nbt::Tag),
- Particle(Particle),
- VillagerData(VillagerData),
- // 0 for absent; 1 + actual value otherwise. Used for entity IDs.
- OptionalUnsignedInt(Option<u32>),
- Pose(Pose),
-}
-
-impl McBufReadable for EntityDataValue {
- fn read_into(buf: &mut impl Read) -> Result<Self, String> {
- let type_ = buf.read_varint()?;
- Ok(match type_ {
- 0 => EntityDataValue::Byte(buf.read_byte()?),
- 1 => EntityDataValue::Int(buf.read_varint()?),
- 2 => EntityDataValue::Float(buf.read_float()?),
- 3 => EntityDataValue::String(buf.read_utf()?),
- 4 => EntityDataValue::Component(Component::read_into(buf)?),
- 5 => EntityDataValue::OptionalComponent(Option::<Component>::read_into(buf)?),
- 6 => EntityDataValue::ItemStack(Slot::read_into(buf)?),
- 7 => EntityDataValue::Boolean(buf.read_boolean()?),
- 8 => EntityDataValue::Rotations {
- x: buf.read_float()?,
- y: buf.read_float()?,
- z: buf.read_float()?,
- },
- 9 => EntityDataValue::BlockPos(BlockPos::read_into(buf)?),
- 10 => EntityDataValue::OptionalBlockPos(Option::<BlockPos>::read_into(buf)?),
- 11 => EntityDataValue::Direction(Direction::read_into(buf)?),
- 12 => EntityDataValue::OptionalUuid(Option::<Uuid>::read_into(buf)?),
- 13 => EntityDataValue::OptionalBlockState({
- let val = i32::read_into(buf)?;
- if val == 0 {
- None
- } else {
- Some(val)
- }
- }),
- 14 => EntityDataValue::CompoundTag(azalea_nbt::Tag::read_into(buf)?),
- 15 => EntityDataValue::Particle(Particle::read_into(buf)?),
- 16 => EntityDataValue::VillagerData(VillagerData::read_into(buf)?),
- 17 => EntityDataValue::OptionalUnsignedInt({
- let val = buf.read_varint()?;
- if val == 0 {
- None
- } else {
- Some((val - 1) as u32)
- }
- }),
- 18 => EntityDataValue::Pose(Pose::read_into(buf)?),
- _ => return Err(format!("Unknown entity data type: {}", type_)),
- })
- }
-}
-
-impl McBufWritable for EntityDataValue {
- fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
- todo!();
- }
-}
-
-#[derive(Clone, Debug, Copy, McBuf)]
-pub enum Pose {
- Standing = 0,
- FallFlying = 1,
- Sleeping = 2,
- Swimming = 3,
- SpinAttack = 4,
- Sneaking = 5,
- LongJumping = 6,
- Dying = 7,
-}
-
-#[derive(Debug, Clone, McBuf)]
-pub struct VillagerData {
- #[var]
- type_: u32,
- #[var]
- profession: u32,
- #[var]
- level: u32,
-}
-
-#[derive(Debug, Clone, McBuf)]
-pub struct Particle {
- #[var]
- pub id: i32,
- pub data: ParticleData,
-}
-
-#[derive(Clone, Debug)]
-pub enum ParticleData {
- AmbientEntityEffect,
- AngryVillager,
- Block(BlockParticle),
- BlockMarker(BlockParticle),
- Bubble,
- Cloud,
- Crit,
- DamageIndicator,
- DragonBreath,
- DrippingLava,
- FallingLava,
- LandingLava,
- DrippingWater,
- FallingWater,
- Dust(DustParticle),
- DustColorTransition(DustColorTransitionParticle),
- Effect,
- ElderGuardian,
- EnchantedHit,
- Enchant,
- EndRod,
- EntityEffect,
- ExplosionEmitter,
- Explosion,
- FallingDust(BlockParticle),
- Firework,
- Fishing,
- Flame,
- SoulFireFlame,
- Soul,
- Flash,
- HappyVillager,
- Composter,
- Heart,
- InstantEffect,
- Item(ItemParticle),
- Vibration(VibrationParticle),
- ItemSlime,
- ItemSnowball,
- LargeSmoke,
- Lava,
- Mycelium,
- Note,
- Poof,
- Portal,
- Rain,
- Smoke,
- Sneeze,
- Spit,
- SquidInk,
- SweepAttack,
- TotemOfUndying,
- Underwater,
- Splash,
- Witch,
- BubblePop,
- CurrentDown,
- BubbleColumnUp,
- Nautilus,
- Dolphin,
- CampfireCozySmoke,
- CampfireSignalSmoke,
- DrippingHoney,
- FallingHoney,
- LandingHoney,
- FallingNectar,
- FallingSporeBlossom,
- Ash,
- CrimsonSpore,
- WarpedSpore,
- SporeBlossomAir,
- DrippingObsidianTear,
- FallingObsidianTear,
- LandingObsidianTear,
- ReversePortal,
- WhiteAsh,
- SmallFlame,
- Snowflake,
- DrippingDripstoneLava,
- FallingDripstoneLava,
- DrippingDripstoneWater,
- FallingDripstoneWater,
- GlowSquidInk,
- Glow,
- WaxOn,
- WaxOff,
- ElectricSpark,
- Scrape,
-}
-
-#[derive(Debug, Clone, McBuf)]
-pub struct BlockParticle {
- #[var]
- pub block_state: i32,
-}
-#[derive(Debug, Clone, McBuf)]
-pub struct DustParticle {
- /// Red value, 0-1
- pub red: f32,
- /// Green value, 0-1
- pub green: f32,
- /// Blue value, 0-1
- pub blue: f32,
- /// The scale, will be clamped between 0.01 and 4.
- pub scale: f32,
-}
-
-#[derive(Debug, Clone, McBuf)]
-pub struct DustColorTransitionParticle {
- /// Red value, 0-1
- pub from_red: f32,
- /// Green value, 0-1
- pub from_green: f32,
- /// Blue value, 0-1
- pub from_blue: f32,
- /// The scale, will be clamped between 0.01 and 4.
- pub scale: f32,
- /// Red value, 0-1
- pub to_red: f32,
- /// Green value, 0-1
- pub to_green: f32,
- /// Blue value, 0-1
- pub to_blue: f32,
-}
-
-#[derive(Debug, Clone, McBuf)]
-pub struct ItemParticle {
- pub item: Slot,
-}
-
-#[derive(Debug, Clone, McBuf)]
-pub struct VibrationParticle {
- pub origin: BlockPos,
- pub position_type: String,
- pub block_position: BlockPos,
- #[var]
- pub entity_id: u32,
- #[var]
- pub ticks: u32,
-}
-
-impl ParticleData {
- pub fn read_from_particle_id(buf: &mut impl Read, id: u32) -> Result<Self, String> {
- Ok(match id {
- 0 => ParticleData::AmbientEntityEffect,
- 1 => ParticleData::AngryVillager,
- 2 => ParticleData::Block(BlockParticle::read_into(buf)?),
- 3 => ParticleData::BlockMarker(BlockParticle::read_into(buf)?),
- 4 => ParticleData::Bubble,
- 5 => ParticleData::Cloud,
- 6 => ParticleData::Crit,
- 7 => ParticleData::DamageIndicator,
- 8 => ParticleData::DragonBreath,
- 9 => ParticleData::DrippingLava,
- 10 => ParticleData::FallingLava,
- 11 => ParticleData::LandingLava,
- 12 => ParticleData::DrippingWater,
- 13 => ParticleData::FallingWater,
- 14 => ParticleData::Dust(DustParticle::read_into(buf)?),
- 15 => ParticleData::DustColorTransition(DustColorTransitionParticle::read_into(buf)?),
- 16 => ParticleData::Effect,
- 17 => ParticleData::ElderGuardian,
- 18 => ParticleData::EnchantedHit,
- 19 => ParticleData::Enchant,
- 20 => ParticleData::EndRod,
- 21 => ParticleData::EntityEffect,
- 22 => ParticleData::ExplosionEmitter,
- 23 => ParticleData::Explosion,
- 24 => ParticleData::FallingDust(BlockParticle::read_into(buf)?),
- 25 => ParticleData::Firework,
- 26 => ParticleData::Fishing,
- 27 => ParticleData::Flame,
- 28 => ParticleData::SoulFireFlame,
- 29 => ParticleData::Soul,
- 30 => ParticleData::Flash,
- 31 => ParticleData::HappyVillager,
- 32 => ParticleData::Composter,
- 33 => ParticleData::Heart,
- 34 => ParticleData::InstantEffect,
- 35 => ParticleData::Item(ItemParticle::read_into(buf)?),
- 36 => ParticleData::Vibration(VibrationParticle::read_into(buf)?),
- 37 => ParticleData::ItemSlime,
- 38 => ParticleData::ItemSnowball,
- 39 => ParticleData::LargeSmoke,
- 40 => ParticleData::Lava,
- 41 => ParticleData::Mycelium,
- 42 => ParticleData::Note,
- 43 => ParticleData::Poof,
- 44 => ParticleData::Portal,
- 45 => ParticleData::Rain,
- 46 => ParticleData::Smoke,
- 47 => ParticleData::Sneeze,
- 48 => ParticleData::Spit,
- 49 => ParticleData::SquidInk,
- 50 => ParticleData::SweepAttack,
- 51 => ParticleData::TotemOfUndying,
- 52 => ParticleData::Underwater,
- 53 => ParticleData::Splash,
- 54 => ParticleData::Witch,
- 55 => ParticleData::BubblePop,
- 56 => ParticleData::CurrentDown,
- 57 => ParticleData::BubbleColumnUp,
- 58 => ParticleData::Nautilus,
- 59 => ParticleData::Dolphin,
- 60 => ParticleData::CampfireCozySmoke,
- 61 => ParticleData::CampfireSignalSmoke,
- 62 => ParticleData::DrippingHoney,
- 63 => ParticleData::FallingHoney,
- 64 => ParticleData::LandingHoney,
- 65 => ParticleData::FallingNectar,
- 66 => ParticleData::FallingSporeBlossom,
- 67 => ParticleData::Ash,
- 68 => ParticleData::CrimsonSpore,
- 69 => ParticleData::WarpedSpore,
- 70 => ParticleData::SporeBlossomAir,
- 71 => ParticleData::DrippingObsidianTear,
- 72 => ParticleData::FallingObsidianTear,
- 73 => ParticleData::LandingObsidianTear,
- 74 => ParticleData::ReversePortal,
- 75 => ParticleData::WhiteAsh,
- 76 => ParticleData::SmallFlame,
- 77 => ParticleData::Snowflake,
- 78 => ParticleData::DrippingDripstoneLava,
- 79 => ParticleData::FallingDripstoneLava,
- 80 => ParticleData::DrippingDripstoneWater,
- 81 => ParticleData::FallingDripstoneWater,
- 82 => ParticleData::GlowSquidInk,
- 83 => ParticleData::Glow,
- 84 => ParticleData::WaxOn,
- 85 => ParticleData::WaxOff,
- 86 => ParticleData::ElectricSpark,
- 87 => ParticleData::Scrape,
- _ => return Err(format!("Unknown particle id: {}", id)),
- })
- }
-}
-
-impl McBufReadable for ParticleData {
- fn read_into(buf: &mut impl Read) -> Result<Self, String> {
- let id = u32::var_read_into(buf)?;
- ParticleData::read_from_particle_id(buf, id)
- }
-}
-
-impl McBufWritable for ParticleData {
- fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
- todo!()
- }
-}
diff --git a/azalea-protocol/src/mc_buf/mod.rs b/azalea-protocol/src/mc_buf/mod.rs
deleted file mode 100644
index 548ba7c2..00000000
--- a/azalea-protocol/src/mc_buf/mod.rs
+++ /dev/null
@@ -1,233 +0,0 @@
-//! Utilities for reading and writing for the Minecraft protocol
-
-mod definitions;
-mod read;
-mod write;
-
-pub use definitions::{BitSet, EntityMetadata, ParticleData, UnsizedByteArray};
-pub use read::{read_varint_async, McBufReadable, McBufVarReadable, Readable};
-pub use write::{McBufVarWritable, McBufWritable, Writable};
-
-// const DEFAULT_NBT_QUOTA: u32 = 2097152;
-const MAX_STRING_LENGTH: u16 = 32767;
-// const MAX_COMPONENT_STRING_LENGTH: u32 = 262144;
-
-// TODO: maybe get rid of the readable/writable traits so there's not two ways to do the same thing and improve McBufReadable/McBufWritable
-
-// TODO: have a definitions.rs in mc_buf that contains UnsizedByteArray and BitSet
-
-#[cfg(test)]
-mod tests {
- use super::*;
- use azalea_core::resource_location::ResourceLocation;
- use std::{collections::HashMap, io::Cursor};
-
- #[test]
- fn test_write_varint() {
- let mut buf = Vec::new();
- buf.write_varint(0).unwrap();
- assert_eq!(buf, vec![0]);
-
- let mut buf = Vec::new();
- buf.write_varint(1).unwrap();
- assert_eq!(buf, vec![1]);
-
- let mut buf = Vec::new();
- buf.write_varint(2).unwrap();
- assert_eq!(buf, vec![2]);
-
- let mut buf = Vec::new();
- buf.write_varint(127).unwrap();
- assert_eq!(buf, vec![127]);
-
- let mut buf = Vec::new();
- buf.write_varint(128).unwrap();
- assert_eq!(buf, vec![128, 1]);
-
- let mut buf = Vec::new();
- buf.write_varint(255).unwrap();
- assert_eq!(buf, vec![255, 1]);
-
- let mut buf = Vec::new();
- buf.write_varint(25565).unwrap();
- assert_eq!(buf, vec![221, 199, 1]);
-
- let mut buf = Vec::new();
- buf.write_varint(2097151).unwrap();
- assert_eq!(buf, vec![255, 255, 127]);
-
- let mut buf = Vec::new();
- buf.write_varint(2147483647).unwrap();
- assert_eq!(buf, vec![255, 255, 255, 255, 7]);
-
- let mut buf = Vec::new();
- buf.write_varint(-1).unwrap();
- assert_eq!(buf, vec![255, 255, 255, 255, 15]);
-
- let mut buf = Vec::new();
- buf.write_varint(-2147483648).unwrap();
- assert_eq!(buf, vec![128, 128, 128, 128, 8]);
- }
-
- #[test]
- fn test_read_varint() {
- let mut buf = Cursor::new(vec![0]);
- assert_eq!(buf.read_varint().unwrap(), 0);
- assert_eq!(buf.get_varint_size(0), 1);
-
- let mut buf = Cursor::new(vec![1]);
- assert_eq!(buf.read_varint().unwrap(), 1);
- assert_eq!(buf.get_varint_size(1), 1);
-
- let mut buf = Cursor::new(vec![2]);
- assert_eq!(buf.read_varint().unwrap(), 2);
- assert_eq!(buf.get_varint_size(2), 1);
-
- let mut buf = Cursor::new(vec![127]);
- assert_eq!(buf.read_varint().unwrap(), 127);
- assert_eq!(buf.get_varint_size(127), 1);
-
- let mut buf = Cursor::new(vec![128, 1]);
- assert_eq!(buf.read_varint().unwrap(), 128);
- assert_eq!(buf.get_varint_size(128), 2);
-
- let mut buf = Cursor::new(vec![255, 1]);
- assert_eq!(buf.read_varint().unwrap(), 255);
- assert_eq!(buf.get_varint_size(255), 2);
-
- let mut buf = Cursor::new(vec![221, 199, 1]);
- assert_eq!(buf.read_varint().unwrap(), 25565);
- assert_eq!(buf.get_varint_size(25565), 3);
-
- let mut buf = Cursor::new(vec![255, 255, 127]);
- assert_eq!(buf.read_varint().unwrap(), 2097151);
- assert_eq!(buf.get_varint_size(2097151), 3);
-
- let mut buf = Cursor::new(vec![255, 255, 255, 255, 7]);
- assert_eq!(buf.read_varint().unwrap(), 2147483647);
- assert_eq!(buf.get_varint_size(2147483647), 5);
-
- let mut buf = Cursor::new(vec![255, 255, 255, 255, 15]);
- assert_eq!(buf.read_varint().unwrap(), -1);
- assert_eq!(buf.get_varint_size(-1), 5);
-
- let mut buf = Cursor::new(vec![128, 128, 128, 128, 8]);
- assert_eq!(buf.read_varint().unwrap(), -2147483648);
- assert_eq!(buf.get_varint_size(-2147483648), 5);
- }
-
- #[test]
- fn test_read_varint_longer() {
- let mut buf = Cursor::new(vec![138, 56, 0, 135, 56, 123]);
- assert_eq!(buf.read_varint().unwrap(), 7178);
- }
-
- #[test]
- fn test_list() {
- let mut buf = Vec::new();
- buf.write_list(&vec!["a", "bc", "def"], |buf, s| buf.write_utf(s))
- .unwrap();
-
- // there's no read_list because idk how to do it in rust
- let mut buf = Cursor::new(buf);
-
- let mut result = Vec::new();
- let length = buf.read_varint().unwrap();
- for _ in 0..length {
- result.push(buf.read_utf().unwrap());
- }
-
- assert_eq!(result, vec!["a", "bc", "def"]);
- }
-
- #[test]
- fn test_int_id_list() {
- let mut buf = Vec::new();
- buf.write_list(&vec![1, 2, 3], |buf, i| buf.write_varint(*i))
- .unwrap();
-
- let mut buf = Cursor::new(buf);
-
- let result = buf.read_int_id_list().unwrap();
- assert_eq!(result, vec![1, 2, 3]);
- }
-
- #[test]
- fn test_map() {
- let mut buf = Vec::new();
- buf.write_map(
- vec![("a", 1), ("bc", 23), ("def", 456)],
- Vec::write_utf,
- Vec::write_varint,
- )
- .unwrap();
-
- let mut buf = Cursor::new(buf);
-
- let mut result = Vec::new();
- let length = buf.read_varint().unwrap();
- for _ in 0..length {
- result.push((buf.read_utf().unwrap(), buf.read_varint().unwrap()));
- }
-
- assert_eq!(
- result,
- vec![
- ("a".to_string(), 1),
- ("bc".to_string(), 23),
- ("def".to_string(), 456)
- ]
- );
- }
-
- #[test]
- fn test_nbt() {
- let mut buf = Vec::new();
- buf.write_nbt(&azalea_nbt::Tag::Compound(HashMap::from_iter(vec![(
- "hello world".to_string(),
- azalea_nbt::Tag::Compound(HashMap::from_iter(vec![(
- "name".to_string(),
- azalea_nbt::Tag::String("Bananrama".to_string()),
- )])),
- )])))
- .unwrap();
-
- let mut buf = Cursor::new(buf);
-
- let result = buf.read_nbt().unwrap();
- assert_eq!(
- result,
- azalea_nbt::Tag::Compound(HashMap::from_iter(vec![(
- "hello world".to_string(),
- azalea_nbt::Tag::Compound(HashMap::from_iter(vec![(
- "name".to_string(),
- azalea_nbt::Tag::String("Bananrama".to_string()),
- )])),
- )]))
- );
- }
-
- #[test]
- fn test_long() {
- let mut buf = Vec::new();
- buf.write_long(123456).unwrap();
-
- let mut buf = Cursor::new(buf);
-
- assert_eq!(buf.read_long().unwrap(), 123456);
- }
-
- #[test]
- fn test_resource_location() {
- let mut buf = Vec::new();
- buf.write_resource_location(&ResourceLocation::new("minecraft:dirt").unwrap())
- .unwrap();
-
- let mut buf = Cursor::new(buf);
-
- assert_eq!(
- buf.read_resource_location().unwrap(),
- ResourceLocation::new("minecraft:dirt").unwrap()
- );
- }
-}
diff --git a/azalea-protocol/src/mc_buf/read.rs b/azalea-protocol/src/mc_buf/read.rs
deleted file mode 100644
index ac8d5ccb..00000000
--- a/azalea-protocol/src/mc_buf/read.rs
+++ /dev/null
@@ -1,525 +0,0 @@
-use super::{UnsizedByteArray, MAX_STRING_LENGTH};
-use azalea_chat::component::Component;
-use azalea_core::{
- difficulty::Difficulty, game_type::GameType, resource_location::ResourceLocation,
- serializable_uuid::SerializableUuid, BlockPos, ChunkSectionPos, Direction, GlobalPos, Slot,
- SlotData,
-};
-use azalea_crypto::SaltSignaturePair;
-use byteorder::{ReadBytesExt, BE};
-use serde::Deserialize;
-use std::{collections::HashMap, hash::Hash, io::Read};
-use tokio::io::{AsyncRead, AsyncReadExt};
-use uuid::Uuid;
-
-pub trait Readable {
- fn read_int_id_list(&mut self) -> Result<Vec<i32>, String>;
- fn read_varint(&mut self) -> Result<i32, String>;
- fn get_varint_size(&mut self, value: i32) -> u8;
- fn get_varlong_size(&mut self, value: i32) -> u8;
- fn read_byte_array(&mut self) -> Result<Vec<u8>, String>;
- fn read_bytes_with_len(&mut self, n: usize) -> Result<Vec<u8>, String>;
- fn read_bytes(&mut self) -> Result<Vec<u8>, String>;
- fn read_utf(&mut self) -> Result<String, String>;
- fn read_utf_with_len(&mut self, max_length: u32) -> Result<String, String>;
- fn read_byte(&mut self) -> Result<u8, String>;
- fn read_int(&mut self) -> Result<i32, String>;
- fn read_boolean(&mut self) -> Result<bool, String>;
- fn read_nbt(&mut self) -> Result<azalea_nbt::Tag, String>;
- fn read_long(&mut self) -> Result<i64, String>;
- fn read_resource_location(&mut self) -> Result<ResourceLocation, String>;
- fn read_short(&mut self) -> Result<i16, String>;
- fn read_float(&mut self) -> Result<f32, String>;
- fn read_double(&mut self) -> Result<f64, String>;
- fn read_uuid(&mut self) -> Result<Uuid, String>;
-}
-
-impl<R> Readable for R
-where
- R: Read,
-{
- fn read_int_id_list(&mut self) -> Result<Vec<i32>, String> {
- let len = self.read_varint()?;
- let mut list = Vec::with_capacity(len as usize);
- for _ in 0..len {
- list.push(self.read_varint()?);
- }
- Ok(list)
- }
-
- // fast varints modified from https://github.com/luojia65/mc-varint/blob/master/src/lib.rs#L67
- /// Read a single varint from the reader and return the value, along with the number of bytes read
- fn read_varint(&mut self) -> Result<i32, String> {
- let mut buffer = [0];
- let mut ans = 0;
- for i in 0..5 {
- self.read_exact(&mut buffer)
- .map_err(|_| "Invalid VarInt".to_string())?;
- ans |= ((buffer[0] & 0b0111_1111) as i32) << (7 * i);
- if buffer[0] & 0b1000_0000 == 0 {
- return Ok(ans);
- }
- }
- Ok(ans)
- }
-
- fn get_varint_size(&mut self, value: i32) -> u8 {
- for i in 1..5 {
- if (value & -1 << (i * 7)) != 0 {
- continue;
- }
- return i;
- }
- 5
- }
-
- fn get_varlong_size(&mut self, value: i32) -> u8 {
- for i in 1..10 {
- if (value & -1 << (i * 7)) != 0 {
- continue;
- }
- return i;
- }
- 10
- }
-
- fn read_byte_array(&mut self) -> Result<Vec<u8>, String> {
- let length = self.read_varint()? as usize;
- self.read_bytes_with_len(length)
- }
-
- fn read_bytes_with_len(&mut self, n: usize) -> Result<Vec<u8>, String> {
- let mut buffer = vec![0; n];
- self.read_exact(&mut buffer)
- .map_err(|_| "Error reading bytes".to_string())?;
- Ok(buffer)
- }
-
- fn read_bytes(&mut self) -> Result<Vec<u8>, String> {
- // read to end of the buffer
- let mut bytes = vec![];
- self.read_to_end(&mut bytes)
- .map_err(|_| "Error reading bytes".to_string())?;
- Ok(bytes)
- }
-
- fn read_utf(&mut self) -> Result<String, String> {
- self.read_utf_with_len(MAX_STRING_LENGTH.into())
- }
-
- fn read_utf_with_len(&mut self, max_length: u32) -> Result<String, String> {
- let length = self.read_varint()?;
- // i don't know why it's multiplied by 4 but it's like that in mojang's code so
- if length < 0 {
- return Err(
- "The received encoded string buffer length is less than zero! Weird string!"
- .to_string(),
- );
- }
- if length as u32 > max_length * 4 {
- return Err(format!(
- "The received encoded string buffer length is longer than maximum allowed ({} > {})",
- length,
- max_length * 4
- ));
- }
-
- // this is probably quite inefficient, idk how to do it better
- let mut string = String::new();
- let mut buffer = vec![0; length as usize];
- self.read_exact(&mut buffer)
- .map_err(|_| "Invalid UTF-8".to_string())?;
- string.push_str(std::str::from_utf8(&buffer).unwrap());
- if string.len() > length as usize {
- return Err(format!(
- "The received string length is longer than maximum allowed ({} > {})",
- length, max_length
- ));
- }
-
- Ok(string)
- }
-
- /// Read a single byte from the reader
- fn read_byte(&mut self) -> Result<u8, String> {
- self.read_u8().map_err(|_| "Error reading byte".to_string())
- }
-
- fn read_int(&mut self) -> Result<i32, String> {
- match self.read_i32::<BE>() {
- Ok(r) => Ok(r),
- Err(_) => Err("Error reading int".to_string()),
- }
- }
-
- fn read_boolean(&mut self) -> Result<bool, String> {
- match self.read_byte()? {
- 0 => Ok(false),
- 1 => Ok(true),
- _ => Err("Error reading boolean".to_string()),
- }
- }
-
- fn read_nbt(&mut self) -> Result<azalea_nbt::Tag, String> {
- match azalea_nbt::Tag::read(self) {
- Ok(r) => Ok(r),
- // Err(e) => Err(e.to_string()),
- Err(e) => Err(e.to_string()).unwrap(),
- }
- }
-
- fn read_long(&mut self) -> Result<i64, String> {
- match self.read_i64::<BE>() {
- Ok(r) => Ok(r),
- Err(_) => Err("Error reading long".to_string()),
- }
- }
-
- fn read_resource_location(&mut self) -> Result<ResourceLocation, String> {
- // get the resource location from the string
- let location_string = self.read_utf()?;
- let location = ResourceLocation::new(&location_string)?;
- Ok(location)
- }
-
- fn read_short(&mut self) -> Result<i16, String> {
- match self.read_i16::<BE>() {
- Ok(r) => Ok(r),
- Err(_) => Err("Error reading short".to_string()),
- }
- }
-
- fn read_float(&mut self) -> Result<f32, String> {
- match self.read_f32::<BE>() {
- Ok(r) => Ok(r),
- Err(_) => Err("Error reading float".to_string()),
- }
- }
-
- fn read_double(&mut self) -> Result<f64, String> {
- match self.read_f64::<BE>() {
- Ok(r) => Ok(r),
- Err(_) => Err("Error reading double".to_string()),
- }
- }
-
- fn read_uuid(&mut self) -> Result<Uuid, String> {
- Ok(Uuid::from_int_array([
- Readable::read_int(self)? as u32,
- Readable::read_int(self)? as u32,
- Readable::read_int(self)? as u32,
- Readable::read_int(self)? as u32,
- ]))
- }
-}
-
-// fast varints modified from https://github.com/luojia65/mc-varint/blob/master/src/lib.rs#L67
-/// Read a single varint from the reader and return the value, along with the number of bytes read
-pub async fn read_varint_async(reader: &mut (dyn AsyncRead + Unpin + Send)) -> Result<i32, String> {
- let mut buffer = [0];
- let mut ans = 0;
- for i in 0..5 {
- reader
- .read_exact(&mut buffer)
- .await
- .map_err(|_| "Invalid VarInt".to_string())?;
- ans |= ((buffer[0] & 0b0111_1111) as i32) << (7 * i);
- if buffer[0] & 0b1000_0000 == 0 {
- return Ok(ans);
- }
- }
- Ok(ans)
-}
-
-pub trait McBufReadable
-where
- Self: Sized,
-{
- fn read_into(buf: &mut impl Read) -> Result<Self, String>;
-}
-
-pub trait McBufVarReadable
-where
- Self: Sized,
-{
- fn var_read_into(buf: &mut impl Read) -> Result<Self, String>;
-}
-
-impl McBufReadable for i32 {
- fn read_into(buf: &mut impl Read) -> Result<Self, String> {
- Readable::read_int(buf)
- }
-}
-
-impl McBufVarReadable for i32 {
- fn var_read_into(buf: &mut impl Read) -> Result<Self, String> {
- buf.read_varint()
- }
-}
-
-impl McBufVarReadable for i64 {
- // fast varints modified from https://github.com/luojia65/mc-varint/blob/master/src/lib.rs#L54
- fn var_read_into(buf: &mut impl Read) -> Result<Self, String> {
- let mut buffer = [0];
- let mut ans = 0;
- for i in 0..8 {
- buf.read_exact(&mut buffer)
- .map_err(|_| "Invalid VarLong".to_string())?;
- ans |= ((buffer[0] & 0b0111_1111) as i64) << 7 * i;
- if buffer[0] & 0b1000_0000 == 0 {
- break;
- }
- }
- Ok(ans)
- }
-}
-impl McBufVarReadable for u64 {
- fn var_read_into(buf: &mut impl Read) -> Result<Self, String> {
- i64::var_read_into(buf).map(|i| i as u64)
- }
-}
-
-impl McBufReadable for UnsizedByteArray {
- fn read_into(buf: &mut impl Read) -> Result<Self, String> {
- Ok(buf.read_bytes()?.into())
- }
-}
-
-impl<T: McBufReadable + Send> McBufReadable for Vec<T> {
- default fn read_into(buf: &mut impl Read) -> Result<Self, String> {
- let length = buf.read_varint()? as usize;
- let mut contents = Vec::with_capacity(length);
- for _ in 0..length {
- contents.push(T::read_into(buf)?);
- }
- Ok(contents)
- }
-}
-
-impl<K: McBufReadable + Send + Eq + Hash, V: McBufReadable + Send> McBufReadable for HashMap<K, V> {
- default fn read_into(buf: &mut impl Read) -> Result<Self, String> {
- let length = buf.read_varint()? as usize;
- let mut contents = HashMap::with_capacity(length);
- for _ in 0..length {
- contents.insert(K::read_into(buf)?, V::read_into(buf)?);
- }
- Ok(contents)
- }
-}
-
-impl McBufReadable for Vec<u8> {
- fn read_into(buf: &mut impl Read) -> Result<Self, String> {
- buf.read_byte_array()
- }
-}
-
-impl McBufReadable for String {
- fn read_into(buf: &mut impl Read) -> Result<Self, String> {
- buf.read_utf()
- }
-}
-
-impl McBufReadable for ResourceLocation {
- fn read_into(buf: &mut impl Read) -> Result<Self, String> {
- buf.read_resource_location()
- }
-}
-
-impl McBufReadable for u32 {
- fn read_into(buf: &mut impl Read) -> Result<Self, String> {
- Readable::read_int(buf).map(|i| i as u32)
- }
-}
-
-impl McBufVarReadable for u32 {
- fn var_read_into(buf: &mut impl Read) -> Result<Self, String> {
- buf.read_varint().map(|i| i as u32)
- }
-}
-
-impl McBufReadable for u16 {
- fn read_into(buf: &mut impl Read) -> Result<Self, String> {
- buf.read_short().map(|i| i as u16)
- }
-}
-
-impl McBufReadable for i16 {
- fn read_into(buf: &mut impl Read) -> Result<Self, String> {
- buf.read_short()
- }
-}
-
-impl McBufVarReadable for u16 {
- fn var_read_into(buf: &mut impl Read) -> Result<Self, String> {
- buf.read_varint().map(|i| i as u16)
- }
-}
-
-impl<T: McBufVarReadable> McBufVarReadable for Vec<T> {
- fn var_read_into(buf: &mut impl Read) -> Result<Self, String> {
- let length = buf.read_varint()? as usize;
- let mut contents = Vec::with_capacity(length);
- for _ in 0..length {
- contents.push(T::var_read_into(buf)?);
- }
- Ok(contents)
- }
-}
-
-impl McBufReadable for i64 {
- fn read_into(buf: &mut impl Read) -> Result<Self, String> {
- buf.read_long()
- }
-}
-
-impl McBufReadable for u64 {
- fn read_into(buf: &mut impl Read) -> Result<Self, String> {
- i64::read_into(buf).map(|i| i as u64)
- }
-}
-
-impl McBufReadable for bool {
- fn read_into(buf: &mut impl Read) -> Result<Self, String> {
- buf.read_boolean()
- }
-}
-
-impl McBufReadable for u8 {
- fn read_into(buf: &mut impl Read) -> Result<Self, String> {
- buf.read_byte()
- }
-}
-
-impl McBufReadable for i8 {
- fn read_into(buf: &mut impl Read) -> Result<Self, String> {
- buf.read_byte().map(|i| i as i8)
- }
-}
-
-impl McBufReadable for f32 {
- fn read_into(buf: &mut impl Read) -> Result<Self, String> {
- buf.read_float()
- }
-}
-
-impl McBufReadable for f64 {
- fn read_into(buf: &mut impl Read) -> Result<Self, String> {
- buf.read_double()
- }
-}
-
-impl McBufReadable for GameType {
- fn read_into(buf: &mut impl Read) -> Result<Self, String> {
- GameType::from_id(buf.read_byte()?)
- }
-}
-
-impl McBufReadable for Option<GameType> {
- fn read_into(buf: &mut impl Read) -> Result<Self, String> {
- GameType::from_optional_id(buf.read_byte()? as i8)
- }
-}
-
-impl<T: McBufReadable> McBufReadable for Option<T> {
- default fn read_into(buf: &mut impl Read) -> Result<Self, String> {
- let present = buf.read_boolean()?;
- Ok(if present {
- Some(T::read_into(buf)?)
- } else {
- None
- })
- }
-}
-
-impl McBufReadable for azalea_nbt::Tag {
- fn read_into(buf: &mut impl Read) -> Result<Self, String> {
- buf.read_nbt()
- }
-}
-
-impl McBufReadable for Difficulty {
- fn read_into(buf: &mut impl Read) -> Result<Self, String> {
- Ok(Difficulty::by_id(u8::read_into(buf)?))
- }
-}
-
-impl McBufReadable for Component {
- fn read_into(buf: &mut impl Read) -> Result<Self, String> {
- let string = buf.read_utf()?;
- let json: serde_json::Value = serde_json::from_str(string.as_str())
- .map_err(|_| "Component isn't valid JSON".to_string())?;
- let component = Component::deserialize(json).map_err(|e| e.to_string())?;
- Ok(component)
- }
-}
-
-impl McBufReadable for Slot {
- fn read_into(buf: &mut impl Read) -> Result<Self, String> {
- let present = buf.read_boolean()?;
- if !present {
- return Ok(Slot::Empty);
- }
- let id = buf.read_varint()?;
- let count = buf.read_byte()?;
- let nbt = buf.read_nbt()?;
- Ok(Slot::Present(SlotData { id, count, nbt }))
- }
-}
-
-impl McBufReadable for Uuid {
- fn read_into(buf: &mut impl Read) -> Result<Self, String> {
- buf.read_uuid()
- }
-}
-
-impl McBufReadable for BlockPos {
- fn read_into(buf: &mut impl Read) -> Result<Self, String> {
- let val = u64::read_into(buf)?;
- let x = (val >> 38) as i32;
- let y = (val & 0xFFF) as i32;
- let z = ((val >> 12) & 0x3FFFFFF) as i32;
- Ok(BlockPos { x, y, z })
- }
-}
-
-impl McBufReadable for GlobalPos {
- fn read_into(buf: &mut impl Read) -> Result<Self, String> {
- Ok(GlobalPos {
- dimension: ResourceLocation::read_into(buf)?,
- pos: BlockPos::read_into(buf)?,
- })
- }
-}
-
-impl McBufReadable for Direction {
- fn read_into(buf: &mut impl Read) -> Result<Self, String> {
- match buf.read_varint()? {
- 0 => Ok(Self::Down),
- 1 => Ok(Self::Up),
- 2 => Ok(Self::North),
- 3 => Ok(Self::South),
- 4 => Ok(Self::West),
- 5 => Ok(Self::East),
- _ => Err("Invalid direction".to_string()),
- }
- }
-}
-
-impl McBufReadable for ChunkSectionPos {
- fn read_into(buf: &mut impl Read) -> Result<Self, String> {
- let long = i64::read_into(buf)?;
- Ok(ChunkSectionPos {
- x: (long >> 42) as i32,
- y: (long << 44 >> 44) as i32,
- z: (long << 22 >> 42) as i32,
- })
- }
-}
-
-impl McBufReadable for SaltSignaturePair {
- fn read_into(buf: &mut impl Read) -> Result<Self, String> {
- let salt = u64::read_into(buf)?;
- let signature = Vec::<u8>::read_into(buf)?;
- Ok(SaltSignaturePair { salt, signature })
- }
-}
diff --git a/azalea-protocol/src/mc_buf/write.rs b/azalea-protocol/src/mc_buf/write.rs
deleted file mode 100644
index 945477d0..00000000
--- a/azalea-protocol/src/mc_buf/write.rs
+++ /dev/null
@@ -1,430 +0,0 @@
-use super::{UnsizedByteArray, MAX_STRING_LENGTH};
-use azalea_chat::component::Component;
-use azalea_core::{
- difficulty::Difficulty, game_type::GameType, resource_location::ResourceLocation,
- serializable_uuid::SerializableUuid, BlockPos, ChunkSectionPos, Direction, GlobalPos, Slot,
-};
-use azalea_crypto::SaltSignaturePair;
-use byteorder::{BigEndian, WriteBytesExt};
-use std::{collections::HashMap, io::Write};
-use uuid::Uuid;
-
-pub trait Writable: Write {
- fn write_list<F, T>(&mut self, list: &[T], writer: F) -> Result<(), std::io::Error>
- where
- F: FnOnce(&mut Self, &T) -> Result<(), std::io::Error> + Copy,
- {
- self.write_varint(list.len() as i32)?;
- for item in list {
- writer(self, item)?;
- }
- Ok(())
- }
-
- fn write_int_id_list(&mut self, list: &[i32]) -> Result<(), std::io::Error> {
- self.write_list(list, |buf, n| buf.write_varint(*n))
- }
-
- fn write_map<KF, VF, KT, VT>(
- &mut self,
- map: Vec<(KT, VT)>,
- key_writer: KF,
- value_writer: VF,
- ) -> Result<(), std::io::Error>
- where
- KF: Fn(&mut Self, KT) -> Result<(), std::io::Error> + Copy,
- VF: Fn(&mut Self, VT) -> Result<(), std::io::Error> + Copy,
- {
- self.write_varint(map.len() as i32)?;
- for (key, value) in map {
- key_writer(self, key)?;
- value_writer(self, value)?;
- }
- Ok(())
- }
-
- fn write_byte(&mut self, n: u8) -> Result<(), std::io::Error> {
- WriteBytesExt::write_u8(self, n)
- }
-
- fn write_bytes(&mut self, bytes: &[u8]) -> Result<(), std::io::Error> {
- self.write_all(bytes)?;
- Ok(())
- }
-
- fn write_varint(&mut self, mut value: i32) -> Result<(), std::io::Error> {
- let mut buffer = [0];
- if value == 0 {
- self.write_all(&buffer).unwrap();
- }
- while value != 0 {
- buffer[0] = (value & 0b0111_1111) as u8;
- value = (value >> 7) & (i32::max_value() >> 6);
- if value != 0 {
- buffer[0] |= 0b1000_0000;
- }
- self.write_all(&buffer)?;
- }
- Ok(())
- }
-
- fn write_utf_with_len(&mut self, string: &str, len: usize) -> Result<(), std::io::Error> {
- if string.len() > len {
- panic!(
- "String too big (was {} bytes encoded, max {})",
- string.len(),
- len
- );
- }
- self.write_varint(string.len() as i32)?;
- self.write_bytes(string.as_bytes())
- }
-
- fn write_utf(&mut self, string: &str) -> Result<(), std::io::Error> {
- self.write_utf_with_len(string, MAX_STRING_LENGTH.into())
- }
-
- fn write_short(&mut self, n: i16) -> Result<(), std::io::Error> {
- WriteBytesExt::write_i16::<BigEndian>(self, n)
- }
-
- fn write_byte_array(&mut self, bytes: &[u8]) -> Result<(), std::io::Error> {
- self.write_varint(bytes.len() as i32)?;
- self.write_bytes(bytes)
- }
-
- fn write_int(&mut self, n: i32) -> Result<(), std::io::Error> {
- WriteBytesExt::write_i32::<BigEndian>(self, n)
- }
-
- fn write_boolean(&mut self, b: bool) -> Result<(), std::io::Error> {
- self.write_byte(if b { 1 } else { 0 })
- }
-
- fn write_nbt(&mut self, nbt: &azalea_nbt::Tag) -> Result<(), std::io::Error>
- where
- Self: Sized,
- {
- nbt.write(self)
- .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))
- }
-
- fn write_long(&mut self, n: i64) -> Result<(), std::io::Error> {
- WriteBytesExt::write_i64::<BigEndian>(self, n)
- }
-
- fn write_float(&mut self, n: f32) -> Result<(), std::io::Error> {
- WriteBytesExt::write_f32::<BigEndian>(self, n)
- }
-
- fn write_double(&mut self, n: f64) -> Result<(), std::io::Error> {
- WriteBytesExt::write_f64::<BigEndian>(self, n)
- }
-
- fn write_resource_location(
- &mut self,
- location: &ResourceLocation,
- ) -> Result<(), std::io::Error> {
- self.write_utf(&location.to_string())
- }
-
- fn write_uuid(&mut self, uuid: &Uuid) -> Result<(), std::io::Error>
- where
- Self: Sized,
- {
- let [a, b, c, d] = uuid.to_int_array();
- a.write_into(self)?;
- b.write_into(self)?;
- c.write_into(self)?;
- d.write_into(self)?;
- Ok(())
- }
-}
-
-impl<W: Write + ?Sized> Writable for W {}
-
-pub trait McBufWritable {
- fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error>;
-}
-
-pub trait McBufVarWritable {
- fn var_write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error>;
-}
-
-impl McBufWritable for i32 {
- fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
- Writable::write_int(buf, *self)
- }
-}
-
-impl McBufVarWritable for i32 {
- fn var_write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
- buf.write_varint(*self)
- }
-}
-
-impl McBufWritable for UnsizedByteArray {
- fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
- buf.write_bytes(self)
- }
-}
-
-impl<T: McBufWritable> McBufWritable for Vec<T> {
- default fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
- buf.write_list(self, |buf, i| T::write_into(i, buf))
- }
-}
-
-impl<K: McBufWritable, V: McBufWritable> McBufWritable for HashMap<K, V> {
- default fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
- u32::var_write_into(&(self.len() as u32), buf)?;
- for (key, value) in self {
- key.write_into(buf)?;
- value.write_into(buf)?;
- }
-
- Ok(())
- }
-}
-
-impl McBufWritable for Vec<u8> {
- fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
- buf.write_byte_array(self)
- }
-}
-
-impl McBufWritable for String {
- fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
- buf.write_utf(self)
- }
-}
-
-impl McBufWritable for ResourceLocation {
- fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
- buf.write_resource_location(self)
- }
-}
-
-impl McBufWritable for u32 {
- fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
- i16::write_into(&(*self as i16), buf)
- }
-}
-
-impl McBufVarWritable for u32 {
- fn var_write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
- i32::var_write_into(&(*self as i32), buf)
- }
-}
-
-impl McBufVarWritable for i64 {
- fn var_write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
- let mut buffer = [0];
- let mut cnt = 0;
- let mut value = *self;
- while value != 0 {
- buffer[0] = (value & 0b0111_1111) as u8;
- value = (value >> 7) & (i64::max_value() >> 6);
- if value != 0 {
- buffer[0] |= 0b1000_0000;
- }
- cnt += buf.write(&mut buffer)?;
- }
- Ok(())
- }
-}
-
-impl McBufVarWritable for u64 {
- fn var_write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
- i64::var_write_into(&(*self as i64), buf)
- }
-}
-
-impl McBufWritable for u16 {
- fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
- i16::write_into(&(*self as i16), buf)
- }
-}
-
-impl McBufVarWritable for u16 {
- fn var_write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
- i32::var_write_into(&(*self as i32), buf)
- }
-}
-
-impl<T: McBufVarWritable> McBufVarWritable for Vec<T> {
- fn var_write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
- u32::var_write_into(&(self.len() as u32), buf)?;
- for i in self {
- i.var_write_into(buf)?;
- }
- Ok(())
- }
-}
-
-impl McBufWritable for u8 {
- fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
- buf.write_byte(*self)
- }
-}
-
-impl McBufWritable for i16 {
- fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
- Writable::write_short(buf, *self)
- }
-}
-
-impl McBufWritable for i64 {
- fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
- Writable::write_long(buf, *self)
- }
-}
-
-impl McBufWritable for u64 {
- fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
- i64::write_into(&(*self as i64), buf)
- }
-}
-
-impl McBufWritable for bool {
- fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
- buf.write_boolean(*self)
- }
-}
-
-impl McBufWritable for i8 {
- fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
- buf.write_byte(*self as u8)
- }
-}
-
-impl McBufWritable for f32 {
- fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
- buf.write_float(*self)
- }
-}
-
-impl McBufWritable for f64 {
- fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
- buf.write_double(*self)
- }
-}
-
-impl McBufWritable for GameType {
- fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
- u8::write_into(&self.to_id(), buf)
- }
-}
-
-impl McBufWritable for Option<GameType> {
- fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
- buf.write_byte(GameType::to_optional_id(self) as u8)
- }
-}
-
-impl<T: McBufWritable> McBufWritable for Option<T> {
- default fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
- if let Some(s) = self {
- buf.write_boolean(true)?;
- s.write_into(buf)?;
- } else {
- buf.write_boolean(false)?;
- };
- Ok(())
- }
-}
-
-impl McBufWritable for azalea_nbt::Tag {
- fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
- buf.write_nbt(self)
- }
-}
-
-impl McBufWritable for Difficulty {
- fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
- u8::write_into(&self.id(), buf)
- }
-}
-
-impl McBufWritable for Component {
- // async fn read_into(buf: &mut impl Read) -> Result<Self, String>
- // where
- // R: AsyncRead + std::marker::Unpin + std::marker::Send,
- // {
- // let string = buf.read_utf().await?;
- // let json: serde_json::Value = serde_json::from_str(string.as_str())
- // .map_err(|e| "Component isn't valid JSON".to_string())?;
- // let component = Component::deserialize(json).map_err(|e| e.to_string())?;
- // Ok(component)
- // }
- fn write_into(&self, _buf: &mut impl Write) -> Result<(), std::io::Error> {
- // component doesn't have serialize implemented yet
- todo!()
- }
-}
-
-impl McBufWritable for Slot {
- fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
- match self {
- Slot::Empty => buf.write_byte(0)?,
- Slot::Present(i) => {
- buf.write_varint(i.id)?;
- buf.write_byte(i.count)?;
- buf.write_nbt(&i.nbt)?;
- }
- }
-
- Ok(())
- }
-}
-
-impl McBufWritable for Uuid {
- fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
- buf.write_uuid(self)?;
-
- Ok(())
- }
-}
-
-impl McBufWritable for BlockPos {
- fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
- buf.write_long(
- (((self.x & 0x3FFFFFF) as i64) << 38)
- | (((self.z & 0x3FFFFFF) as i64) << 12)
- | ((self.y & 0xFFF) as i64),
- )
- }
-}
-
-impl McBufWritable for GlobalPos {
- fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
- ResourceLocation::write_into(&self.dimension, buf)?;
- BlockPos::write_into(&self.pos, buf)?;
-
- Ok(())
- }
-}
-
-impl McBufWritable for Direction {
- fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
- buf.write_varint(*self as i32)
- }
-}
-
-impl McBufWritable for ChunkSectionPos {
- fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
- let long = (((self.x & 0x3FFFFF) as i64) << 42)
- | (self.y & 0xFFFFF) as i64
- | (((self.z & 0x3FFFFF) as i64) << 20);
- long.write_into(buf)?;
- Ok(())
- }
-}
-
-impl McBufWritable for SaltSignaturePair {
- fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
- self.salt.write_into(buf)?;
- self.signature.write_into(buf)?;
- Ok(())
- }
-}
diff --git a/azalea-protocol/src/packets/game/clientbound_add_entity_packet.rs b/azalea-protocol/src/packets/game/clientbound_add_entity_packet.rs
index 9ef7e05c..0fc7b817 100644
--- a/azalea-protocol/src/packets/game/clientbound_add_entity_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_add_entity_packet.rs
@@ -1,4 +1,7 @@
-use packet_macros::{GamePacket, McBuf};
+use azalea_buf::McBuf;
+use azalea_core::EntityPos;
+use azalea_entity::Entity;
+use packet_macros::GamePacket;
use uuid::Uuid;
#[derive(Clone, Debug, McBuf, GamePacket)]
@@ -22,3 +25,17 @@ pub struct ClientboundAddEntityPacket {
pub y_vel: i16,
pub z_vel: i16,
}
+
+impl From<&ClientboundAddEntityPacket> for Entity {
+ fn from(p: &ClientboundAddEntityPacket) -> Self {
+ Self::new(
+ p.id,
+ p.uuid,
+ EntityPos {
+ x: p.x,
+ y: p.y,
+ z: p.z,
+ },
+ )
+ }
+}
diff --git a/azalea-protocol/src/packets/game/clientbound_add_player_packet.rs b/azalea-protocol/src/packets/game/clientbound_add_player_packet.rs
index f1947d09..ddadc73f 100644
--- a/azalea-protocol/src/packets/game/clientbound_add_player_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_add_player_packet.rs
@@ -1,10 +1,14 @@
-use packet_macros::{GamePacket, McBuf};
+use azalea_buf::McBuf;
+use azalea_core::EntityPos;
+use azalea_entity::Entity;
+use packet_macros::GamePacket;
use uuid::Uuid;
+/// This packet is sent by the server when a player comes into visible range, not when a player joins.
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundAddPlayerPacket {
#[var]
- pub id: i32,
+ pub id: u32,
pub uuid: Uuid,
pub x: f64,
pub y: f64,
@@ -12,3 +16,17 @@ pub struct ClientboundAddPlayerPacket {
pub x_rot: i8,
pub y_rot: i8,
}
+
+impl From<&ClientboundAddPlayerPacket> for Entity {
+ fn from(p: &ClientboundAddPlayerPacket) -> Self {
+ Self::new(
+ p.id,
+ p.uuid,
+ EntityPos {
+ x: p.x,
+ y: p.y,
+ z: p.z,
+ },
+ )
+ }
+}
diff --git a/azalea-protocol/src/packets/game/clientbound_animate_packet.rs b/azalea-protocol/src/packets/game/clientbound_animate_packet.rs
index 0bba1a25..e554da0a 100644
--- a/azalea-protocol/src/packets/game/clientbound_animate_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_animate_packet.rs
@@ -1,4 +1,5 @@
-use packet_macros::{GamePacket, McBuf};
+use azalea_buf::McBuf;
+use packet_macros::GamePacket;
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundAnimatePacket {
diff --git a/azalea-protocol/src/packets/game/clientbound_block_changed_ack_packet.rs b/azalea-protocol/src/packets/game/clientbound_block_changed_ack_packet.rs
index a580440c..2901cb82 100644
--- a/azalea-protocol/src/packets/game/clientbound_block_changed_ack_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_block_changed_ack_packet.rs
@@ -1,4 +1,5 @@
-use packet_macros::{GamePacket, McBuf};
+use azalea_buf::McBuf;
+use packet_macros::GamePacket;
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundBlockChangedAckPacket {
diff --git a/azalea-protocol/src/packets/game/clientbound_block_update_packet.rs b/azalea-protocol/src/packets/game/clientbound_block_update_packet.rs
index f068cc7d..769270ee 100644
--- a/azalea-protocol/src/packets/game/clientbound_block_update_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_block_update_packet.rs
@@ -1,5 +1,6 @@
+use azalea_buf::McBuf;
use azalea_core::BlockPos;
-use packet_macros::{GamePacket, McBuf};
+use packet_macros::GamePacket;
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundBlockUpdatePacket {
diff --git a/azalea-protocol/src/packets/game/clientbound_change_difficulty_packet.rs b/azalea-protocol/src/packets/game/clientbound_change_difficulty_packet.rs
index edda52d9..57cb1f69 100755
--- a/azalea-protocol/src/packets/game/clientbound_change_difficulty_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_change_difficulty_packet.rs
@@ -1,5 +1,6 @@
-use azalea_core::difficulty::Difficulty;
-use packet_macros::{GamePacket, McBuf};
+use azalea_buf::McBuf;
+use azalea_core::Difficulty;
+use packet_macros::GamePacket;
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundChangeDifficultyPacket {
diff --git a/azalea-protocol/src/packets/game/clientbound_chat_preview_packet.rs b/azalea-protocol/src/packets/game/clientbound_chat_preview_packet.rs
index 58dd0722..75bf0cf7 100644
--- a/azalea-protocol/src/packets/game/clientbound_chat_preview_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_chat_preview_packet.rs
@@ -1,5 +1,6 @@
+use azalea_buf::McBuf;
use azalea_chat::component::Component;
-use packet_macros::{GamePacket, McBuf};
+use packet_macros::GamePacket;
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundChatPreviewPacket {
diff --git a/azalea-protocol/src/packets/game/clientbound_container_set_content_packet.rs b/azalea-protocol/src/packets/game/clientbound_container_set_content_packet.rs
index d38bbfda..721937a7 100644
--- a/azalea-protocol/src/packets/game/clientbound_container_set_content_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_container_set_content_packet.rs
@@ -1,5 +1,6 @@
+use azalea_buf::McBuf;
use azalea_core::Slot;
-use packet_macros::{GamePacket, McBuf};
+use packet_macros::GamePacket;
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundContainerSetContentPacket {
diff --git a/azalea-protocol/src/packets/game/clientbound_custom_payload_packet.rs b/azalea-protocol/src/packets/game/clientbound_custom_payload_packet.rs
index b9ccbba4..d01e7459 100755
--- a/azalea-protocol/src/packets/game/clientbound_custom_payload_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_custom_payload_packet.rs
@@ -1,6 +1,7 @@
-use crate::mc_buf::UnsizedByteArray;
-use azalea_core::resource_location::ResourceLocation;
-use packet_macros::{GamePacket, McBuf};
+use azalea_buf::McBuf;
+use azalea_buf::UnsizedByteArray;
+use azalea_core::ResourceLocation;
+use packet_macros::GamePacket;
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundCustomPayloadPacket {
diff --git a/azalea-protocol/src/packets/game/clientbound_declare_commands_packet.rs b/azalea-protocol/src/packets/game/clientbound_declare_commands_packet.rs
index 648ca9e0..bf29a050 100755
--- a/azalea-protocol/src/packets/game/clientbound_declare_commands_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_declare_commands_packet.rs
@@ -1,8 +1,9 @@
use super::GamePacket;
-use crate::mc_buf::McBufVarReadable;
-use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable};
-use azalea_core::resource_location::ResourceLocation;
-use packet_macros::{GamePacket, McBuf};
+use azalea_buf::McBuf;
+use azalea_buf::McBufVarReadable;
+use azalea_buf::{McBufReadable, McBufWritable, Readable, Writable};
+use azalea_core::ResourceLocation;
+use packet_macros::GamePacket;
use std::{
hash::Hash,
io::{Read, Write},
@@ -182,10 +183,10 @@ impl McBufReadable for BrigadierParser {
41 => Ok(BrigadierParser::Dimension),
42 => Ok(BrigadierParser::Time),
43 => Ok(BrigadierParser::ResourceOrTag {
- registry_key: buf.read_resource_location()?,
+ registry_key: ResourceLocation::read_into(buf)?,
}),
44 => Ok(BrigadierParser::Resource {
- registry_key: buf.read_resource_location()?,
+ registry_key: ResourceLocation::read_into(buf)?,
}),
45 => Ok(BrigadierParser::TemplateMirror),
46 => Ok(BrigadierParser::TemplateRotation),
@@ -218,7 +219,7 @@ impl McBufReadable for BrigadierNodeStub {
let _name = buf.read_utf()?;
let _parser = BrigadierParser::read_into(buf)?;
let _suggestions_type = if has_suggestions_type {
- Some(buf.read_resource_location()?)
+ Some(ResourceLocation::read_into(buf)?)
} else {
None
};
diff --git a/azalea-protocol/src/packets/game/clientbound_disconnect_packet.rs b/azalea-protocol/src/packets/game/clientbound_disconnect_packet.rs
index c030d512..e5f35dc9 100644
--- a/azalea-protocol/src/packets/game/clientbound_disconnect_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_disconnect_packet.rs
@@ -1,5 +1,6 @@
+use azalea_buf::McBuf;
use azalea_chat::component::Component;
-use packet_macros::{GamePacket, McBuf};
+use packet_macros::GamePacket;
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundDisconnectPacket {
diff --git a/azalea-protocol/src/packets/game/clientbound_entity_event_packet.rs b/azalea-protocol/src/packets/game/clientbound_entity_event_packet.rs
index d0cc7222..a6f6e38d 100644
--- a/azalea-protocol/src/packets/game/clientbound_entity_event_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_entity_event_packet.rs
@@ -1,4 +1,5 @@
-use packet_macros::{GamePacket, McBuf};
+use azalea_buf::McBuf;
+use packet_macros::GamePacket;
// we can't identify the status in azalea-protocol since they vary depending on the entity
#[derive(Clone, Debug, McBuf, GamePacket)]
diff --git a/azalea-protocol/src/packets/game/clientbound_entity_velocity_packet.rs b/azalea-protocol/src/packets/game/clientbound_entity_velocity_packet.rs
index 07218c4e..7e2fa606 100644
--- a/azalea-protocol/src/packets/game/clientbound_entity_velocity_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_entity_velocity_packet.rs
@@ -1,4 +1,5 @@
-use packet_macros::{GamePacket, McBuf};
+use azalea_buf::McBuf;
+use packet_macros::GamePacket;
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundEntityVelocityPacket {
diff --git a/azalea-protocol/src/packets/game/clientbound_game_event_packet.rs b/azalea-protocol/src/packets/game/clientbound_game_event_packet.rs
index dd5f08f6..f5cb13a1 100644
--- a/azalea-protocol/src/packets/game/clientbound_game_event_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_game_event_packet.rs
@@ -1,4 +1,5 @@
-use packet_macros::{GamePacket, McBuf};
+use azalea_buf::McBuf;
+use packet_macros::GamePacket;
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundGameEventPacket {
diff --git a/azalea-protocol/src/packets/game/clientbound_initialize_border_packet.rs b/azalea-protocol/src/packets/game/clientbound_initialize_border_packet.rs
index a522eba3..f759cfc9 100644
--- a/azalea-protocol/src/packets/game/clientbound_initialize_border_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_initialize_border_packet.rs
@@ -1,4 +1,5 @@
-use packet_macros::{GamePacket, McBuf};
+use azalea_buf::McBuf;
+use packet_macros::GamePacket;
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundInitializeBorderPacket {
diff --git a/azalea-protocol/src/packets/game/clientbound_keep_alive_packet.rs b/azalea-protocol/src/packets/game/clientbound_keep_alive_packet.rs
index 18628c86..adaca872 100644
--- a/azalea-protocol/src/packets/game/clientbound_keep_alive_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_keep_alive_packet.rs
@@ -1,4 +1,5 @@
-use packet_macros::{GamePacket, McBuf};
+use azalea_buf::McBuf;
+use packet_macros::GamePacket;
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundKeepAlivePacket {
diff --git a/azalea-protocol/src/packets/game/clientbound_level_chunk_with_light_packet.rs b/azalea-protocol/src/packets/game/clientbound_level_chunk_with_light_packet.rs
index 43bda0b6..f105bd6a 100644
--- a/azalea-protocol/src/packets/game/clientbound_level_chunk_with_light_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_level_chunk_with_light_packet.rs
@@ -1,4 +1,5 @@
-use packet_macros::{GamePacket, McBuf};
+use azalea_buf::McBuf;
+use packet_macros::GamePacket;
use super::clientbound_light_update_packet::ClientboundLightUpdatePacketData;
diff --git a/azalea-protocol/src/packets/game/clientbound_level_event_packet.rs b/azalea-protocol/src/packets/game/clientbound_level_event_packet.rs
index 70926268..42c5f412 100644
--- a/azalea-protocol/src/packets/game/clientbound_level_event_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_level_event_packet.rs
@@ -1,5 +1,6 @@
+use azalea_buf::McBuf;
use azalea_core::BlockPos;
-use packet_macros::{GamePacket, McBuf};
+use packet_macros::GamePacket;
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundLevelEventPacket {
diff --git a/azalea-protocol/src/packets/game/clientbound_level_particles_packet.rs b/azalea-protocol/src/packets/game/clientbound_level_particles_packet.rs
index 9ed08d8a..df1174b7 100644
--- a/azalea-protocol/src/packets/game/clientbound_level_particles_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_level_particles_packet.rs
@@ -1,5 +1,5 @@
-use crate::mc_buf::McBufVarReadable;
-use crate::mc_buf::{McBufReadable, McBufWritable, ParticleData};
+use azalea_buf::{McBufReadable, McBufVarReadable, McBufWritable};
+use azalea_core::ParticleData;
use packet_macros::GamePacket;
use std::io::{Read, Write};
diff --git a/azalea-protocol/src/packets/game/clientbound_light_update_packet.rs b/azalea-protocol/src/packets/game/clientbound_light_update_packet.rs
index f04987ac..adb6e33b 100644
--- a/azalea-protocol/src/packets/game/clientbound_light_update_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_light_update_packet.rs
@@ -1,5 +1,6 @@
-use crate::mc_buf::BitSet;
-use packet_macros::{GamePacket, McBuf};
+use azalea_buf::BitSet;
+use azalea_buf::McBuf;
+use packet_macros::GamePacket;
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundLightUpdatePacket {
diff --git a/azalea-protocol/src/packets/game/clientbound_login_packet.rs b/azalea-protocol/src/packets/game/clientbound_login_packet.rs
index 6ddc6b5a..6b144bac 100755
--- a/azalea-protocol/src/packets/game/clientbound_login_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_login_packet.rs
@@ -1,12 +1,13 @@
-use azalea_core::{game_type::GameType, resource_location::ResourceLocation, GlobalPos};
-use packet_macros::{GamePacket, McBuf};
+use azalea_buf::McBuf;
+use azalea_core::{GameType, GlobalPos, OptionalGameType, ResourceLocation};
+use packet_macros::GamePacket;
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundLoginPacket {
pub player_id: u32,
pub hardcore: bool,
pub game_type: GameType,
- pub previous_game_type: Option<GameType>,
+ pub previous_game_type: OptionalGameType,
pub levels: Vec<ResourceLocation>,
pub registry_holder: azalea_nbt::Tag,
pub dimension_type: ResourceLocation,
diff --git a/azalea-protocol/src/packets/game/clientbound_move_entity_pos_packet.rs b/azalea-protocol/src/packets/game/clientbound_move_entity_pos_packet.rs
index 0fc0104a..cd3e3148 100644
--- a/azalea-protocol/src/packets/game/clientbound_move_entity_pos_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_move_entity_pos_packet.rs
@@ -1,11 +1,11 @@
-use packet_macros::{GamePacket, McBuf};
+use azalea_buf::McBuf;
+use azalea_core::PositionDelta8;
+use packet_macros::GamePacket;
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundMoveEntityPosPacket {
#[var]
- pub entity_id: i32,
- pub xa: i16,
- pub ya: i16,
- pub za: i16,
+ pub entity_id: u32,
+ pub delta: PositionDelta8,
pub on_ground: bool,
}
diff --git a/azalea-protocol/src/packets/game/clientbound_move_entity_posrot_packet.rs b/azalea-protocol/src/packets/game/clientbound_move_entity_posrot_packet.rs
index 5fde1b93..e3422ac0 100644
--- a/azalea-protocol/src/packets/game/clientbound_move_entity_posrot_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_move_entity_posrot_packet.rs
@@ -1,12 +1,13 @@
-use packet_macros::{GamePacket, McBuf};
+use azalea_buf::McBuf;
+use azalea_core::PositionDelta8;
+use packet_macros::GamePacket;
+/// This packet is sent by the server when an entity moves less then 8 blocks.
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundMoveEntityPosRotPacket {
#[var]
- pub entity_id: i32,
- pub xa: i16,
- pub ya: i16,
- pub za: i16,
+ pub entity_id: u32,
+ pub delta: PositionDelta8,
pub y_rot: i8,
pub x_rot: i8,
pub on_ground: bool,
diff --git a/azalea-protocol/src/packets/game/clientbound_move_entity_rot_packet.rs b/azalea-protocol/src/packets/game/clientbound_move_entity_rot_packet.rs
index c8d0170b..85515628 100644
--- a/azalea-protocol/src/packets/game/clientbound_move_entity_rot_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_move_entity_rot_packet.rs
@@ -1,4 +1,5 @@
-use packet_macros::{GamePacket, McBuf};
+use azalea_buf::McBuf;
+use packet_macros::GamePacket;
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundMoveEntityRotPacket {
diff --git a/azalea-protocol/src/packets/game/clientbound_player_abilities_packet.rs b/azalea-protocol/src/packets/game/clientbound_player_abilities_packet.rs
index c3387f7f..d351ab04 100755
--- a/azalea-protocol/src/packets/game/clientbound_player_abilities_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_player_abilities_packet.rs
@@ -1,5 +1,6 @@
-use crate::mc_buf::{McBufReadable, McBufWritable, Readable};
-use packet_macros::{GamePacket, McBuf};
+use azalea_buf::McBuf;
+use azalea_buf::{McBufReadable, McBufWritable, Readable};
+use packet_macros::GamePacket;
use std::io::{Read, Write};
#[derive(Clone, Debug, McBuf, GamePacket)]
diff --git a/azalea-protocol/src/packets/game/clientbound_player_chat_packet.rs b/azalea-protocol/src/packets/game/clientbound_player_chat_packet.rs
index e6941f25..4aac93f4 100644
--- a/azalea-protocol/src/packets/game/clientbound_player_chat_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_player_chat_packet.rs
@@ -1,6 +1,7 @@
+use azalea_buf::McBuf;
use azalea_chat::component::Component;
use azalea_crypto::SaltSignaturePair;
-use packet_macros::{GamePacket, McBuf};
+use packet_macros::GamePacket;
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundPlayerChatPacket {
diff --git a/azalea-protocol/src/packets/game/clientbound_player_info_packet.rs b/azalea-protocol/src/packets/game/clientbound_player_info_packet.rs
index cb17f1f5..f216fde8 100644
--- a/azalea-protocol/src/packets/game/clientbound_player_info_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_player_info_packet.rs
@@ -1,6 +1,7 @@
-use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable};
+use azalea_buf::McBuf;
+use azalea_buf::{McBufReadable, McBufWritable, Readable, Writable};
use azalea_chat::component::Component;
-use packet_macros::{GamePacket, McBuf};
+use packet_macros::GamePacket;
use std::io::{Read, Write};
use uuid::Uuid;
diff --git a/azalea-protocol/src/packets/game/clientbound_player_position_packet.rs b/azalea-protocol/src/packets/game/clientbound_player_position_packet.rs
index 0457269a..29f7c1a3 100644
--- a/azalea-protocol/src/packets/game/clientbound_player_position_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_player_position_packet.rs
@@ -1,5 +1,6 @@
-use crate::mc_buf::{McBufReadable, McBufWritable, Readable};
-use packet_macros::{GamePacket, McBuf};
+use azalea_buf::McBuf;
+use azalea_buf::{McBufReadable, McBufWritable, Readable};
+use packet_macros::GamePacket;
use std::io::{Read, Write};
#[derive(Clone, Debug, McBuf, GamePacket)]
@@ -13,7 +14,7 @@ pub struct ClientboundPlayerPositionPacket {
/// Client should confirm this packet with Teleport Confirm containing the
/// same Teleport ID.
#[var]
- pub id: i32,
+ pub id: u32,
pub dismount_vehicle: bool,
}
diff --git a/azalea-protocol/src/packets/game/clientbound_recipe_packet.rs b/azalea-protocol/src/packets/game/clientbound_recipe_packet.rs
index e76504cc..a79bfcf1 100644
--- a/azalea-protocol/src/packets/game/clientbound_recipe_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_recipe_packet.rs
@@ -1,6 +1,7 @@
-use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable};
-use azalea_core::resource_location::ResourceLocation;
-use packet_macros::{GamePacket, McBuf};
+use azalea_buf::McBuf;
+use azalea_buf::{McBufReadable, McBufWritable, Readable, Writable};
+use azalea_core::ResourceLocation;
+use packet_macros::GamePacket;
use std::io::{Read, Write};
#[derive(Clone, Debug, McBuf, GamePacket)]
diff --git a/azalea-protocol/src/packets/game/clientbound_remove_entities_packet.rs b/azalea-protocol/src/packets/game/clientbound_remove_entities_packet.rs
index 8f51596d..8c76ec15 100644
--- a/azalea-protocol/src/packets/game/clientbound_remove_entities_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_remove_entities_packet.rs
@@ -1,4 +1,5 @@
-use packet_macros::{GamePacket, McBuf};
+use azalea_buf::McBuf;
+use packet_macros::GamePacket;
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundRemoveEntitiesPacket {
diff --git a/azalea-protocol/src/packets/game/clientbound_rotate_head_packet.rs b/azalea-protocol/src/packets/game/clientbound_rotate_head_packet.rs
index 71b485ae..dc7ec881 100644
--- a/azalea-protocol/src/packets/game/clientbound_rotate_head_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_rotate_head_packet.rs
@@ -1,4 +1,5 @@
-use packet_macros::{GamePacket, McBuf};
+use azalea_buf::McBuf;
+use packet_macros::GamePacket;
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundRotateHeadPacket {
diff --git a/azalea-protocol/src/packets/game/clientbound_section_blocks_update_packet.rs b/azalea-protocol/src/packets/game/clientbound_section_blocks_update_packet.rs
index 6c429edb..6ee27ed1 100644
--- a/azalea-protocol/src/packets/game/clientbound_section_blocks_update_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_section_blocks_update_packet.rs
@@ -1,6 +1,7 @@
-use crate::mc_buf::{McBufReadable, McBufVarReadable, McBufVarWritable, McBufWritable};
+use azalea_buf::McBuf;
+use azalea_buf::{McBufReadable, McBufVarReadable, McBufVarWritable, McBufWritable};
use azalea_core::{ChunkSectionBlockPos, ChunkSectionPos};
-use packet_macros::{GamePacket, McBuf};
+use packet_macros::GamePacket;
use std::io::{Read, Write};
#[derive(Clone, Debug, McBuf, GamePacket)]
diff --git a/azalea-protocol/src/packets/game/clientbound_server_data_packet.rs b/azalea-protocol/src/packets/game/clientbound_server_data_packet.rs
index 4c2d94e6..1dddfc1e 100644
--- a/azalea-protocol/src/packets/game/clientbound_server_data_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_server_data_packet.rs
@@ -1,5 +1,6 @@
+use azalea_buf::McBuf;
use azalea_chat::component::Component;
-use packet_macros::{GamePacket, McBuf};
+use packet_macros::GamePacket;
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundServerDataPacket {
diff --git a/azalea-protocol/src/packets/game/clientbound_set_carried_item_packet.rs b/azalea-protocol/src/packets/game/clientbound_set_carried_item_packet.rs
index 003b6ccc..a4ecaaab 100755
--- a/azalea-protocol/src/packets/game/clientbound_set_carried_item_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_set_carried_item_packet.rs
@@ -1,4 +1,5 @@
-use packet_macros::{GamePacket, McBuf};
+use azalea_buf::McBuf;
+use packet_macros::GamePacket;
/// Sent to change the player's slot selection.
#[derive(Clone, Debug, McBuf, GamePacket)]
diff --git a/azalea-protocol/src/packets/game/clientbound_set_chunk_cache_center_packet.rs b/azalea-protocol/src/packets/game/clientbound_set_chunk_cache_center_packet.rs
index 7557c16b..ee86ec9d 100644
--- a/azalea-protocol/src/packets/game/clientbound_set_chunk_cache_center_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_set_chunk_cache_center_packet.rs
@@ -1,4 +1,5 @@
-use packet_macros::{GamePacket, McBuf};
+use azalea_buf::McBuf;
+use packet_macros::GamePacket;
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundSetChunkCacheCenterPacket {
diff --git a/azalea-protocol/src/packets/game/clientbound_set_default_spawn_position_packet.rs b/azalea-protocol/src/packets/game/clientbound_set_default_spawn_position_packet.rs
index 7ac42c5c..9e9a7b87 100644
--- a/azalea-protocol/src/packets/game/clientbound_set_default_spawn_position_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_set_default_spawn_position_packet.rs
@@ -1,5 +1,6 @@
+use azalea_buf::McBuf;
use azalea_core::BlockPos;
-use packet_macros::{GamePacket, McBuf};
+use packet_macros::GamePacket;
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundSetDefaultSpawnPositionPacket {
diff --git a/azalea-protocol/src/packets/game/clientbound_set_display_chat_preview_packet.rs b/azalea-protocol/src/packets/game/clientbound_set_display_chat_preview_packet.rs
index 46a0d582..8e2cfe70 100644
--- a/azalea-protocol/src/packets/game/clientbound_set_display_chat_preview_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_set_display_chat_preview_packet.rs
@@ -1,4 +1,5 @@
-use packet_macros::{GamePacket, McBuf};
+use azalea_buf::McBuf;
+use packet_macros::GamePacket;
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundSetDisplayChatPreviewPacket {
diff --git a/azalea-protocol/src/packets/game/clientbound_set_entity_data_packet.rs b/azalea-protocol/src/packets/game/clientbound_set_entity_data_packet.rs
index 8a568689..8cbd6f9b 100644
--- a/azalea-protocol/src/packets/game/clientbound_set_entity_data_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_set_entity_data_packet.rs
@@ -1,9 +1,10 @@
-use crate::mc_buf::EntityMetadata;
-use packet_macros::{GamePacket, McBuf};
+use azalea_buf::McBuf;
+use azalea_entity::EntityMetadata;
+use packet_macros::GamePacket;
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundSetEntityDataPacket {
#[var]
- pub id: i32,
+ pub id: u32,
pub metadata: EntityMetadata,
}
diff --git a/azalea-protocol/src/packets/game/clientbound_set_entity_link_packet.rs b/azalea-protocol/src/packets/game/clientbound_set_entity_link_packet.rs
index e6e3af67..ec1ee0ec 100644
--- a/azalea-protocol/src/packets/game/clientbound_set_entity_link_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_set_entity_link_packet.rs
@@ -1,4 +1,5 @@
-use packet_macros::{GamePacket, McBuf};
+use azalea_buf::McBuf;
+use packet_macros::GamePacket;
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundSetEntityLinkPacket {
diff --git a/azalea-protocol/src/packets/game/clientbound_set_equipment_packet.rs b/azalea-protocol/src/packets/game/clientbound_set_equipment_packet.rs
index 3acbd58f..aa352189 100644
--- a/azalea-protocol/src/packets/game/clientbound_set_equipment_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_set_equipment_packet.rs
@@ -1,7 +1,8 @@
+use azalea_buf::McBuf;
use azalea_core::Slot;
-use packet_macros::{GamePacket, McBuf};
+use packet_macros::GamePacket;
-use crate::mc_buf::{McBufReadable, McBufWritable};
+use azalea_buf::{McBufReadable, McBufWritable};
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundSetEquipmentPacket {
diff --git a/azalea-protocol/src/packets/game/clientbound_set_experience_packet.rs b/azalea-protocol/src/packets/game/clientbound_set_experience_packet.rs
index bcb6393d..7387f6dc 100644
--- a/azalea-protocol/src/packets/game/clientbound_set_experience_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_set_experience_packet.rs
@@ -1,4 +1,5 @@
-use packet_macros::{GamePacket, McBuf};
+use azalea_buf::McBuf;
+use packet_macros::GamePacket;
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundSetExperiencePacket {
diff --git a/azalea-protocol/src/packets/game/clientbound_set_health_packet.rs b/azalea-protocol/src/packets/game/clientbound_set_health_packet.rs
index 6c75cf63..b99fe86a 100644
--- a/azalea-protocol/src/packets/game/clientbound_set_health_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_set_health_packet.rs
@@ -1,4 +1,5 @@
-use packet_macros::{GamePacket, McBuf};
+use azalea_buf::McBuf;
+use packet_macros::GamePacket;
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundSetHealthPacket {
diff --git a/azalea-protocol/src/packets/game/clientbound_set_time_packet.rs b/azalea-protocol/src/packets/game/clientbound_set_time_packet.rs
index 4cad0693..ea4437b7 100644
--- a/azalea-protocol/src/packets/game/clientbound_set_time_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_set_time_packet.rs
@@ -1,4 +1,5 @@
-use packet_macros::{GamePacket, McBuf};
+use azalea_buf::McBuf;
+use packet_macros::GamePacket;
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundSetTimePacket {
diff --git a/azalea-protocol/src/packets/game/clientbound_sound_packet.rs b/azalea-protocol/src/packets/game/clientbound_sound_packet.rs
index fbc5830b..a8607599 100644
--- a/azalea-protocol/src/packets/game/clientbound_sound_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_sound_packet.rs
@@ -1,4 +1,5 @@
-use packet_macros::{GamePacket, McBuf};
+use azalea_buf::McBuf;
+use packet_macros::GamePacket;
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundSoundPacket {
diff --git a/azalea-protocol/src/packets/game/clientbound_system_chat_packet.rs b/azalea-protocol/src/packets/game/clientbound_system_chat_packet.rs
index dfa75a5b..c531fa1e 100644
--- a/azalea-protocol/src/packets/game/clientbound_system_chat_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_system_chat_packet.rs
@@ -1,5 +1,6 @@
+use azalea_buf::McBuf;
use azalea_chat::component::Component;
-use packet_macros::{GamePacket, McBuf};
+use packet_macros::GamePacket;
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundSystemChatPacket {
diff --git a/azalea-protocol/src/packets/game/clientbound_teleport_entity_packet.rs b/azalea-protocol/src/packets/game/clientbound_teleport_entity_packet.rs
index c10db7b9..433b0727 100644
--- a/azalea-protocol/src/packets/game/clientbound_teleport_entity_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_teleport_entity_packet.rs
@@ -1,4 +1,5 @@
-use packet_macros::{GamePacket, McBuf};
+use azalea_buf::McBuf;
+use packet_macros::GamePacket;
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundTeleportEntityPacket {
diff --git a/azalea-protocol/src/packets/game/clientbound_update_advancements_packet.rs b/azalea-protocol/src/packets/game/clientbound_update_advancements_packet.rs
index daa1ac93..43e4d69f 100644
--- a/azalea-protocol/src/packets/game/clientbound_update_advancements_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_update_advancements_packet.rs
@@ -1,7 +1,7 @@
-use crate::packets::{McBufReadable, McBufWritable};
+use azalea_buf::{McBuf, McBufReadable, McBufWritable};
use azalea_chat::component::Component;
-use azalea_core::{resource_location::ResourceLocation, Slot};
-use packet_macros::{GamePacket, McBuf};
+use azalea_core::{ResourceLocation, Slot};
+use packet_macros::GamePacket;
use std::{
collections::HashMap,
io::{Read, Write},
diff --git a/azalea-protocol/src/packets/game/clientbound_update_attributes_packet.rs b/azalea-protocol/src/packets/game/clientbound_update_attributes_packet.rs
index d0e7c9ee..3eca2a84 100644
--- a/azalea-protocol/src/packets/game/clientbound_update_attributes_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_update_attributes_packet.rs
@@ -1,6 +1,7 @@
-use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable};
-use azalea_core::resource_location::ResourceLocation;
-use packet_macros::{GamePacket, McBuf};
+use azalea_buf::McBuf;
+use azalea_buf::{McBufReadable, McBufWritable, Readable, Writable};
+use azalea_core::ResourceLocation;
+use packet_macros::GamePacket;
use std::io::{Read, Write};
use uuid::Uuid;
diff --git a/azalea-protocol/src/packets/game/clientbound_update_mob_effect_packet.rs b/azalea-protocol/src/packets/game/clientbound_update_mob_effect_packet.rs
new file mode 100644
index 00000000..5a446c2f
--- /dev/null
+++ b/azalea-protocol/src/packets/game/clientbound_update_mob_effect_packet.rs
@@ -0,0 +1,16 @@
+use azalea_buf::McBuf;
+use packet_macros::GamePacket;
+
+#[derive(Clone, Debug, McBuf, GamePacket)]
+pub struct ClientboundUpdateMobEffectPacket {
+ #[var]
+ pub entity_id: u32,
+ // TODO: have an enum for this
+ #[var]
+ pub effect: u32,
+ pub effect_amplifier: u8,
+ #[var]
+ pub effect_duration_ticks: u32,
+ pub flags: u8,
+ pub factor_data: Option<azalea_nbt::Tag>,
+}
diff --git a/azalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs b/azalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs
index 27839919..05d57695 100644
--- a/azalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs
@@ -1,9 +1,10 @@
use std::io::{Read, Write};
-use azalea_core::{resource_location::ResourceLocation, Slot};
-use packet_macros::{GamePacket, McBuf};
+use azalea_buf::McBuf;
+use azalea_core::{ResourceLocation, Slot};
+use packet_macros::GamePacket;
-use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable};
+use azalea_buf::{McBufReadable, McBufWritable, Readable, Writable};
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundUpdateRecipesPacket {
@@ -129,8 +130,8 @@ impl McBufWritable for Recipe {
impl McBufReadable for Recipe {
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
- let recipe_type = buf.read_resource_location()?;
- let identifier = buf.read_resource_location()?;
+ let recipe_type = ResourceLocation::read_into(buf)?;
+ let identifier = ResourceLocation::read_into(buf)?;
// rust doesn't let us match ResourceLocation so we have to do a big
// if-else chain :(
diff --git a/azalea-protocol/src/packets/game/clientbound_update_tags_packet.rs b/azalea-protocol/src/packets/game/clientbound_update_tags_packet.rs
index 60794f03..cf3bc069 100755
--- a/azalea-protocol/src/packets/game/clientbound_update_tags_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_update_tags_packet.rs
@@ -1,6 +1,8 @@
-use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable};
-use azalea_core::resource_location::ResourceLocation;
-use packet_macros::{GamePacket, McBuf};
+use azalea_buf::McBuf;
+use azalea_buf::{McBufReadable, McBufWritable, Readable, Writable};
+use azalea_core::ResourceLocation;
+use packet_macros::GamePacket;
+use std::ops::Deref;
use std::{
collections::HashMap,
io::{Read, Write},
@@ -8,7 +10,7 @@ use std::{
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundUpdateTagsPacket {
- pub tags: HashMap<ResourceLocation, Vec<Tags>>,
+ pub tags: TagMap,
}
#[derive(Clone, Debug)]
@@ -17,12 +19,15 @@ pub struct Tags {
pub elements: Vec<i32>,
}
-impl McBufReadable for HashMap<ResourceLocation, Vec<Tags>> {
+#[derive(Clone, Debug)]
+pub struct TagMap(HashMap<ResourceLocation, Vec<Tags>>);
+
+impl McBufReadable for TagMap {
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
let length = buf.read_varint()? as usize;
let mut data = HashMap::with_capacity(length);
for _ in 0..length {
- let tag_type = buf.read_resource_location()?;
+ let tag_type = ResourceLocation::read_into(buf)?;
let tags_count = buf.read_varint()? as usize;
let mut tags_vec = Vec::with_capacity(tags_count);
for _ in 0..tags_count {
@@ -31,14 +36,14 @@ impl McBufReadable for HashMap<ResourceLocation, Vec<Tags>> {
}
data.insert(tag_type, tags_vec);
}
- Ok(data)
+ Ok(TagMap(data))
}
}
-impl McBufWritable for HashMap<ResourceLocation, Vec<Tags>> {
+impl McBufWritable for TagMap {
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
buf.write_varint(self.len() as i32)?;
- for (k, v) in self {
+ for (k, v) in &self.0 {
k.write_into(buf)?;
v.write_into(buf)?;
}
@@ -47,7 +52,7 @@ impl McBufWritable for HashMap<ResourceLocation, Vec<Tags>> {
}
impl McBufReadable for Tags {
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
- let name = buf.read_resource_location()?;
+ let name = ResourceLocation::read_into(buf)?;
let elements = buf.read_int_id_list()?;
Ok(Tags { name, elements })
}
@@ -60,3 +65,11 @@ impl McBufWritable for Tags {
Ok(())
}
}
+
+impl Deref for TagMap {
+ type Target = HashMap<ResourceLocation, Vec<Tags>>;
+
+ fn deref(&self) -> &Self::Target {
+ &self.0
+ }
+}
diff --git a/azalea-protocol/src/packets/game/clientbound_update_view_distance_packet.rs b/azalea-protocol/src/packets/game/clientbound_update_view_distance_packet.rs
index 8288bd73..c0c40f75 100755
--- a/azalea-protocol/src/packets/game/clientbound_update_view_distance_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_update_view_distance_packet.rs
@@ -1,4 +1,5 @@
-use packet_macros::{GamePacket, McBuf};
+use azalea_buf::McBuf;
+use packet_macros::GamePacket;
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ClientboundUpdateViewDistancePacket {
diff --git a/azalea-protocol/src/packets/game/mod.rs b/azalea-protocol/src/packets/game/mod.rs
index c4435636..f407a697 100755
--- a/azalea-protocol/src/packets/game/mod.rs
+++ b/azalea-protocol/src/packets/game/mod.rs
@@ -46,23 +46,34 @@ pub mod clientbound_system_chat_packet;
pub mod clientbound_teleport_entity_packet;
pub mod clientbound_update_advancements_packet;
pub mod clientbound_update_attributes_packet;
+pub mod clientbound_update_mob_effect_packet;
pub mod clientbound_update_recipes_packet;
pub mod clientbound_update_tags_packet;
pub mod clientbound_update_view_distance_packet;
+pub mod serverbound_accept_teleportation_packet;
pub mod serverbound_chat_command_packet;
pub mod serverbound_chat_preview_packet;
pub mod serverbound_custom_payload_packet;
pub mod serverbound_keep_alive_packet;
+pub mod serverbound_move_player_packet_pos;
+pub mod serverbound_move_player_packet_pos_rot;
+pub mod serverbound_move_player_packet_rot;
+pub mod serverbound_move_player_packet_status_only;
use packet_macros::declare_state_packets;
declare_state_packets!(
GamePacket,
Serverbound => {
+ 0x00: serverbound_accept_teleportation_packet::ServerboundAcceptTeleportationPacket,
0x03: serverbound_chat_command_packet::ServerboundChatCommandPacket,
0x05: serverbound_chat_preview_packet::ServerboundChatPreviewPacket,
0x0c: serverbound_custom_payload_packet::ServerboundCustomPayloadPacket,
0x11: serverbound_keep_alive_packet::ServerboundKeepAlivePacket,
+ 0x13: serverbound_move_player_packet_pos::ServerboundMovePlayerPacketPos,
+ 0x14: serverbound_move_player_packet_pos_rot::ServerboundMovePlayerPacketPosRot,
+ 0x15: serverbound_move_player_packet_rot::ServerboundMovePlayerPacketRot,
+ 0x16: serverbound_move_player_packet_status_only::ServerboundMovePlayerPacketStatusOnly,
},
Clientbound => {
0x00: clientbound_add_entity_packet::ClientboundAddEntityPacket,
@@ -97,13 +108,13 @@ declare_state_packets!(
0x3c: clientbound_rotate_head_packet::ClientboundRotateHeadPacket,
0x3d: clientbound_section_blocks_update_packet::ClientboundSectionBlocksUpdatePacket,
0x3f: clientbound_server_data_packet::ClientboundServerDataPacket,
- 0x44: clientbound_set_entity_link_packet::ClientboundSetEntityLinkPacket,
0x47: clientbound_set_carried_item_packet::ClientboundSetCarriedItemPacket,
0x48: clientbound_set_chunk_cache_center_packet::ClientboundSetChunkCacheCenterPacket,
0x49: clientbound_update_view_distance_packet::ClientboundUpdateViewDistancePacket,
0x4a: clientbound_set_default_spawn_position_packet::ClientboundSetDefaultSpawnPositionPacket,
0x4b: clientbound_set_display_chat_preview_packet::ClientboundSetDisplayChatPreviewPacket,
0x4d: clientbound_set_entity_data_packet::ClientboundSetEntityDataPacket,
+ 0x4e: clientbound_set_entity_link_packet::ClientboundSetEntityLinkPacket,
0x4f: clientbound_entity_velocity_packet::ClientboundEntityVelocityPacket,
0x50: clientbound_set_equipment_packet::ClientboundSetEquipmentPacket,
0x51: clientbound_set_experience_packet::ClientboundSetExperiencePacket,
@@ -114,6 +125,7 @@ declare_state_packets!(
0x63: clientbound_teleport_entity_packet::ClientboundTeleportEntityPacket,
0x64: clientbound_update_advancements_packet::ClientboundUpdateAdvancementsPacket,
0x65: clientbound_update_attributes_packet::ClientboundUpdateAttributesPacket,
+ 0x66: clientbound_update_mob_effect_packet::ClientboundUpdateMobEffectPacket,
0x67: clientbound_update_recipes_packet::ClientboundUpdateRecipesPacket,
0x68: clientbound_update_tags_packet::ClientboundUpdateTagsPacket,
}
diff --git a/azalea-protocol/src/packets/game/serverbound_accept_teleportation_packet.rs b/azalea-protocol/src/packets/game/serverbound_accept_teleportation_packet.rs
new file mode 100644
index 00000000..98a9f728
--- /dev/null
+++ b/azalea-protocol/src/packets/game/serverbound_accept_teleportation_packet.rs
@@ -0,0 +1,8 @@
+use azalea_buf::McBuf;
+use packet_macros::GamePacket;
+
+#[derive(Clone, Debug, McBuf, GamePacket)]
+pub struct ServerboundAcceptTeleportationPacket {
+ #[var]
+ pub id: u32,
+}
diff --git a/azalea-protocol/src/packets/game/serverbound_chat_command_packet.rs b/azalea-protocol/src/packets/game/serverbound_chat_command_packet.rs
index 9ae0b79f..6371463b 100644
--- a/azalea-protocol/src/packets/game/serverbound_chat_command_packet.rs
+++ b/azalea-protocol/src/packets/game/serverbound_chat_command_packet.rs
@@ -1,6 +1,7 @@
use std::collections::HashMap;
-use packet_macros::{GamePacket, McBuf};
+use azalea_buf::McBuf;
+use packet_macros::GamePacket;
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ServerboundChatCommandPacket {
diff --git a/azalea-protocol/src/packets/game/serverbound_chat_preview_packet.rs b/azalea-protocol/src/packets/game/serverbound_chat_preview_packet.rs
index 60535f69..32711d45 100644
--- a/azalea-protocol/src/packets/game/serverbound_chat_preview_packet.rs
+++ b/azalea-protocol/src/packets/game/serverbound_chat_preview_packet.rs
@@ -1,4 +1,5 @@
-use packet_macros::{GamePacket, McBuf};
+use azalea_buf::McBuf;
+use packet_macros::GamePacket;
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ServerboundChatPreviewPacket {
diff --git a/azalea-protocol/src/packets/game/serverbound_custom_payload_packet.rs b/azalea-protocol/src/packets/game/serverbound_custom_payload_packet.rs
index bef25b59..eecb920b 100644
--- a/azalea-protocol/src/packets/game/serverbound_custom_payload_packet.rs
+++ b/azalea-protocol/src/packets/game/serverbound_custom_payload_packet.rs
@@ -1,6 +1,7 @@
-use crate::mc_buf::UnsizedByteArray;
-use azalea_core::resource_location::ResourceLocation;
-use packet_macros::{GamePacket, McBuf};
+use azalea_buf::McBuf;
+use azalea_buf::UnsizedByteArray;
+use azalea_core::ResourceLocation;
+use packet_macros::GamePacket;
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ServerboundCustomPayloadPacket {
diff --git a/azalea-protocol/src/packets/game/serverbound_keep_alive_packet.rs b/azalea-protocol/src/packets/game/serverbound_keep_alive_packet.rs
index c430499e..1edc5a52 100644
--- a/azalea-protocol/src/packets/game/serverbound_keep_alive_packet.rs
+++ b/azalea-protocol/src/packets/game/serverbound_keep_alive_packet.rs
@@ -1,4 +1,5 @@
-use packet_macros::{GamePacket, McBuf};
+use azalea_buf::McBuf;
+use packet_macros::GamePacket;
#[derive(Clone, Debug, McBuf, GamePacket)]
pub struct ServerboundKeepAlivePacket {
diff --git a/azalea-protocol/src/packets/game/serverbound_move_player_packet_pos.rs b/azalea-protocol/src/packets/game/serverbound_move_player_packet_pos.rs
new file mode 100644
index 00000000..23f4050e
--- /dev/null
+++ b/azalea-protocol/src/packets/game/serverbound_move_player_packet_pos.rs
@@ -0,0 +1,10 @@
+use azalea_buf::McBuf;
+use packet_macros::GamePacket;
+
+#[derive(Clone, Debug, McBuf, GamePacket)]
+pub struct ServerboundMovePlayerPacketPos {
+ pub x: f64,
+ pub y: f64,
+ pub z: f64,
+ pub on_ground: bool,
+}
diff --git a/azalea-protocol/src/packets/game/serverbound_move_player_packet_pos_rot.rs b/azalea-protocol/src/packets/game/serverbound_move_player_packet_pos_rot.rs
new file mode 100644
index 00000000..9416461c
--- /dev/null
+++ b/azalea-protocol/src/packets/game/serverbound_move_player_packet_pos_rot.rs
@@ -0,0 +1,12 @@
+use azalea_buf::McBuf;
+use packet_macros::GamePacket;
+
+#[derive(Clone, Debug, McBuf, GamePacket)]
+pub struct ServerboundMovePlayerPacketPosRot {
+ pub x: f64,
+ pub y: f64,
+ pub z: f64,
+ pub y_rot: f32,
+ pub x_rot: f32,
+ pub on_ground: bool,
+}
diff --git a/azalea-protocol/src/packets/game/serverbound_move_player_packet_rot.rs b/azalea-protocol/src/packets/game/serverbound_move_player_packet_rot.rs
new file mode 100644
index 00000000..0952483a
--- /dev/null
+++ b/azalea-protocol/src/packets/game/serverbound_move_player_packet_rot.rs
@@ -0,0 +1,9 @@
+use azalea_buf::McBuf;
+use packet_macros::GamePacket;
+
+#[derive(Clone, Debug, McBuf, GamePacket)]
+pub struct ServerboundMovePlayerPacketRot {
+ pub y_rot: f32,
+ pub x_rot: f32,
+ pub on_ground: bool,
+}
diff --git a/azalea-protocol/src/packets/game/serverbound_move_player_packet_status_only.rs b/azalea-protocol/src/packets/game/serverbound_move_player_packet_status_only.rs
new file mode 100644
index 00000000..fb765c27
--- /dev/null
+++ b/azalea-protocol/src/packets/game/serverbound_move_player_packet_status_only.rs
@@ -0,0 +1,7 @@
+use azalea_buf::McBuf;
+use packet_macros::GamePacket;
+
+#[derive(Clone, Debug, McBuf, GamePacket)]
+pub struct ServerboundMovePlayerPacketStatusOnly {
+ pub on_ground: bool,
+}
diff --git a/azalea-protocol/src/packets/handshake/client_intention_packet.rs b/azalea-protocol/src/packets/handshake/client_intention_packet.rs
index 410c11ab..5f1987e2 100755
--- a/azalea-protocol/src/packets/handshake/client_intention_packet.rs
+++ b/azalea-protocol/src/packets/handshake/client_intention_packet.rs
@@ -1,5 +1,6 @@
use crate::packets::ConnectionProtocol;
-use packet_macros::{HandshakePacket, McBuf};
+use azalea_buf::McBuf;
+use packet_macros::HandshakePacket;
use std::hash::Hash;
#[derive(Hash, Clone, Debug, McBuf, HandshakePacket)]
diff --git a/azalea-protocol/src/packets/login/clientbound_custom_query_packet.rs b/azalea-protocol/src/packets/login/clientbound_custom_query_packet.rs
index 1b1da87a..05310fb0 100755
--- a/azalea-protocol/src/packets/login/clientbound_custom_query_packet.rs
+++ b/azalea-protocol/src/packets/login/clientbound_custom_query_packet.rs
@@ -1,6 +1,6 @@
-use crate::mc_buf::UnsizedByteArray;
-use azalea_core::resource_location::ResourceLocation;
-use packet_macros::{LoginPacket, McBuf};
+use azalea_buf::{McBuf, UnsizedByteArray};
+use azalea_core::ResourceLocation;
+use packet_macros::LoginPacket;
use std::hash::Hash;
#[derive(Hash, Clone, Debug, McBuf, LoginPacket)]
diff --git a/azalea-protocol/src/packets/login/clientbound_game_profile_packet.rs b/azalea-protocol/src/packets/login/clientbound_game_profile_packet.rs
index dd11f7f7..bd2edf38 100755
--- a/azalea-protocol/src/packets/login/clientbound_game_profile_packet.rs
+++ b/azalea-protocol/src/packets/login/clientbound_game_profile_packet.rs
@@ -1,10 +1,8 @@
use std::io::{Read, Write};
use super::LoginPacket;
-use crate::mc_buf::McBufReadable;
-use crate::mc_buf::{Readable, Writable};
use azalea_auth::game_profile::GameProfile;
-use azalea_core::serializable_uuid::SerializableUuid;
+use azalea_buf::{McBufReadable, Readable, SerializableUuid, Writable};
use uuid::Uuid;
#[derive(Clone, Debug)]
diff --git a/azalea-protocol/src/packets/login/clientbound_hello_packet.rs b/azalea-protocol/src/packets/login/clientbound_hello_packet.rs
index 58d48ffe..f3724c18 100755
--- a/azalea-protocol/src/packets/login/clientbound_hello_packet.rs
+++ b/azalea-protocol/src/packets/login/clientbound_hello_packet.rs
@@ -1,5 +1,5 @@
+use azalea_buf::McBuf;
use packet_macros::LoginPacket;
-use packet_macros::McBuf;
#[derive(Clone, Debug, McBuf, LoginPacket)]
pub struct ClientboundHelloPacket {
diff --git a/azalea-protocol/src/packets/login/clientbound_login_compression_packet.rs b/azalea-protocol/src/packets/login/clientbound_login_compression_packet.rs
index b1323f50..19b2d58e 100755
--- a/azalea-protocol/src/packets/login/clientbound_login_compression_packet.rs
+++ b/azalea-protocol/src/packets/login/clientbound_login_compression_packet.rs
@@ -3,7 +3,7 @@ use std::{
io::{Read, Write},
};
-use crate::mc_buf::{Readable, Writable};
+use azalea_buf::{Readable, Writable};
use super::LoginPacket;
diff --git a/azalea-protocol/src/packets/login/clientbound_login_disconnect_packet.rs b/azalea-protocol/src/packets/login/clientbound_login_disconnect_packet.rs
index 9ab09e3b..acc68c82 100644
--- a/azalea-protocol/src/packets/login/clientbound_login_disconnect_packet.rs
+++ b/azalea-protocol/src/packets/login/clientbound_login_disconnect_packet.rs
@@ -1,5 +1,6 @@
+use azalea_buf::McBuf;
use azalea_chat::component::Component;
-use packet_macros::{LoginPacket, McBuf};
+use packet_macros::LoginPacket;
#[derive(Clone, Debug, McBuf, LoginPacket)]
pub struct ClientboundLoginDisconnectPacket {
diff --git a/azalea-protocol/src/packets/login/serverbound_hello_packet.rs b/azalea-protocol/src/packets/login/serverbound_hello_packet.rs
index bed93f04..57a3e4d8 100755
--- a/azalea-protocol/src/packets/login/serverbound_hello_packet.rs
+++ b/azalea-protocol/src/packets/login/serverbound_hello_packet.rs
@@ -1,4 +1,5 @@
-use packet_macros::{LoginPacket, McBuf};
+use azalea_buf::McBuf;
+use packet_macros::LoginPacket;
#[derive(Clone, Debug, McBuf, LoginPacket)]
pub struct ServerboundHelloPacket {
diff --git a/azalea-protocol/src/packets/login/serverbound_key_packet.rs b/azalea-protocol/src/packets/login/serverbound_key_packet.rs
index d57b122a..12b7c4ec 100644
--- a/azalea-protocol/src/packets/login/serverbound_key_packet.rs
+++ b/azalea-protocol/src/packets/login/serverbound_key_packet.rs
@@ -1,8 +1,9 @@
+use azalea_buf::McBuf;
use azalea_crypto::SaltSignaturePair;
-use packet_macros::{LoginPacket, McBuf};
+use packet_macros::LoginPacket;
use std::io::{Read, Write};
-use crate::mc_buf::{McBufReadable, McBufWritable};
+use azalea_buf::{McBufReadable, McBufWritable};
#[derive(Clone, Debug, McBuf, LoginPacket)]
pub struct ServerboundKeyPacket {
diff --git a/azalea-protocol/src/packets/mod.rs b/azalea-protocol/src/packets/mod.rs
index 73a3a842..b9116228 100755
--- a/azalea-protocol/src/packets/mod.rs
+++ b/azalea-protocol/src/packets/mod.rs
@@ -3,13 +3,12 @@ pub mod handshake;
pub mod login;
pub mod status;
+use crate::connect::PacketFlow;
+use azalea_buf::{McBufReadable, McBufWritable, Readable, Writable};
+use num_derive::FromPrimitive;
+use num_traits::FromPrimitive;
use std::io::{Read, Write};
-use crate::{
- connect::PacketFlow,
- mc_buf::{McBufReadable, McBufWritable, Readable, Writable},
-};
-
pub const PROTOCOL_VERSION: u32 = 759;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
@@ -53,7 +52,7 @@ where
fn write(&self, buf: &mut impl Write) -> Result<(), std::io::Error>;
}
-impl crate::mc_buf::McBufReadable for ConnectionProtocol {
+impl azalea_buf::McBufReadable for ConnectionProtocol {
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
ConnectionProtocol::from_i32(buf.read_varint()?)
.ok_or_else(|| "Invalid intention".to_string())
diff --git a/azalea-protocol/src/packets/status/clientbound_status_response_packet.rs b/azalea-protocol/src/packets/status/clientbound_status_response_packet.rs
index 2acdb8c2..e7fb4f2b 100755
--- a/azalea-protocol/src/packets/status/clientbound_status_response_packet.rs
+++ b/azalea-protocol/src/packets/status/clientbound_status_response_packet.rs
@@ -4,7 +4,7 @@ use azalea_chat::component::Component;
use serde::Deserialize;
use serde_json::Value;
-use crate::mc_buf::Readable;
+use azalea_buf::Readable;
use super::StatusPacket;
diff --git a/azalea-protocol/src/packets/status/serverbound_status_request_packet.rs b/azalea-protocol/src/packets/status/serverbound_status_request_packet.rs
index 3369e6a9..c19d7795 100755
--- a/azalea-protocol/src/packets/status/serverbound_status_request_packet.rs
+++ b/azalea-protocol/src/packets/status/serverbound_status_request_packet.rs
@@ -1,4 +1,5 @@
-use packet_macros::{McBuf, StatusPacket};
+use azalea_buf::McBuf;
+use packet_macros::StatusPacket;
#[derive(Clone, Debug, McBuf, StatusPacket)]
pub struct ServerboundStatusRequestPacket {}
diff --git a/azalea-protocol/src/read.rs b/azalea-protocol/src/read.rs
index b4ba17ea..e19b5538 100755
--- a/azalea-protocol/src/read.rs
+++ b/azalea-protocol/src/read.rs
@@ -1,8 +1,5 @@
-use crate::{
- connect::PacketFlow,
- mc_buf::{read_varint_async, Readable},
- packets::ProtocolPacket,
-};
+use crate::{connect::PacketFlow, packets::ProtocolPacket};
+use azalea_buf::{read_varint_async, Readable};
use azalea_crypto::Aes128CfbDec;
use flate2::read::ZlibDecoder;
use std::{
diff --git a/azalea-protocol/src/write.rs b/azalea-protocol/src/write.rs
index 9291681c..ae9a6829 100755
--- a/azalea-protocol/src/write.rs
+++ b/azalea-protocol/src/write.rs
@@ -1,5 +1,6 @@
-use crate::{mc_buf::Writable, packets::ProtocolPacket, read::MAXIMUM_UNCOMPRESSED_LENGTH};
+use crate::{packets::ProtocolPacket, read::MAXIMUM_UNCOMPRESSED_LENGTH};
use async_compression::tokio::bufread::ZlibEncoder;
+use azalea_buf::Writable;
use azalea_crypto::Aes128CfbEnc;
use std::fmt::Debug;
use tokio::io::{AsyncReadExt, AsyncWrite, AsyncWriteExt};