diff --git a/azalea-block/src/lib.rs b/azalea-block/src/lib.rs index 59db1579..a5d62ac7 100755 --- a/azalea-block/src/lib.rs +++ b/azalea-block/src/lib.rs @@ -11,7 +11,7 @@ use std::{ io::{Cursor, Write}, }; -use azalea_buf::{BufReadError, McBufReadable, McBufVarReadable, McBufVarWritable, McBufWritable}; +use azalea_buf::{BufReadError, AzaleaRead, AzaleaReadVar, AzaleaWriteVar, AzaleaWrite}; pub use behavior::BlockBehavior; pub use generated::{blocks, properties}; pub use range::BlockStates; @@ -80,7 +80,7 @@ impl TryFrom for BlockState { } } -impl McBufReadable for BlockState { +impl AzaleaRead for BlockState { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let state_id = u32::azalea_read_var(buf)?; Self::try_from(state_id).map_err(|_| BufReadError::UnexpectedEnumVariant { @@ -88,7 +88,7 @@ impl McBufReadable for BlockState { }) } } -impl McBufWritable for BlockState { +impl AzaleaWrite for BlockState { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { u32::azalea_write_var(&self.id, buf) } diff --git a/azalea-brigadier/src/suggestion/mod.rs b/azalea-brigadier/src/suggestion/mod.rs index 3cf9a426..a31b6837 100755 --- a/azalea-brigadier/src/suggestion/mod.rs +++ b/azalea-brigadier/src/suggestion/mod.rs @@ -9,7 +9,7 @@ use std::{ }; #[cfg(feature = "azalea-buf")] -use azalea_buf::McBufWritable; +use azalea_buf::AzaleaWrite; #[cfg(feature = "azalea-buf")] use azalea_chat::FormattedText; pub use suggestions::Suggestions; @@ -137,7 +137,7 @@ impl PartialOrd for SuggestionValue { } #[cfg(feature = "azalea-buf")] -impl McBufWritable for Suggestion { +impl AzaleaWrite for Suggestion { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { self.value.to_string().azalea_write(buf)?; self.tooltip diff --git a/azalea-brigadier/src/suggestion/suggestions.rs b/azalea-brigadier/src/suggestion/suggestions.rs index 4574d7fa..2eb904f2 100755 --- a/azalea-brigadier/src/suggestion/suggestions.rs +++ b/azalea-brigadier/src/suggestion/suggestions.rs @@ -4,7 +4,7 @@ use std::{collections::HashSet, hash::Hash}; #[cfg(feature = "azalea-buf")] use azalea_buf::{ - BufReadError, McBuf, McBufReadable, McBufVarReadable, McBufVarWritable, McBufWritable, + BufReadError, McBuf, AzaleaRead, AzaleaReadVar, AzaleaWriteVar, AzaleaWrite, }; #[cfg(feature = "azalea-buf")] use azalea_chat::FormattedText; @@ -79,7 +79,7 @@ impl Suggestions { } #[cfg(feature = "azalea-buf")] -impl McBufReadable for Suggestions { +impl AzaleaRead for Suggestions { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { #[derive(McBuf)] struct StandaloneSuggestion { @@ -92,7 +92,7 @@ impl McBufReadable for Suggestions { let range = StringRange::between(start, start + length); // the range of a Suggestion depends on the Suggestions containing it, - // so we can't just `impl McBufReadable for Suggestion` + // so we can't just `impl AzaleaRead for Suggestion` let mut suggestions = Vec::::azalea_read(buf)? .into_iter() .map(|s| Suggestion { @@ -108,7 +108,7 @@ impl McBufReadable for Suggestions { } #[cfg(feature = "azalea-buf")] -impl McBufWritable for Suggestions { +impl AzaleaWrite for Suggestions { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { (self.range.start() as u32).azalea_write_var(buf)?; (self.range.length() as u32).azalea_write_var(buf)?; diff --git a/azalea-buf/azalea-buf-macros/src/lib.rs b/azalea-buf/azalea-buf-macros/src/lib.rs index 4d17daa6..c5a2238b 100755 --- a/azalea-buf/azalea-buf-macros/src/lib.rs +++ b/azalea-buf/azalea-buf-macros/src/lib.rs @@ -5,26 +5,26 @@ use proc_macro::TokenStream; use quote::quote; use syn::{parse_macro_input, DeriveInput}; -#[proc_macro_derive(McBufReadable, attributes(var))] -pub fn derive_mcbufreadable(input: TokenStream) -> TokenStream { +#[proc_macro_derive(AzaleaRead, attributes(var))] +pub fn derive_azalearead(input: TokenStream) -> TokenStream { let DeriveInput { ident, data, .. } = parse_macro_input!(input); - read::create_impl_mcbufreadable(&ident, &data).into() + read::create_impl_azalearead(&ident, &data).into() } -#[proc_macro_derive(McBufWritable, attributes(var))] -pub fn derive_mcbufwritable(input: TokenStream) -> TokenStream { +#[proc_macro_derive(AzaleaWrite, attributes(var))] +pub fn derive_azaleawrite(input: TokenStream) -> TokenStream { let DeriveInput { ident, data, .. } = parse_macro_input!(input); - write::create_impl_mcbufwritable(&ident, &data).into() + write::create_impl_azaleawrite(&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 = write::create_impl_mcbufwritable(&ident, &data); - let readable = read::create_impl_mcbufreadable(&ident, &data); + let writable = write::create_impl_azaleawrite(&ident, &data); + let readable = read::create_impl_azalearead(&ident, &data); quote! { #writable #readable diff --git a/azalea-buf/azalea-buf-macros/src/read.rs b/azalea-buf/azalea-buf-macros/src/read.rs index acbe721c..70a6312a 100644 --- a/azalea-buf/azalea-buf-macros/src/read.rs +++ b/azalea-buf/azalea-buf-macros/src/read.rs @@ -15,11 +15,11 @@ fn read_named_fields( syn::Type::Path(_) | syn::Type::Array(_) => { if f.attrs.iter().any(|a| a.path().is_ident("var")) { quote! { - let #field_name = azalea_buf::McBufVarReadable::azalea_read_var(buf)?; + let #field_name = azalea_buf::AzaleaReadVar::azalea_read_var(buf)?; } } else { quote! { - let #field_name = azalea_buf::McBufReadable::azalea_read(buf)?; + let #field_name = azalea_buf::AzaleaRead::azalea_read(buf)?; } } } @@ -36,14 +36,14 @@ fn read_named_fields( (read_fields, read_field_names) } -pub fn create_impl_mcbufreadable(ident: &Ident, data: &Data) -> proc_macro2::TokenStream { +pub fn create_impl_azalearead(ident: &Ident, data: &Data) -> proc_macro2::TokenStream { match data { syn::Data::Struct(syn::DataStruct { fields, .. }) => match fields { syn::Fields::Named(FieldsNamed { named, .. }) => { let (read_fields, read_field_names) = read_named_fields(named); quote! { - impl azalea_buf::McBufReadable for #ident { + impl azalea_buf::AzaleaRead for #ident { fn azalea_read(buf: &mut std::io::Cursor<&[u8]>) -> Result { #(#read_fields)* Ok(Self { @@ -55,7 +55,7 @@ pub fn create_impl_mcbufreadable(ident: &Ident, data: &Data) -> proc_macro2::Tok } syn::Fields::Unit => { quote! { - impl azalea_buf::McBufReadable for #ident { + impl azalea_buf::AzaleaRead for #ident { fn azalea_read(buf: &mut std::io::Cursor<&[u8]>) -> Result { Ok(Self) } @@ -110,11 +110,11 @@ pub fn create_impl_mcbufreadable(ident: &Ident, data: &Data) -> proc_macro2::Tok for f in &fields.unnamed { if f.attrs.iter().any(|attr| attr.path().is_ident("var")) { reader_code.extend(quote! { - Self::#variant_name(azalea_buf::McBufVarReadable::azalea_read_var(buf)?), + Self::#variant_name(azalea_buf::AzaleaReadVar::azalea_read_var(buf)?), }); } else { reader_code.extend(quote! { - Self::#variant_name(azalea_buf::McBufReadable::azalea_read(buf)?), + Self::#variant_name(azalea_buf::AzaleaRead::azalea_read(buf)?), }); } } @@ -139,9 +139,9 @@ pub fn create_impl_mcbufreadable(ident: &Ident, data: &Data) -> proc_macro2::Tok let first_reader = first_reader.expect("There should be at least one variant"); quote! { - impl azalea_buf::McBufReadable for #ident { + impl azalea_buf::AzaleaRead for #ident { fn azalea_read(buf: &mut std::io::Cursor<&[u8]>) -> Result { - let id = azalea_buf::McBufVarReadable::azalea_read_var(buf)?; + let id = azalea_buf::AzaleaReadVar::azalea_read_var(buf)?; Self::azalea_read_id(buf, id) } } diff --git a/azalea-buf/azalea-buf-macros/src/write.rs b/azalea-buf/azalea-buf-macros/src/write.rs index 5fe46bac..ed98c8a1 100644 --- a/azalea-buf/azalea-buf-macros/src/write.rs +++ b/azalea-buf/azalea-buf-macros/src/write.rs @@ -19,11 +19,11 @@ fn write_named_fields( syn::Type::Path(_) | syn::Type::Array(_) => { if f.attrs.iter().any(|attr| attr.path().is_ident("var")) { quote! { - azalea_buf::McBufVarWritable::azalea_write_var(#ident_dot_field, buf)?; + azalea_buf::AzaleaWriteVar::azalea_write_var(#ident_dot_field, buf)?; } } else { quote! { - azalea_buf::McBufWritable::azalea_write(#ident_dot_field, buf)?; + azalea_buf::AzaleaWrite::azalea_write(#ident_dot_field, buf)?; } } } @@ -37,7 +37,7 @@ fn write_named_fields( quote! { #(#write_fields)* } } -pub fn create_impl_mcbufwritable(ident: &Ident, data: &Data) -> proc_macro2::TokenStream { +pub fn create_impl_azaleawrite(ident: &Ident, data: &Data) -> proc_macro2::TokenStream { match data { syn::Data::Struct(syn::DataStruct { fields, .. }) => match fields { syn::Fields::Named(FieldsNamed { named, .. }) => { @@ -45,7 +45,7 @@ pub fn create_impl_mcbufwritable(ident: &Ident, data: &Data) -> proc_macro2::Tok write_named_fields(named, Some(&Ident::new("self", Span::call_site()))); quote! { - impl azalea_buf::McBufWritable for #ident { + impl azalea_buf::AzaleaWrite for #ident { fn azalea_write(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> { #write_fields Ok(()) @@ -55,7 +55,7 @@ pub fn create_impl_mcbufwritable(ident: &Ident, data: &Data) -> proc_macro2::Tok } syn::Fields::Unit => { quote! { - impl azalea_buf::McBufWritable for #ident { + impl azalea_buf::AzaleaWrite for #ident { fn azalea_write(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> { Ok(()) } @@ -103,7 +103,7 @@ pub fn create_impl_mcbufwritable(ident: &Ident, data: &Data) -> proc_macro2::Tok // the variant number that we're going to write let write_the_variant = quote! { - azalea_buf::McBufVarWritable::azalea_write_var(&#variant_discrim, buf)?; + azalea_buf::AzaleaWriteVar::azalea_write_var(&#variant_discrim, buf)?; }; match &variant.fields { syn::Fields::Named(f) => { @@ -145,11 +145,11 @@ pub fn create_impl_mcbufwritable(ident: &Ident, data: &Data) -> proc_macro2::Tok params_code.extend(quote! { #param_ident, }); if f.attrs.iter().any(|attr| attr.path().is_ident("var")) { writers_code.extend(quote! { - azalea_buf::McBufVarWritable::azalea_write_var(#param_ident, buf)?; + azalea_buf::AzaleaWriteVar::azalea_write_var(#param_ident, buf)?; }); } else { writers_code.extend(quote! { - azalea_buf::McBufWritable::azalea_write(#param_ident, buf)?; + azalea_buf::AzaleaWrite::azalea_write(#param_ident, buf)?; }); } } @@ -161,7 +161,7 @@ pub fn create_impl_mcbufwritable(ident: &Ident, data: &Data) -> proc_macro2::Tok }); match_arms_without_id.extend(quote! { Self::#variant_name(data) => { - azalea_buf::McBufWritable::azalea_write(data, buf)?; + azalea_buf::AzaleaWrite::azalea_write(data, buf)?; } }); } @@ -169,7 +169,7 @@ pub fn create_impl_mcbufwritable(ident: &Ident, data: &Data) -> proc_macro2::Tok } if is_data_enum { quote! { - impl azalea_buf::McBufWritable for #ident { + impl azalea_buf::AzaleaWrite for #ident { fn azalea_write(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> { match self { #match_arms @@ -189,9 +189,9 @@ pub fn create_impl_mcbufwritable(ident: &Ident, data: &Data) -> proc_macro2::Tok } else { // optimization: if it doesn't have data we can just do `as u32` quote! { - impl azalea_buf::McBufWritable for #ident { + impl azalea_buf::AzaleaWrite for #ident { fn azalea_write(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> { - azalea_buf::McBufVarWritable::azalea_write_var(&(*self as u32), buf) + azalea_buf::AzaleaWriteVar::azalea_write_var(&(*self as u32), buf) } } } diff --git a/azalea-buf/src/lib.rs b/azalea-buf/src/lib.rs index 332031e6..30626da8 100755 --- a/azalea-buf/src/lib.rs +++ b/azalea-buf/src/lib.rs @@ -10,9 +10,9 @@ mod write; pub use azalea_buf_macros::*; pub use definitions::*; -pub use read::{BufReadError, McBufReadable, McBufVarReadable}; +pub use read::{BufReadError, AzaleaRead, AzaleaReadVar}; pub use serializable_uuid::*; -pub use write::{McBufVarWritable, McBufWritable}; +pub use write::{AzaleaWriteVar, AzaleaWrite}; // const DEFAULT_NBT_QUOTA: u32 = 2097152; const MAX_STRING_LENGTH: u16 = 32767; diff --git a/azalea-buf/src/read.rs b/azalea-buf/src/read.rs index edae683e..415cb384 100755 --- a/azalea-buf/src/read.rs +++ b/azalea-buf/src/read.rs @@ -105,27 +105,27 @@ fn read_utf_with_len(buf: &mut Cursor<&[u8]>, max_length: u32) -> Result) -> Result; } -pub trait McBufVarReadable +pub trait AzaleaReadVar where Self: Sized, { fn azalea_read_var(buf: &mut Cursor<&[u8]>) -> Result; } -impl McBufReadable for i32 { +impl AzaleaRead for i32 { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { Ok(buf.read_i32::()?) } } -impl McBufVarReadable for i32 { +impl AzaleaReadVar for i32 { // 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 fn azalea_read_var(buf: &mut Cursor<&[u8]>) -> Result { @@ -142,7 +142,7 @@ impl McBufVarReadable for i32 { } } -impl McBufVarReadable for i64 { +impl AzaleaReadVar for i64 { // fast varints modified from https://github.com/luojia65/mc-varint/blob/master/src/lib.rs#L54 fn azalea_read_var(buf: &mut Cursor<&[u8]>) -> Result { let mut buffer = [0]; @@ -158,13 +158,13 @@ impl McBufVarReadable for i64 { Ok(ans) } } -impl McBufVarReadable for u64 { +impl AzaleaReadVar for u64 { fn azalea_read_var(buf: &mut Cursor<&[u8]>) -> Result { i64::azalea_read_var(buf).map(|i| i as u64) } } -impl McBufReadable for UnsizedByteArray { +impl AzaleaRead for UnsizedByteArray { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { // read to end of the buffer let data = buf.get_ref()[buf.position() as usize..].to_vec(); @@ -173,7 +173,7 @@ impl McBufReadable for UnsizedByteArray { } } -impl McBufReadable for Vec { +impl AzaleaRead for Vec { default fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let length = u32::azalea_read_var(buf)? as usize; // we limit the capacity to not get exploited into allocating a bunch @@ -185,7 +185,7 @@ impl McBufReadable for Vec { } } -impl McBufReadable for HashMap { +impl AzaleaRead for HashMap { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let length = i32::azalea_read_var(buf)? as usize; let mut contents = HashMap::with_capacity(usize::min(length, 65536)); @@ -196,7 +196,7 @@ impl McBufReadable } } -impl McBufVarReadable +impl AzaleaReadVar for HashMap { fn azalea_read_var(buf: &mut Cursor<&[u8]>) -> Result { @@ -209,50 +209,50 @@ impl McBufVarRe } } -impl McBufReadable for Vec { +impl AzaleaRead for Vec { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let length = i32::azalea_read_var(buf)? as usize; read_bytes(buf, length).map(|b| b.to_vec()) } } -impl McBufReadable for String { +impl AzaleaRead for String { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { read_utf_with_len(buf, MAX_STRING_LENGTH.into()) } } -impl McBufReadable for u32 { +impl AzaleaRead for u32 { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { Ok(i32::azalea_read(buf)? as u32) } } -impl McBufVarReadable for u32 { +impl AzaleaReadVar for u32 { fn azalea_read_var(buf: &mut Cursor<&[u8]>) -> Result { Ok(i32::azalea_read_var(buf)? as u32) } } -impl McBufReadable for u16 { +impl AzaleaRead for u16 { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { i16::azalea_read(buf).map(|i| i as u16) } } -impl McBufReadable for i16 { +impl AzaleaRead for i16 { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { Ok(buf.read_i16::()?) } } -impl McBufVarReadable for u16 { +impl AzaleaReadVar for u16 { fn azalea_read_var(buf: &mut Cursor<&[u8]>) -> Result { Ok(i32::azalea_read_var(buf)? as u16) } } -impl McBufVarReadable for Vec { +impl AzaleaReadVar for Vec { fn azalea_read_var(buf: &mut Cursor<&[u8]>) -> Result { let length = i32::azalea_read_var(buf)? as usize; let mut contents = Vec::with_capacity(usize::min(length, 65536)); @@ -263,19 +263,19 @@ impl McBufVarReadable for Vec { } } -impl McBufReadable for i64 { +impl AzaleaRead for i64 { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { Ok(buf.read_i64::()?) } } -impl McBufReadable for u64 { +impl AzaleaRead for u64 { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { i64::azalea_read(buf).map(|i| i as u64) } } -impl McBufReadable for bool { +impl AzaleaRead for bool { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let byte = u8::azalea_read(buf)?; if byte > 1 { @@ -285,31 +285,31 @@ impl McBufReadable for bool { } } -impl McBufReadable for u8 { +impl AzaleaRead for u8 { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { Ok(buf.read_u8()?) } } -impl McBufReadable for i8 { +impl AzaleaRead for i8 { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { u8::azalea_read(buf).map(|i| i as i8) } } -impl McBufReadable for f32 { +impl AzaleaRead for f32 { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { Ok(buf.read_f32::()?) } } -impl McBufReadable for f64 { +impl AzaleaRead for f64 { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { Ok(buf.read_f64::()?) } } -impl McBufReadable for Option { +impl AzaleaRead for Option { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let present = bool::azalea_read(buf)?; Ok(if present { @@ -320,7 +320,7 @@ impl McBufReadable for Option { } } -impl McBufVarReadable for Option { +impl AzaleaReadVar for Option { fn azalea_read_var(buf: &mut Cursor<&[u8]>) -> Result { let present = bool::azalea_read(buf)?; Ok(if present { @@ -332,7 +332,7 @@ impl McBufVarReadable for Option { } // [String; 4] -impl McBufReadable for [T; N] { +impl AzaleaRead for [T; N] { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let mut contents = Vec::with_capacity(N); for _ in 0..N { @@ -344,13 +344,13 @@ impl McBufReadable for [T; N] { } } -impl McBufReadable for simdnbt::owned::NbtTag { +impl AzaleaRead for simdnbt::owned::NbtTag { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { Ok(simdnbt::owned::read_tag(buf).map_err(simdnbt::Error::from)?) } } -impl McBufReadable for simdnbt::owned::NbtCompound { +impl AzaleaRead for simdnbt::owned::NbtCompound { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { match simdnbt::owned::read_tag(buf).map_err(simdnbt::Error::from)? { simdnbt::owned::NbtTag::Compound(compound) => Ok(compound), @@ -359,15 +359,15 @@ impl McBufReadable for simdnbt::owned::NbtCompound { } } -impl McBufReadable for simdnbt::owned::Nbt { +impl AzaleaRead for simdnbt::owned::Nbt { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { Ok(simdnbt::owned::read_unnamed(buf)?) } } -impl McBufReadable for Box +impl AzaleaRead for Box where - T: McBufReadable, + T: AzaleaRead, { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { Ok(Box::new(T::azalea_read(buf)?)) diff --git a/azalea-buf/src/serializable_uuid.rs b/azalea-buf/src/serializable_uuid.rs index 8091548e..53eccbbb 100755 --- a/azalea-buf/src/serializable_uuid.rs +++ b/azalea-buf/src/serializable_uuid.rs @@ -2,7 +2,7 @@ use std::io::{Cursor, Write}; use uuid::Uuid; -use crate::{read::BufReadError, McBufReadable, McBufWritable}; +use crate::{read::BufReadError, AzaleaRead, AzaleaWrite}; pub trait SerializableUuid { fn to_int_array(&self) -> [u32; 4]; @@ -34,7 +34,7 @@ impl SerializableUuid for Uuid { } } -impl McBufReadable for Uuid { +impl AzaleaRead for Uuid { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { Ok(Uuid::from_int_array([ u32::azalea_read(buf)?, @@ -45,7 +45,7 @@ impl McBufReadable for Uuid { } } -impl McBufWritable for Uuid { +impl AzaleaWrite for Uuid { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { let [a, b, c, d] = self.to_int_array(); a.azalea_write(buf)?; diff --git a/azalea-buf/src/write.rs b/azalea-buf/src/write.rs index b8e4039c..1092586d 100755 --- a/azalea-buf/src/write.rs +++ b/azalea-buf/src/write.rs @@ -20,21 +20,21 @@ fn write_utf_with_len( Ok(()) } -pub trait McBufWritable { +pub trait AzaleaWrite { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error>; } -pub trait McBufVarWritable { +pub trait AzaleaWriteVar { fn azalea_write_var(&self, buf: &mut impl Write) -> Result<(), std::io::Error>; } -impl McBufWritable for i32 { +impl AzaleaWrite for i32 { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { WriteBytesExt::write_i32::(buf, *self) } } -impl McBufVarWritable for i32 { +impl AzaleaWriteVar for i32 { fn azalea_write_var(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { let mut buffer = [0]; let mut value = *self; @@ -53,19 +53,19 @@ impl McBufVarWritable for i32 { } } -impl McBufWritable for UnsizedByteArray { +impl AzaleaWrite for UnsizedByteArray { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { buf.write_all(self) } } -impl McBufWritable for Vec { +impl AzaleaWrite for Vec { default fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { self[..].azalea_write(buf) } } -impl McBufWritable for [T] { +impl AzaleaWrite for [T] { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { (self.len() as u32).azalea_write_var(buf)?; for item in self { @@ -75,7 +75,7 @@ impl McBufWritable for [T] { } } -impl McBufWritable for HashMap { +impl AzaleaWrite for HashMap { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { u32::azalea_write_var(&(self.len() as u32), buf)?; for (key, value) in self { @@ -87,7 +87,7 @@ impl McBufWritable for HashMap { } } -impl McBufVarWritable for HashMap { +impl AzaleaWriteVar for HashMap { fn azalea_write_var(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { u32::azalea_write_var(&(self.len() as u32), buf)?; for (key, value) in self { @@ -99,38 +99,38 @@ impl McBufVarWritable for HashMap { } } -impl McBufWritable for Vec { +impl AzaleaWrite for Vec { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { (self.len() as u32).azalea_write_var(buf)?; buf.write_all(self) } } -impl McBufWritable for String { +impl AzaleaWrite for String { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { write_utf_with_len(buf, self, MAX_STRING_LENGTH.into()) } } -impl McBufWritable for &str { +impl AzaleaWrite for &str { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { write_utf_with_len(buf, self, MAX_STRING_LENGTH.into()) } } -impl McBufWritable for u32 { +impl AzaleaWrite for u32 { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { i32::azalea_write(&(*self as i32), buf) } } -impl McBufVarWritable for u32 { +impl AzaleaWriteVar for u32 { fn azalea_write_var(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { i32::azalea_write_var(&(*self as i32), buf) } } -impl McBufVarWritable for i64 { +impl AzaleaWriteVar for i64 { fn azalea_write_var(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { let mut buffer = [0]; let mut value = *self; @@ -149,25 +149,25 @@ impl McBufVarWritable for i64 { } } -impl McBufVarWritable for u64 { +impl AzaleaWriteVar for u64 { fn azalea_write_var(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { i64::azalea_write_var(&(*self as i64), buf) } } -impl McBufWritable for u16 { +impl AzaleaWrite for u16 { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { i16::azalea_write(&(*self as i16), buf) } } -impl McBufVarWritable for u16 { +impl AzaleaWriteVar for u16 { fn azalea_write_var(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { i32::azalea_write_var(&(*self as i32), buf) } } -impl McBufVarWritable for Vec { +impl AzaleaWriteVar for Vec { fn azalea_write_var(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { u32::azalea_write_var(&(self.len() as u32), buf)?; for i in self { @@ -177,56 +177,56 @@ impl McBufVarWritable for Vec { } } -impl McBufWritable for u8 { +impl AzaleaWrite for u8 { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { WriteBytesExt::write_u8(buf, *self) } } -impl McBufWritable for i16 { +impl AzaleaWrite for i16 { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { WriteBytesExt::write_i16::(buf, *self) } } -impl McBufWritable for i64 { +impl AzaleaWrite for i64 { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { WriteBytesExt::write_i64::(buf, *self) } } -impl McBufWritable for u64 { +impl AzaleaWrite for u64 { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { i64::azalea_write(&(*self as i64), buf) } } -impl McBufWritable for bool { +impl AzaleaWrite for bool { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { let byte = u8::from(*self); byte.azalea_write(buf) } } -impl McBufWritable for i8 { +impl AzaleaWrite for i8 { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { (*self as u8).azalea_write(buf) } } -impl McBufWritable for f32 { +impl AzaleaWrite for f32 { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { WriteBytesExt::write_f32::(buf, *self) } } -impl McBufWritable for f64 { +impl AzaleaWrite for f64 { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { WriteBytesExt::write_f64::(buf, *self) } } -impl McBufWritable for Option { +impl AzaleaWrite for Option { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { if let Some(s) = self { true.azalea_write(buf)?; @@ -238,7 +238,7 @@ impl McBufWritable for Option { } } -impl McBufVarWritable for Option { +impl AzaleaWriteVar for Option { fn azalea_write_var(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { if let Some(s) = self { true.azalea_write(buf)?; @@ -251,7 +251,7 @@ impl McBufVarWritable for Option { } // [T; N] -impl McBufWritable for [T; N] { +impl AzaleaWrite for [T; N] { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { for i in self { i.azalea_write(buf)?; @@ -260,7 +260,7 @@ impl McBufWritable for [T; N] { } } -impl McBufWritable for simdnbt::owned::NbtTag { +impl AzaleaWrite for simdnbt::owned::NbtTag { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { let mut data = Vec::new(); self.write(&mut data); @@ -268,7 +268,7 @@ impl McBufWritable for simdnbt::owned::NbtTag { } } -impl McBufWritable for simdnbt::owned::NbtCompound { +impl AzaleaWrite for simdnbt::owned::NbtCompound { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { let mut data = Vec::new(); simdnbt::owned::NbtTag::Compound(self.clone()).write(&mut data); @@ -276,7 +276,7 @@ impl McBufWritable for simdnbt::owned::NbtCompound { } } -impl McBufWritable for simdnbt::owned::Nbt { +impl AzaleaWrite for simdnbt::owned::Nbt { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { let mut data = Vec::new(); self.write_unnamed(&mut data); @@ -284,9 +284,9 @@ impl McBufWritable for simdnbt::owned::Nbt { } } -impl McBufWritable for Box +impl AzaleaWrite for Box where - T: McBufWritable, + T: AzaleaWrite, { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { T::azalea_write(&**self, buf) diff --git a/azalea-chat/src/component.rs b/azalea-chat/src/component.rs index f5ecd4c1..c0ebeb5f 100755 --- a/azalea-chat/src/component.rs +++ b/azalea-chat/src/component.rs @@ -1,7 +1,7 @@ use std::fmt::Display; #[cfg(feature = "azalea-buf")] -use azalea_buf::{BufReadError, McBufReadable, McBufWritable}; +use azalea_buf::{BufReadError, AzaleaRead, AzaleaWrite}; use once_cell::sync::Lazy; use serde::{de, Deserialize, Deserializer, Serialize}; #[cfg(feature = "simdnbt")] @@ -456,7 +456,7 @@ impl From<&simdnbt::Mutf8Str> for FormattedText { #[cfg(feature = "azalea-buf")] #[cfg(feature = "simdnbt")] -impl McBufReadable for FormattedText { +impl AzaleaRead for FormattedText { fn azalea_read(buf: &mut std::io::Cursor<&[u8]>) -> Result { let nbt = simdnbt::borrow::read_optional_tag(buf)?; if let Some(nbt) = nbt { @@ -471,7 +471,7 @@ impl McBufReadable for FormattedText { #[cfg(feature = "azalea-buf")] #[cfg(feature = "simdnbt")] -impl McBufWritable for FormattedText { +impl AzaleaWrite for FormattedText { fn azalea_write(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> { let mut out = Vec::new(); simdnbt::owned::BaseNbt::write_unnamed(&(self.clone().to_compound().into()), &mut out); diff --git a/azalea-chat/src/numbers.rs b/azalea-chat/src/numbers.rs index 87fdecc6..161f1177 100644 --- a/azalea-chat/src/numbers.rs +++ b/azalea-chat/src/numbers.rs @@ -4,7 +4,7 @@ use std::io::{Cursor, Write}; #[cfg(feature = "azalea-buf")] -use azalea_buf::{McBufReadable, McBufWritable}; +use azalea_buf::{AzaleaRead, AzaleaWrite}; use azalea_registry::NumberFormatKind; use simdnbt::owned::Nbt; @@ -18,7 +18,7 @@ pub enum NumberFormat { } #[cfg(feature = "azalea-buf")] -impl McBufReadable for NumberFormat { +impl AzaleaRead for NumberFormat { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let kind = NumberFormatKind::azalea_read(buf)?; match kind { @@ -34,7 +34,7 @@ impl McBufReadable for NumberFormat { } #[cfg(feature = "azalea-buf")] -impl McBufWritable for NumberFormat { +impl AzaleaWrite for NumberFormat { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { match self { NumberFormat::Blank => NumberFormatKind::Blank.azalea_write(buf)?, diff --git a/azalea-client/src/configuration.rs b/azalea-client/src/configuration.rs index d94f39e6..e07e7a74 100644 --- a/azalea-client/src/configuration.rs +++ b/azalea-client/src/configuration.rs @@ -1,4 +1,4 @@ -use azalea_buf::McBufWritable; +use azalea_buf::AzaleaWrite; use azalea_core::resource_location::ResourceLocation; use azalea_protocol::{ common::ClientInformation, diff --git a/azalea-core/src/bitset.rs b/azalea-core/src/bitset.rs index 7d6dee94..c6756b55 100755 --- a/azalea-core/src/bitset.rs +++ b/azalea-core/src/bitset.rs @@ -1,6 +1,6 @@ use std::io::{Cursor, Write}; -use azalea_buf::{BufReadError, McBuf, McBufReadable, McBufWritable}; +use azalea_buf::{BufReadError, McBuf, AzaleaRead, AzaleaWrite}; /// Represents Java's BitSet, a list of bits. #[derive(Debug, Clone, PartialEq, Eq, Hash, Default, McBuf)] @@ -159,7 +159,7 @@ where } } -impl McBufReadable for FixedBitSet +impl AzaleaRead for FixedBitSet where [u8; N.div_ceil(8)]: Sized, { @@ -171,7 +171,7 @@ where Ok(FixedBitSet { data }) } } -impl McBufWritable for FixedBitSet +impl AzaleaWrite for FixedBitSet where [u8; N.div_ceil(8)]: Sized, { diff --git a/azalea-core/src/difficulty.rs b/azalea-core/src/difficulty.rs index 5bc1f508..e913ffac 100755 --- a/azalea-core/src/difficulty.rs +++ b/azalea-core/src/difficulty.rs @@ -3,7 +3,7 @@ use std::{ io::{Cursor, Write}, }; -use azalea_buf::{BufReadError, McBufReadable, McBufWritable}; +use azalea_buf::{BufReadError, AzaleaRead, AzaleaWrite}; #[derive(Hash, Clone, Copy, Debug, PartialEq, Eq)] pub enum Difficulty { @@ -66,13 +66,13 @@ impl Difficulty { } } -impl McBufReadable for Difficulty { +impl AzaleaRead for Difficulty { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { Ok(Difficulty::by_id(u8::azalea_read(buf)?)) } } -impl McBufWritable for Difficulty { +impl AzaleaWrite for Difficulty { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { u8::azalea_write(&self.id(), buf) } diff --git a/azalea-core/src/game_type.rs b/azalea-core/src/game_type.rs index d8230ead..f898d721 100644 --- a/azalea-core/src/game_type.rs +++ b/azalea-core/src/game_type.rs @@ -1,6 +1,6 @@ use std::io::{Cursor, Write}; -use azalea_buf::{BufReadError, McBufReadable, McBufVarReadable, McBufWritable}; +use azalea_buf::{BufReadError, AzaleaRead, AzaleaReadVar, AzaleaWrite}; use tracing::debug; /// A Minecraft gamemode, like survival or creative. @@ -93,7 +93,7 @@ impl GameMode { } } -impl McBufReadable for GameMode { +impl AzaleaRead for GameMode { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let id = u32::azalea_read_var(buf)?; let id = id.try_into().unwrap_or_else(|_| { @@ -107,13 +107,13 @@ impl McBufReadable for GameMode { } } -impl McBufWritable for GameMode { +impl AzaleaWrite for GameMode { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { u8::azalea_write(&self.to_id(), buf) } } -/// Rust doesn't let us `impl McBufReadable for Option` so we have to +/// Rust doesn't let us `impl AzaleaRead for Option` so we have to /// make a new type :( #[derive(Hash, Copy, Clone, Debug)] pub struct OptionalGameType(pub Option); @@ -130,14 +130,14 @@ impl From for Option { } } -impl McBufReadable for OptionalGameType { +impl AzaleaRead for OptionalGameType { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let id = i8::azalea_read(buf)?; GameMode::from_optional_id(id).ok_or(BufReadError::UnexpectedEnumVariant { id: id as i32 }) } } -impl McBufWritable for OptionalGameType { +impl AzaleaWrite for OptionalGameType { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { GameMode::to_optional_id(*self).azalea_write(buf) } diff --git a/azalea-core/src/position.rs b/azalea-core/src/position.rs index b045269c..c9aa010a 100755 --- a/azalea-core/src/position.rs +++ b/azalea-core/src/position.rs @@ -11,7 +11,7 @@ use std::{ str::FromStr, }; -use azalea_buf::{BufReadError, McBuf, McBufReadable, McBufWritable}; +use azalea_buf::{BufReadError, McBuf, AzaleaRead, AzaleaWrite}; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; @@ -315,13 +315,13 @@ impl From for ChunkPos { } } } -impl McBufReadable for ChunkPos { +impl AzaleaRead for ChunkPos { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let long = u64::azalea_read(buf)?; Ok(ChunkPos::from(long)) } } -impl McBufWritable for ChunkPos { +impl AzaleaWrite for ChunkPos { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { u64::from(*self).azalea_write(buf)?; Ok(()) @@ -586,7 +586,7 @@ const PACKED_Z_MASK: u64 = (1 << PACKED_Z_LENGTH) - 1; const Z_OFFSET: u64 = PACKED_Y_LENGTH; const X_OFFSET: u64 = PACKED_Y_LENGTH + PACKED_Z_LENGTH; -impl McBufReadable for BlockPos { +impl AzaleaRead for BlockPos { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let val = i64::azalea_read(buf)?; let x = (val << (64 - X_OFFSET - PACKED_X_LENGTH) >> (64 - PACKED_X_LENGTH)) as i32; @@ -596,7 +596,7 @@ impl McBufReadable for BlockPos { } } -impl McBufReadable for GlobalPos { +impl AzaleaRead for GlobalPos { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { Ok(GlobalPos { world: ResourceLocation::azalea_read(buf)?, @@ -605,7 +605,7 @@ impl McBufReadable for GlobalPos { } } -impl McBufReadable for ChunkSectionPos { +impl AzaleaRead for ChunkSectionPos { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let long = i64::azalea_read(buf)?; Ok(ChunkSectionPos { @@ -616,7 +616,7 @@ impl McBufReadable for ChunkSectionPos { } } -impl McBufWritable for BlockPos { +impl AzaleaWrite for BlockPos { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { let mut val: u64 = 0; val |= ((self.x as u64) & PACKED_X_MASK) << X_OFFSET; @@ -626,7 +626,7 @@ impl McBufWritable for BlockPos { } } -impl McBufWritable for GlobalPos { +impl AzaleaWrite for GlobalPos { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { ResourceLocation::azalea_write(&self.world, buf)?; BlockPos::azalea_write(&self.pos, buf)?; @@ -635,7 +635,7 @@ impl McBufWritable for GlobalPos { } } -impl McBufWritable for ChunkSectionPos { +impl AzaleaWrite for ChunkSectionPos { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { let long = (((self.x & 0x3FFFFF) as i64) << 42) | (self.y & 0xFFFFF) as i64 diff --git a/azalea-core/src/resource_location.rs b/azalea-core/src/resource_location.rs index 25e54d86..539b9b81 100755 --- a/azalea-core/src/resource_location.rs +++ b/azalea-core/src/resource_location.rs @@ -6,7 +6,7 @@ use std::{ str::FromStr, }; -use azalea_buf::{BufReadError, McBufReadable, McBufWritable}; +use azalea_buf::{BufReadError, AzaleaRead, AzaleaWrite}; #[cfg(feature = "serde")] use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; use simdnbt::{owned::NbtTag, FromNbtTag, ToNbtTag}; @@ -60,13 +60,13 @@ impl FromStr for ResourceLocation { } } -impl McBufReadable for ResourceLocation { +impl AzaleaRead for ResourceLocation { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let location_string = String::azalea_read(buf)?; Ok(ResourceLocation::new(&location_string)) } } -impl McBufWritable for ResourceLocation { +impl AzaleaWrite for ResourceLocation { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { self.to_string().azalea_write(buf) } diff --git a/azalea-crypto/src/signing.rs b/azalea-crypto/src/signing.rs index 8ff7d7bf..9e276ede 100755 --- a/azalea-crypto/src/signing.rs +++ b/azalea-crypto/src/signing.rs @@ -1,6 +1,6 @@ use std::time::{SystemTime, UNIX_EPOCH}; -use azalea_buf::{McBuf, McBufWritable}; +use azalea_buf::{McBuf, AzaleaWrite}; use rsa::{ signature::{RandomizedSigner, SignatureEncoding}, RsaPrivateKey, diff --git a/azalea-entity/src/data.rs b/azalea-entity/src/data.rs index 12558a54..a67037e2 100755 --- a/azalea-entity/src/data.rs +++ b/azalea-entity/src/data.rs @@ -2,9 +2,7 @@ use std::io::{Cursor, Write}; -use azalea_buf::{ - BufReadError, McBuf, McBufReadable, McBufVarReadable, McBufVarWritable, McBufWritable, -}; +use azalea_buf::{AzaleaRead, AzaleaReadVar, AzaleaWrite, AzaleaWriteVar, BufReadError, McBuf}; use azalea_chat::FormattedText; use azalea_core::{ direction::Direction, @@ -36,7 +34,7 @@ impl EntityMetadataItems { } } -impl McBufReadable for EntityMetadataItems { +impl AzaleaRead for EntityMetadataItems { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let mut metadata = Vec::new(); loop { @@ -51,7 +49,7 @@ impl McBufReadable for EntityMetadataItems { } } -impl McBufWritable for EntityMetadataItems { +impl AzaleaWrite for EntityMetadataItems { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { for item in &self.0 { item.index.azalea_write(buf)?; @@ -122,7 +120,7 @@ pub enum ArmadilloStateKind { Scared, } -impl McBufReadable for OptionalUnsignedInt { +impl AzaleaRead for OptionalUnsignedInt { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let val = u32::azalea_read_var(buf)?; Ok(OptionalUnsignedInt(if val == 0 { @@ -132,7 +130,7 @@ impl McBufReadable for OptionalUnsignedInt { })) } } -impl McBufWritable for OptionalUnsignedInt { +impl AzaleaWrite for OptionalUnsignedInt { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { match self.0 { Some(val) => (val + 1).azalea_write_var(buf), diff --git a/azalea-inventory/src/components.rs b/azalea-inventory/src/components.rs index 42ac546c..f2d44a05 100644 --- a/azalea-inventory/src/components.rs +++ b/azalea-inventory/src/components.rs @@ -1,7 +1,7 @@ use core::f64; use std::{any::Any, collections::HashMap, io::Cursor}; -use azalea_buf::{BufReadError, McBuf, McBufReadable, McBufWritable}; +use azalea_buf::{BufReadError, McBuf, AzaleaRead, AzaleaWrite}; use azalea_chat::FormattedText; use azalea_core::{position::GlobalPos, resource_location::ResourceLocation}; use azalea_registry::{ @@ -26,7 +26,7 @@ pub trait EncodableDataComponent: Send + Sync + Any { impl EncodableDataComponent for T where - T: DataComponent + Clone + McBufWritable + McBufReadable + PartialEq, + T: DataComponent + Clone + AzaleaWrite + AzaleaRead + PartialEq, { fn encode(&self, buf: &mut Vec) -> Result<(), std::io::Error> { self.azalea_write(buf) diff --git a/azalea-inventory/src/slot.rs b/azalea-inventory/src/slot.rs index 1a1a89f9..7d62bf69 100644 --- a/azalea-inventory/src/slot.rs +++ b/azalea-inventory/src/slot.rs @@ -4,7 +4,7 @@ use std::{ io::{Cursor, Write}, }; -use azalea_buf::{BufReadError, McBufReadable, McBufVarReadable, McBufVarWritable, McBufWritable}; +use azalea_buf::{AzaleaRead, AzaleaReadVar, AzaleaWrite, AzaleaWriteVar, BufReadError}; use azalea_registry::DataComponentKind; use crate::components::{self}; @@ -140,7 +140,7 @@ impl ItemStackData { } } -impl McBufReadable for ItemStack { +impl AzaleaRead for ItemStack { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let count = i32::azalea_read_var(buf)?; if count <= 0 { @@ -157,7 +157,7 @@ impl McBufReadable for ItemStack { } } -impl McBufWritable for ItemStack { +impl AzaleaWrite for ItemStack { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { match self { ItemStack::Empty => 0.azalea_write_var(buf)?, @@ -182,7 +182,7 @@ impl DataComponentPatch { } } -impl McBufReadable for DataComponentPatch { +impl AzaleaRead for DataComponentPatch { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let components_with_data_count = u32::azalea_read_var(buf)?; let components_without_data_count = u32::azalea_read_var(buf)?; @@ -207,7 +207,7 @@ impl McBufReadable for DataComponentPatch { } } -impl McBufWritable for DataComponentPatch { +impl AzaleaWrite for DataComponentPatch { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { let mut components_with_data_count = 0; let mut components_without_data_count = 0; diff --git a/azalea-protocol/README.md b/azalea-protocol/README.md index 3f0ea40e..91d425a6 100755 --- a/azalea-protocol/README.md +++ b/azalea-protocol/README.md @@ -21,6 +21,6 @@ Adding new packets is usually pretty easy, but you'll want to have Minecraft's d ### Implementing packets -You can manually implement reading and writing functionality for a packet by implementing McBufReadable and McBufWritable, but you can also have this automatically generated for a struct or enum by deriving McBuf. +You can manually implement reading and writing functionality for a packet by implementing AzaleaRead and AzaleaWrite, but you can also have this automatically generated for a struct or enum by deriving McBuf. Look at other packets as an example. diff --git a/azalea-protocol/azalea-protocol-macros/src/lib.rs b/azalea-protocol/azalea-protocol-macros/src/lib.rs index dde36d33..01ad307c 100755 --- a/azalea-protocol/azalea-protocol-macros/src/lib.rs +++ b/azalea-protocol/azalea-protocol-macros/src/lib.rs @@ -21,13 +21,13 @@ fn as_packet_derive(input: TokenStream, state: proc_macro2::TokenStream) -> Toke let contents = quote! { impl #ident { pub fn write(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> { - azalea_buf::McBufWritable::azalea_write(self, buf) + azalea_buf::AzaleaWrite::azalea_write(self, buf) } pub fn read( buf: &mut std::io::Cursor<&[u8]>, ) -> Result<#state, azalea_buf::BufReadError> { - use azalea_buf::McBufReadable; + use azalea_buf::AzaleaRead; Ok(Self::azalea_read(buf)?.into_variant()) } diff --git a/azalea-protocol/src/common.rs b/azalea-protocol/src/common.rs index d9f99b50..9529cd1b 100644 --- a/azalea-protocol/src/common.rs +++ b/azalea-protocol/src/common.rs @@ -1,6 +1,6 @@ //! Some serializable data types that are used by several packets. -use azalea_buf::{McBuf, McBufReadable, McBufWritable}; +use azalea_buf::{AzaleaRead, AzaleaWrite, McBuf}; use azalea_core::bitset::FixedBitSet; use bevy_ecs::component::Component; @@ -97,7 +97,7 @@ impl Default for ModelCustomization { } } -impl McBufReadable for ModelCustomization { +impl AzaleaRead for ModelCustomization { fn azalea_read(buf: &mut std::io::Cursor<&[u8]>) -> Result { let set = FixedBitSet::<7>::azalea_read(buf)?; Ok(Self { @@ -112,7 +112,7 @@ impl McBufReadable for ModelCustomization { } } -impl McBufWritable for ModelCustomization { +impl AzaleaWrite for ModelCustomization { fn azalea_write(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> { let mut set = FixedBitSet::<7>::new(); if self.cape { @@ -144,7 +144,7 @@ impl McBufWritable for ModelCustomization { mod tests { use std::io::Cursor; - use azalea_buf::{McBufReadable, McBufWritable}; + use azalea_buf::{AzaleaRead, AzaleaWrite}; use super::*; diff --git a/azalea-protocol/src/packets/config/c_update_tags.rs b/azalea-protocol/src/packets/config/c_update_tags.rs index 83a97e38..95b75d2c 100644 --- a/azalea-protocol/src/packets/config/c_update_tags.rs +++ b/azalea-protocol/src/packets/config/c_update_tags.rs @@ -2,8 +2,8 @@ use std::io::Cursor; use std::ops::Deref; use std::{collections::HashMap, io::Write}; -use azalea_buf::{BufReadError, McBuf, McBufVarReadable, McBufVarWritable}; -use azalea_buf::{McBufReadable, McBufWritable}; +use azalea_buf::{AzaleaRead, AzaleaWrite}; +use azalea_buf::{AzaleaWriteVar, BufReadError, McBuf, AzaleaReadVar}; use azalea_core::resource_location::ResourceLocation; use azalea_protocol_macros::ClientboundConfigPacket; @@ -21,7 +21,7 @@ pub struct Tags { #[derive(Clone, Debug)] pub struct TagMap(pub HashMap>); -impl McBufReadable for TagMap { +impl AzaleaRead for TagMap { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let length = u32::azalea_read_var(buf)? as usize; let mut data = HashMap::with_capacity(length); @@ -39,7 +39,7 @@ impl McBufReadable for TagMap { } } -impl McBufWritable for TagMap { +impl AzaleaWrite for TagMap { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { (self.len() as u32).azalea_write_var(buf)?; for (k, v) in &self.0 { @@ -49,7 +49,7 @@ impl McBufWritable for TagMap { Ok(()) } } -impl McBufReadable for Tags { +impl AzaleaRead for Tags { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let name = ResourceLocation::azalea_read(buf)?; let elements = Vec::::azalea_read_var(buf)?; @@ -57,7 +57,7 @@ impl McBufReadable for Tags { } } -impl McBufWritable for Tags { +impl AzaleaWrite for Tags { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { self.name.azalea_write(buf)?; self.elements.azalea_write_var(buf)?; diff --git a/azalea-protocol/src/packets/game/c_boss_event.rs b/azalea-protocol/src/packets/game/c_boss_event.rs index 2e292afe..5e479db2 100755 --- a/azalea-protocol/src/packets/game/c_boss_event.rs +++ b/azalea-protocol/src/packets/game/c_boss_event.rs @@ -2,7 +2,7 @@ use std::io::Cursor; use std::io::Write; use azalea_buf::{ - BufReadError, McBuf, McBufReadable, McBufVarReadable, McBufVarWritable, McBufWritable, + BufReadError, McBuf, AzaleaRead, AzaleaReadVar, AzaleaWriteVar, AzaleaWrite, }; use azalea_chat::FormattedText; use azalea_core::bitset::FixedBitSet; @@ -25,7 +25,7 @@ pub enum Operation { UpdateProperties(Properties), } -impl McBufReadable for Operation { +impl AzaleaRead for Operation { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let operation_id = u32::azalea_read_var(buf)?; Ok(match operation_id { @@ -44,7 +44,7 @@ impl McBufReadable for Operation { } } -impl McBufWritable for Operation { +impl AzaleaWrite for Operation { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { match self { Operation::Add(add) => { @@ -116,7 +116,7 @@ pub struct Properties { pub create_world_fog: bool, } -impl McBufReadable for Properties { +impl AzaleaRead for Properties { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let set = FixedBitSet::<3>::azalea_read(buf)?; Ok(Self { @@ -127,7 +127,7 @@ impl McBufReadable for Properties { } } -impl McBufWritable for Properties { +impl AzaleaWrite for Properties { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { let mut set = FixedBitSet::<3>::new(); if self.darken_screen { diff --git a/azalea-protocol/src/packets/game/c_command_suggestions.rs b/azalea-protocol/src/packets/game/c_command_suggestions.rs index ed8b4229..f1fa65d7 100755 --- a/azalea-protocol/src/packets/game/c_command_suggestions.rs +++ b/azalea-protocol/src/packets/game/c_command_suggestions.rs @@ -14,7 +14,7 @@ mod tests { use std::io::Cursor; use azalea_brigadier::{context::StringRange, suggestion::Suggestion}; - use azalea_buf::{McBufReadable, McBufWritable}; + use azalea_buf::{AzaleaRead, AzaleaWrite}; use super::*; diff --git a/azalea-protocol/src/packets/game/c_commands.rs b/azalea-protocol/src/packets/game/c_commands.rs index e1a20e6a..60df57e5 100755 --- a/azalea-protocol/src/packets/game/c_commands.rs +++ b/azalea-protocol/src/packets/game/c_commands.rs @@ -1,7 +1,7 @@ use std::io::{Cursor, Write}; use azalea_buf::{ - BufReadError, McBuf, McBufReadable, McBufVarReadable, McBufVarWritable, McBufWritable, + BufReadError, McBuf, AzaleaRead, AzaleaReadVar, AzaleaWriteVar, AzaleaWrite, }; use azalea_core::{bitset::FixedBitSet, resource_location::ResourceLocation}; use azalea_protocol_macros::ClientboundGamePacket; @@ -46,7 +46,7 @@ impl PartialEq for BrigadierNumber { } } -impl McBufReadable for BrigadierNumber { +impl AzaleaRead for BrigadierNumber { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let flags = FixedBitSet::<2>::azalea_read(buf)?; let min = if flags.index(0) { @@ -62,7 +62,7 @@ impl McBufReadable for BrigadierNumber { Ok(BrigadierNumber { min, max }) } } -impl McBufWritable for BrigadierNumber { +impl AzaleaWrite for BrigadierNumber { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { let mut flags = FixedBitSet::<2>::new(); if self.min.is_some() { @@ -156,7 +156,7 @@ pub struct EntityParser { pub single: bool, pub players_only: bool, } -impl McBufReadable for EntityParser { +impl AzaleaRead for EntityParser { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let flags = FixedBitSet::<2>::azalea_read(buf)?; Ok(EntityParser { @@ -165,7 +165,7 @@ impl McBufReadable for EntityParser { }) } } -impl McBufWritable for EntityParser { +impl AzaleaWrite for EntityParser { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { let mut flags = FixedBitSet::<2>::new(); if self.single { @@ -180,7 +180,7 @@ impl McBufWritable for EntityParser { } // TODO: BrigadierNodeStub should have more stuff -impl McBufReadable for BrigadierNodeStub { +impl AzaleaRead for BrigadierNodeStub { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let flags = FixedBitSet::<8>::azalea_read(buf)?; if flags.index(5) || flags.index(6) || flags.index(7) { @@ -239,7 +239,7 @@ impl McBufReadable for BrigadierNodeStub { } } -impl McBufWritable for BrigadierNodeStub { +impl AzaleaWrite for BrigadierNodeStub { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { let mut flags = FixedBitSet::<4>::new(); if self.is_executable { diff --git a/azalea-protocol/src/packets/game/c_damage_event.rs b/azalea-protocol/src/packets/game/c_damage_event.rs index 73ce307d..4d218511 100644 --- a/azalea-protocol/src/packets/game/c_damage_event.rs +++ b/azalea-protocol/src/packets/game/c_damage_event.rs @@ -1,6 +1,6 @@ use std::io::{Cursor, Write}; -use azalea_buf::{McBuf, McBufReadable, McBufVarReadable, McBufVarWritable, McBufWritable}; +use azalea_buf::{McBuf, AzaleaRead, AzaleaReadVar, AzaleaWriteVar, AzaleaWrite}; use azalea_core::position::Vec3; use azalea_protocol_macros::ClientboundGamePacket; @@ -17,7 +17,7 @@ pub struct ClientboundDamageEvent { #[derive(Clone, Debug)] pub struct OptionalEntityId(pub Option); -impl McBufReadable for OptionalEntityId { +impl AzaleaRead for OptionalEntityId { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { match u32::azalea_read_var(buf)? { 0 => Ok(OptionalEntityId(None)), @@ -25,7 +25,7 @@ impl McBufReadable for OptionalEntityId { } } } -impl McBufWritable for OptionalEntityId { +impl AzaleaWrite for OptionalEntityId { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { match self.0 { Some(id) => (id + 1).azalea_write_var(buf), diff --git a/azalea-protocol/src/packets/game/c_explode.rs b/azalea-protocol/src/packets/game/c_explode.rs index 705d32a4..159b4178 100755 --- a/azalea-protocol/src/packets/game/c_explode.rs +++ b/azalea-protocol/src/packets/game/c_explode.rs @@ -4,7 +4,7 @@ use std::{ }; use azalea_buf::{ - BufReadError, McBuf, McBufReadable, McBufVarReadable, McBufVarWritable, McBufWritable, + BufReadError, McBuf, AzaleaRead, AzaleaReadVar, AzaleaWriteVar, AzaleaWrite, }; use azalea_core::{position::BlockPos, resource_location::ResourceLocation}; use azalea_protocol_macros::ClientboundGamePacket; @@ -34,7 +34,7 @@ pub enum BlockInteraction { TriggerBlock, } -impl McBufReadable for ClientboundExplode { +impl AzaleaRead for ClientboundExplode { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let x = f64::azalea_read(buf)?; let y = f64::azalea_read(buf)?; @@ -88,7 +88,7 @@ impl McBufReadable for ClientboundExplode { } } -impl McBufWritable for ClientboundExplode { +impl AzaleaWrite for ClientboundExplode { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { self.x.azalea_write(buf)?; self.y.azalea_write(buf)?; diff --git a/azalea-protocol/src/packets/game/c_level_chunk_with_light.rs b/azalea-protocol/src/packets/game/c_level_chunk_with_light.rs index 336cf190..3ba47cbe 100755 --- a/azalea-protocol/src/packets/game/c_level_chunk_with_light.rs +++ b/azalea-protocol/src/packets/game/c_level_chunk_with_light.rs @@ -32,7 +32,7 @@ pub struct BlockEntity { mod tests { use std::{io::Cursor, ops::Deref}; - use azalea_buf::McBufReadable; + use azalea_buf::AzaleaRead; use azalea_world::Chunk; use simdnbt::owned::BaseNbt; diff --git a/azalea-protocol/src/packets/game/c_level_particles.rs b/azalea-protocol/src/packets/game/c_level_particles.rs index d1c8bdb2..eca5b872 100755 --- a/azalea-protocol/src/packets/game/c_level_particles.rs +++ b/azalea-protocol/src/packets/game/c_level_particles.rs @@ -20,7 +20,7 @@ pub struct ClientboundLevelParticles { mod tests { use std::io::Cursor; - use azalea_buf::McBufReadable; + use azalea_buf::AzaleaRead; use super::*; diff --git a/azalea-protocol/src/packets/game/c_map_item_data.rs b/azalea-protocol/src/packets/game/c_map_item_data.rs index 6123c494..70c483fc 100755 --- a/azalea-protocol/src/packets/game/c_map_item_data.rs +++ b/azalea-protocol/src/packets/game/c_map_item_data.rs @@ -1,4 +1,4 @@ -use azalea_buf::{McBuf, McBufReadable, McBufWritable}; +use azalea_buf::{AzaleaRead, AzaleaWrite, McBuf}; use azalea_chat::FormattedText; use azalea_protocol_macros::ClientboundGamePacket; @@ -26,7 +26,7 @@ pub struct MapDecoration { #[derive(Debug, Clone)] pub struct OptionalMapPatch(pub Option); -impl McBufReadable for OptionalMapPatch { +impl AzaleaRead for OptionalMapPatch { fn azalea_read(buf: &mut std::io::Cursor<&[u8]>) -> Result { let pos = buf.position(); Ok(Self(if u8::azalea_read(buf)? == 0 { @@ -38,7 +38,7 @@ impl McBufReadable for OptionalMapPatch { } } -impl McBufWritable for OptionalMapPatch { +impl AzaleaWrite for OptionalMapPatch { fn azalea_write(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> { match &self.0 { None => 0u8.azalea_write(buf), diff --git a/azalea-protocol/src/packets/game/c_player_abilities.rs b/azalea-protocol/src/packets/game/c_player_abilities.rs index 0e21d3d6..84d6059e 100755 --- a/azalea-protocol/src/packets/game/c_player_abilities.rs +++ b/azalea-protocol/src/packets/game/c_player_abilities.rs @@ -1,7 +1,7 @@ use std::io::{Cursor, Write}; use azalea_buf::{BufReadError, McBuf}; -use azalea_buf::{McBufReadable, McBufWritable}; +use azalea_buf::{AzaleaRead, AzaleaWrite}; use azalea_core::bitset::FixedBitSet; use azalea_protocol_macros::ClientboundGamePacket; @@ -21,7 +21,7 @@ pub struct PlayerAbilitiesFlags { pub instant_break: bool, } -impl McBufReadable for PlayerAbilitiesFlags { +impl AzaleaRead for PlayerAbilitiesFlags { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let set = FixedBitSet::<4>::azalea_read(buf)?; Ok(PlayerAbilitiesFlags { @@ -33,7 +33,7 @@ impl McBufReadable for PlayerAbilitiesFlags { } } -impl McBufWritable for PlayerAbilitiesFlags { +impl AzaleaWrite for PlayerAbilitiesFlags { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { let mut set = FixedBitSet::<4>::new(); if self.invulnerable { diff --git a/azalea-protocol/src/packets/game/c_player_chat.rs b/azalea-protocol/src/packets/game/c_player_chat.rs index 62ad7322..4dbfe5d7 100644 --- a/azalea-protocol/src/packets/game/c_player_chat.rs +++ b/azalea-protocol/src/packets/game/c_player_chat.rs @@ -1,7 +1,7 @@ use std::io::{Cursor, Write}; use azalea_buf::{ - BufReadError, McBuf, McBufReadable, McBufVarReadable, McBufVarWritable, McBufWritable, + BufReadError, McBuf, AzaleaRead, AzaleaReadVar, AzaleaWriteVar, AzaleaWrite, }; use azalea_chat::{ translatable_component::{StringOrComponent, TranslatableComponent}, @@ -144,7 +144,7 @@ impl ChatType { } } -impl McBufReadable for PackedMessageSignature { +impl AzaleaRead for PackedMessageSignature { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let id = u32::azalea_read_var(buf)?; if id == 0 { @@ -156,7 +156,7 @@ impl McBufReadable for PackedMessageSignature { } } } -impl McBufWritable for PackedMessageSignature { +impl AzaleaWrite for PackedMessageSignature { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { match self { PackedMessageSignature::Signature(full_signature) => { diff --git a/azalea-protocol/src/packets/game/c_player_info_update.rs b/azalea-protocol/src/packets/game/c_player_info_update.rs index 1232014b..49202093 100644 --- a/azalea-protocol/src/packets/game/c_player_info_update.rs +++ b/azalea-protocol/src/packets/game/c_player_info_update.rs @@ -5,7 +5,7 @@ use std::{ use azalea_auth::game_profile::{GameProfile, ProfilePropertyValue}; use azalea_buf::{ - BufReadError, McBuf, McBufReadable, McBufVarReadable, McBufVarWritable, McBufWritable, + BufReadError, McBuf, AzaleaRead, AzaleaReadVar, AzaleaWriteVar, AzaleaWrite, }; use azalea_chat::FormattedText; use azalea_core::{bitset::FixedBitSet, game_type::GameMode}; @@ -63,7 +63,7 @@ pub struct UpdateListOrderAction { pub list_order: i32, } -impl McBufReadable for ClientboundPlayerInfoUpdate { +impl AzaleaRead for ClientboundPlayerInfoUpdate { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let actions = ActionEnumSet::azalea_read(buf)?; let mut entries = Vec::new(); @@ -111,7 +111,7 @@ impl McBufReadable for ClientboundPlayerInfoUpdate { } } -impl McBufWritable for ClientboundPlayerInfoUpdate { +impl AzaleaWrite for ClientboundPlayerInfoUpdate { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { self.actions.azalea_write(buf)?; @@ -173,7 +173,7 @@ pub struct ActionEnumSet { pub update_list_order: bool, } -impl McBufReadable for ActionEnumSet { +impl AzaleaRead for ActionEnumSet { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let set = FixedBitSet::<7>::azalea_read(buf)?; Ok(ActionEnumSet { @@ -188,7 +188,7 @@ impl McBufReadable for ActionEnumSet { } } -impl McBufWritable for ActionEnumSet { +impl AzaleaWrite for ActionEnumSet { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { let mut set = FixedBitSet::<7>::new(); if self.add_player { diff --git a/azalea-protocol/src/packets/game/c_player_position.rs b/azalea-protocol/src/packets/game/c_player_position.rs index 4ea5c4cc..d4cfcd29 100755 --- a/azalea-protocol/src/packets/game/c_player_position.rs +++ b/azalea-protocol/src/packets/game/c_player_position.rs @@ -1,6 +1,6 @@ use std::io::{Cursor, Write}; -use azalea_buf::{BufReadError, McBuf, McBufReadable, McBufWritable}; +use azalea_buf::{BufReadError, McBuf, AzaleaRead, AzaleaWrite}; use azalea_core::{bitset::FixedBitSet, position::Vec3}; use azalea_protocol_macros::ClientboundGamePacket; @@ -24,7 +24,7 @@ pub struct RelativeMovements { pub x_rot: bool, } -impl McBufReadable for RelativeMovements { +impl AzaleaRead for RelativeMovements { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { // yes minecraft seriously wastes that many bits, smh let set = FixedBitSet::<32>::azalea_read(buf)?; @@ -38,7 +38,7 @@ impl McBufReadable for RelativeMovements { } } -impl McBufWritable for RelativeMovements { +impl AzaleaWrite for RelativeMovements { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { let mut set = FixedBitSet::<5>::new(); if self.x { diff --git a/azalea-protocol/src/packets/game/c_section_blocks_update.rs b/azalea-protocol/src/packets/game/c_section_blocks_update.rs index 29312e78..122e024a 100755 --- a/azalea-protocol/src/packets/game/c_section_blocks_update.rs +++ b/azalea-protocol/src/packets/game/c_section_blocks_update.rs @@ -2,7 +2,7 @@ use std::io::{Cursor, Write}; use azalea_block::BlockState; use azalea_buf::{ - BufReadError, McBuf, McBufReadable, McBufVarReadable, McBufVarWritable, McBufWritable, + BufReadError, McBuf, AzaleaRead, AzaleaReadVar, AzaleaWriteVar, AzaleaWrite, }; use azalea_core::position::{ChunkSectionBlockPos, ChunkSectionPos}; use azalea_protocol_macros::ClientboundGamePacket; @@ -19,7 +19,7 @@ pub struct BlockStateWithPosition { pub state: BlockState, } -impl McBufReadable for BlockStateWithPosition { +impl AzaleaRead for BlockStateWithPosition { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let data = u64::azalea_read_var(buf)?; let position_part = data & 4095; @@ -35,7 +35,7 @@ impl McBufReadable for BlockStateWithPosition { } } -impl McBufWritable for BlockStateWithPosition { +impl AzaleaWrite for BlockStateWithPosition { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { let data = (self.state.id as u64) << 12 | (u64::from(self.pos.x) << 8 | u64::from(self.pos.z) << 4 | u64::from(self.pos.y)); diff --git a/azalea-protocol/src/packets/game/c_set_equipment.rs b/azalea-protocol/src/packets/game/c_set_equipment.rs index c57a60cc..1d0b3c79 100755 --- a/azalea-protocol/src/packets/game/c_set_equipment.rs +++ b/azalea-protocol/src/packets/game/c_set_equipment.rs @@ -1,7 +1,7 @@ use std::io::Cursor; use azalea_buf::{BufReadError, McBuf}; -use azalea_buf::{McBufReadable, McBufWritable}; +use azalea_buf::{AzaleaRead, AzaleaWrite}; use azalea_inventory::ItemStack; use azalea_protocol_macros::ClientboundGamePacket; @@ -17,7 +17,7 @@ pub struct EquipmentSlots { pub slots: Vec<(EquipmentSlot, ItemStack)>, } -impl McBufReadable for EquipmentSlots { +impl AzaleaRead for EquipmentSlots { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let mut slots = vec![]; @@ -39,7 +39,7 @@ impl McBufReadable for EquipmentSlots { Ok(EquipmentSlots { slots }) } } -impl McBufWritable for EquipmentSlots { +impl AzaleaWrite for EquipmentSlots { fn azalea_write(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> { for i in 0..self.slots.len() { let (equipment_slot, item) = &self.slots[i]; diff --git a/azalea-protocol/src/packets/game/c_set_objective.rs b/azalea-protocol/src/packets/game/c_set_objective.rs index d1c2f96f..2a53d8e2 100755 --- a/azalea-protocol/src/packets/game/c_set_objective.rs +++ b/azalea-protocol/src/packets/game/c_set_objective.rs @@ -1,6 +1,6 @@ use std::io::{Cursor, Write}; -use azalea_buf::{McBuf, McBufReadable, McBufWritable}; +use azalea_buf::{AzaleaRead, McBuf, AzaleaWrite}; use azalea_chat::{numbers::NumberFormat, FormattedText}; use azalea_core::objectives::ObjectiveCriteria; use azalea_protocol_macros::ClientboundGamePacket; @@ -33,7 +33,7 @@ pub enum Method { }, } -impl McBufReadable for Method { +impl AzaleaRead for Method { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let kind = MethodKind::azalea_read(buf)?; match kind { @@ -52,7 +52,7 @@ impl McBufReadable for Method { } } -impl McBufWritable for Method { +impl AzaleaWrite for Method { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { match self { Method::Add { diff --git a/azalea-protocol/src/packets/game/c_set_player_team.rs b/azalea-protocol/src/packets/game/c_set_player_team.rs index b5924a9c..fe8fda1c 100755 --- a/azalea-protocol/src/packets/game/c_set_player_team.rs +++ b/azalea-protocol/src/packets/game/c_set_player_team.rs @@ -1,6 +1,6 @@ use std::io::{Cursor, Write}; -use azalea_buf::{BufReadError, McBuf, McBufReadable, McBufWritable}; +use azalea_buf::{BufReadError, McBuf, AzaleaRead, AzaleaWrite}; use azalea_chat::{style::ChatFormatting, FormattedText}; use azalea_protocol_macros::ClientboundGamePacket; @@ -19,7 +19,7 @@ pub enum Method { Leave(PlayerList), } -impl McBufReadable for Method { +impl AzaleaRead for Method { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { Ok(match u8::azalea_read(buf)? { 0 => Method::Add((Parameters::azalea_read(buf)?, PlayerList::azalea_read(buf)?)), @@ -32,7 +32,7 @@ impl McBufReadable for Method { } } -impl McBufWritable for Method { +impl AzaleaWrite for Method { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { match self { Method::Add((parameters, playerlist)) => { diff --git a/azalea-protocol/src/packets/game/c_stop_sound.rs b/azalea-protocol/src/packets/game/c_stop_sound.rs index 7fc8bcf1..0a01fa71 100755 --- a/azalea-protocol/src/packets/game/c_stop_sound.rs +++ b/azalea-protocol/src/packets/game/c_stop_sound.rs @@ -1,6 +1,6 @@ use std::io::{Cursor, Write}; -use azalea_buf::{BufReadError, McBufReadable, McBufWritable}; +use azalea_buf::{BufReadError, AzaleaRead, AzaleaWrite}; use azalea_core::{bitset::FixedBitSet, resource_location::ResourceLocation}; use azalea_protocol_macros::ClientboundGamePacket; @@ -12,7 +12,7 @@ pub struct ClientboundStopSound { pub name: Option, } -impl McBufReadable for ClientboundStopSound { +impl AzaleaRead for ClientboundStopSound { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let set = FixedBitSet::<2>::azalea_read(buf)?; let source = if set.index(0) { @@ -30,7 +30,7 @@ impl McBufReadable for ClientboundStopSound { } } -impl McBufWritable for ClientboundStopSound { +impl AzaleaWrite for ClientboundStopSound { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { let mut set = FixedBitSet::<2>::new(); if self.source.is_some() { diff --git a/azalea-protocol/src/packets/game/c_system_chat.rs b/azalea-protocol/src/packets/game/c_system_chat.rs index 9055f839..13e32491 100755 --- a/azalea-protocol/src/packets/game/c_system_chat.rs +++ b/azalea-protocol/src/packets/game/c_system_chat.rs @@ -12,7 +12,7 @@ pub struct ClientboundSystemChat { mod tests { use std::io::Cursor; - use azalea_buf::McBufReadable; + use azalea_buf::AzaleaRead; use super::*; diff --git a/azalea-protocol/src/packets/game/c_tab_list.rs b/azalea-protocol/src/packets/game/c_tab_list.rs index 71a90860..87d92c9d 100755 --- a/azalea-protocol/src/packets/game/c_tab_list.rs +++ b/azalea-protocol/src/packets/game/c_tab_list.rs @@ -12,7 +12,7 @@ pub struct ClientboundTabList { mod tests { use std::io::Cursor; - use azalea_buf::McBufReadable; + use azalea_buf::AzaleaRead; use super::*; diff --git a/azalea-protocol/src/packets/game/c_update_advancements.rs b/azalea-protocol/src/packets/game/c_update_advancements.rs index 6e0baf16..3ce8d81c 100755 --- a/azalea-protocol/src/packets/game/c_update_advancements.rs +++ b/azalea-protocol/src/packets/game/c_update_advancements.rs @@ -36,7 +36,7 @@ pub struct DisplayInfo { pub y: f32, } -impl azalea_buf::McBufWritable for DisplayInfo { +impl azalea_buf::AzaleaWrite for DisplayInfo { fn azalea_write(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> { self.title.azalea_write(buf)?; self.description.azalea_write(buf)?; @@ -63,12 +63,12 @@ impl azalea_buf::McBufWritable for DisplayInfo { Ok(()) } } -impl azalea_buf::McBufReadable for DisplayInfo { +impl azalea_buf::AzaleaRead for DisplayInfo { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { - let title = azalea_buf::McBufReadable::azalea_read(buf)?; - let description = azalea_buf::McBufReadable::azalea_read(buf)?; - let icon = azalea_buf::McBufReadable::azalea_read(buf)?; - let frame = azalea_buf::McBufReadable::azalea_read(buf)?; + let title = azalea_buf::AzaleaRead::azalea_read(buf)?; + let description = azalea_buf::AzaleaRead::azalea_read(buf)?; + let icon = azalea_buf::AzaleaRead::azalea_read(buf)?; + let frame = azalea_buf::AzaleaRead::azalea_read(buf)?; let data = u32::azalea_read(buf)?; let has_background = (data & 0b1) != 0; @@ -80,8 +80,8 @@ impl azalea_buf::McBufReadable for DisplayInfo { } else { None }; - let x = azalea_buf::McBufReadable::azalea_read(buf)?; - let y = azalea_buf::McBufReadable::azalea_read(buf)?; + let x = azalea_buf::AzaleaRead::azalea_read(buf)?; + let y = azalea_buf::AzaleaRead::azalea_read(buf)?; Ok(DisplayInfo { title, description, @@ -118,7 +118,7 @@ pub struct AdvancementHolder { #[cfg(test)] mod tests { - use azalea_buf::{McBufReadable, McBufWritable}; + use azalea_buf::{AzaleaRead, AzaleaWrite}; use super::*; diff --git a/azalea-protocol/src/packets/game/c_update_tags.rs b/azalea-protocol/src/packets/game/c_update_tags.rs index 40a4076d..a6e9a33d 100755 --- a/azalea-protocol/src/packets/game/c_update_tags.rs +++ b/azalea-protocol/src/packets/game/c_update_tags.rs @@ -2,8 +2,8 @@ use std::io::Cursor; use std::ops::Deref; use std::{collections::HashMap, io::Write}; -use azalea_buf::{BufReadError, McBuf, McBufVarReadable, McBufVarWritable}; -use azalea_buf::{McBufReadable, McBufWritable}; +use azalea_buf::{BufReadError, McBuf, AzaleaReadVar, AzaleaWriteVar}; +use azalea_buf::{AzaleaRead, AzaleaWrite}; use azalea_core::resource_location::ResourceLocation; use azalea_protocol_macros::ClientboundGamePacket; @@ -21,7 +21,7 @@ pub struct Tags { #[derive(Clone, Debug)] pub struct TagMap(pub HashMap>); -impl McBufReadable for TagMap { +impl AzaleaRead for TagMap { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let length = u32::azalea_read_var(buf)? as usize; let mut data = HashMap::with_capacity(length); @@ -39,7 +39,7 @@ impl McBufReadable for TagMap { } } -impl McBufWritable for TagMap { +impl AzaleaWrite for TagMap { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { (self.len() as u32).azalea_write_var(buf)?; for (k, v) in &self.0 { @@ -49,7 +49,7 @@ impl McBufWritable for TagMap { Ok(()) } } -impl McBufReadable for Tags { +impl AzaleaRead for Tags { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let name = ResourceLocation::azalea_read(buf)?; let elements = Vec::::azalea_read_var(buf)?; @@ -57,7 +57,7 @@ impl McBufReadable for Tags { } } -impl McBufWritable for Tags { +impl AzaleaWrite for Tags { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { self.name.azalea_write(buf)?; self.elements.azalea_write_var(buf)?; diff --git a/azalea-protocol/src/packets/game/s_interact.rs b/azalea-protocol/src/packets/game/s_interact.rs index 0eda7e99..c3d2ffa7 100755 --- a/azalea-protocol/src/packets/game/s_interact.rs +++ b/azalea-protocol/src/packets/game/s_interact.rs @@ -1,6 +1,6 @@ use std::io::{Cursor, Write}; -use azalea_buf::{McBuf, McBufReadable, McBufVarReadable, McBufVarWritable, McBufWritable}; +use azalea_buf::{McBuf, AzaleaRead, AzaleaReadVar, AzaleaWriteVar, AzaleaWrite}; use azalea_core::position::Vec3; use azalea_protocol_macros::ServerboundGamePacket; @@ -27,7 +27,7 @@ pub enum ActionType { }, } -impl McBufWritable for ActionType { +impl AzaleaWrite for ActionType { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { match self { ActionType::Interact { hand } => { @@ -49,7 +49,7 @@ impl McBufWritable for ActionType { } } -impl McBufReadable for ActionType { +impl AzaleaRead for ActionType { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let action_type = u32::azalea_read_var(buf)?; match action_type { diff --git a/azalea-protocol/src/packets/game/s_player_abilities.rs b/azalea-protocol/src/packets/game/s_player_abilities.rs index d65b2b1b..fdf2d8a4 100755 --- a/azalea-protocol/src/packets/game/s_player_abilities.rs +++ b/azalea-protocol/src/packets/game/s_player_abilities.rs @@ -1,6 +1,6 @@ use std::io::Cursor; -use azalea_buf::{McBufReadable, McBufWritable}; +use azalea_buf::{AzaleaRead, AzaleaWrite}; use azalea_core::bitset::FixedBitSet; use azalea_protocol_macros::ServerboundGamePacket; @@ -11,7 +11,7 @@ pub struct ServerboundPlayerAbilities { pub is_flying: bool, } -impl McBufReadable for ServerboundPlayerAbilities { +impl AzaleaRead for ServerboundPlayerAbilities { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let set = FixedBitSet::<2>::azalea_read(buf)?; Ok(Self { @@ -20,7 +20,7 @@ impl McBufReadable for ServerboundPlayerAbilities { } } -impl McBufWritable for ServerboundPlayerAbilities { +impl AzaleaWrite for ServerboundPlayerAbilities { fn azalea_write(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> { let mut set = FixedBitSet::<2>::new(); if self.is_flying { diff --git a/azalea-protocol/src/packets/game/s_player_input.rs b/azalea-protocol/src/packets/game/s_player_input.rs index 3313491b..bd4ba970 100755 --- a/azalea-protocol/src/packets/game/s_player_input.rs +++ b/azalea-protocol/src/packets/game/s_player_input.rs @@ -1,7 +1,7 @@ use std::io::Cursor; use azalea_buf::BufReadError; -use azalea_buf::{McBufReadable, McBufWritable}; +use azalea_buf::{AzaleaRead, AzaleaWrite}; use azalea_core::bitset::FixedBitSet; use azalea_protocol_macros::ServerboundGamePacket; @@ -16,7 +16,7 @@ pub struct ServerboundPlayerInput { pub sprint: bool, } -impl McBufReadable for ServerboundPlayerInput { +impl AzaleaRead for ServerboundPlayerInput { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let set = FixedBitSet::<7>::azalea_read(buf)?; Ok(Self { @@ -31,7 +31,7 @@ impl McBufReadable for ServerboundPlayerInput { } } -impl McBufWritable for ServerboundPlayerInput { +impl AzaleaWrite for ServerboundPlayerInput { fn azalea_write(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> { let mut set = FixedBitSet::<7>::new(); if self.forward { diff --git a/azalea-protocol/src/packets/game/s_seen_advancements.rs b/azalea-protocol/src/packets/game/s_seen_advancements.rs index 24b71e89..7ac970ec 100755 --- a/azalea-protocol/src/packets/game/s_seen_advancements.rs +++ b/azalea-protocol/src/packets/game/s_seen_advancements.rs @@ -1,6 +1,6 @@ use std::io::Cursor; -use azalea_buf::{McBuf, McBufReadable, McBufWritable}; +use azalea_buf::{McBuf, AzaleaRead, AzaleaWrite}; use azalea_core::resource_location::ResourceLocation; use azalea_protocol_macros::ServerboundGamePacket; @@ -18,7 +18,7 @@ pub enum Action { ClosedScreen = 1, } -impl McBufReadable for ServerboundSeenAdvancements { +impl AzaleaRead for ServerboundSeenAdvancements { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let action = Action::azalea_read(buf)?; let tab = if action == Action::OpenedTab { @@ -30,7 +30,7 @@ impl McBufReadable for ServerboundSeenAdvancements { } } -impl McBufWritable for ServerboundSeenAdvancements { +impl AzaleaWrite for ServerboundSeenAdvancements { fn azalea_write(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> { self.action.azalea_write(buf)?; if let Some(tab) = &self.tab { diff --git a/azalea-protocol/src/packets/game/s_set_command_block.rs b/azalea-protocol/src/packets/game/s_set_command_block.rs index cb8bcc2e..9e0100a5 100755 --- a/azalea-protocol/src/packets/game/s_set_command_block.rs +++ b/azalea-protocol/src/packets/game/s_set_command_block.rs @@ -1,10 +1,10 @@ use std::io::Cursor; -use azalea_buf::{BufReadError, McBuf, McBufReadable}; +use azalea_buf::{BufReadError, McBuf, AzaleaRead}; use azalea_core::{bitset::FixedBitSet, position::BlockPos}; use azalea_protocol_macros::ServerboundGamePacket; -use crate::packets::McBufWritable; +use crate::packets::AzaleaWrite; #[derive(Clone, Debug, ServerboundGamePacket)] pub struct ServerboundSetCommandBlock { @@ -24,7 +24,7 @@ pub enum Mode { Redstone = 2, } -impl McBufReadable for ServerboundSetCommandBlock { +impl AzaleaRead for ServerboundSetCommandBlock { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let pos = BlockPos::azalea_read(buf)?; let command = String::azalea_read(buf)?; @@ -42,7 +42,7 @@ impl McBufReadable for ServerboundSetCommandBlock { } } -impl McBufWritable for ServerboundSetCommandBlock { +impl AzaleaWrite for ServerboundSetCommandBlock { fn azalea_write(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> { self.pos.azalea_write(buf)?; self.command.azalea_write(buf)?; diff --git a/azalea-protocol/src/packets/game/s_set_jigsaw_block.rs b/azalea-protocol/src/packets/game/s_set_jigsaw_block.rs index f5fad0ea..937c91e8 100755 --- a/azalea-protocol/src/packets/game/s_set_jigsaw_block.rs +++ b/azalea-protocol/src/packets/game/s_set_jigsaw_block.rs @@ -2,13 +2,13 @@ use std::io::Cursor; use std::io::Write; use azalea_buf::McBuf; -use azalea_buf::McBufReadable; +use azalea_buf::AzaleaRead; use azalea_core::position::BlockPos; use azalea_core::resource_location::ResourceLocation; use azalea_protocol_macros::ServerboundGamePacket; use crate::packets::BufReadError; -use crate::packets::McBufWritable; +use crate::packets::AzaleaWrite; #[derive(Clone, Debug, McBuf, ServerboundGamePacket)] pub struct ServerboundSetJigsawBlock { @@ -29,7 +29,7 @@ pub enum JointType { Aligned, } -impl McBufReadable for JointType { +impl AzaleaRead for JointType { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let name = String::azalea_read(buf)?; match name.as_str() { @@ -40,7 +40,7 @@ impl McBufReadable for JointType { } } -impl McBufWritable for JointType { +impl AzaleaWrite for JointType { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { match self { JointType::Rollable => "rollable".to_string().azalea_write(buf)?, diff --git a/azalea-protocol/src/packets/game/s_set_structure_block.rs b/azalea-protocol/src/packets/game/s_set_structure_block.rs index 72a9ab2f..e6dae668 100755 --- a/azalea-protocol/src/packets/game/s_set_structure_block.rs +++ b/azalea-protocol/src/packets/game/s_set_structure_block.rs @@ -1,7 +1,7 @@ use std::io::{Cursor, Write}; use azalea_buf::McBuf; -use azalea_buf::{McBufReadable, McBufWritable}; +use azalea_buf::{AzaleaRead, AzaleaWrite}; use azalea_core::{bitset::FixedBitSet, position::BlockPos}; use azalea_protocol_macros::ServerboundGamePacket; @@ -69,7 +69,7 @@ pub struct Flags { pub show_bounding_box: bool, } -impl McBufReadable for Flags { +impl AzaleaRead for Flags { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let set = FixedBitSet::<3>::azalea_read(buf)?; Ok(Self { @@ -80,7 +80,7 @@ impl McBufReadable for Flags { } } -impl McBufWritable for Flags { +impl AzaleaWrite for Flags { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { let mut set = FixedBitSet::<3>::new(); if self.ignore_entities { diff --git a/azalea-protocol/src/packets/game/s_use_item_on.rs b/azalea-protocol/src/packets/game/s_use_item_on.rs index 70f4e18a..d0069d11 100755 --- a/azalea-protocol/src/packets/game/s_use_item_on.rs +++ b/azalea-protocol/src/packets/game/s_use_item_on.rs @@ -1,6 +1,6 @@ use std::io::{Cursor, Write}; -use azalea_buf::{BufReadError, McBuf, McBufReadable, McBufWritable}; +use azalea_buf::{BufReadError, McBuf, AzaleaRead, AzaleaWrite}; use azalea_core::{ direction::Direction, position::{BlockPos, Vec3}, @@ -31,7 +31,7 @@ pub struct BlockHit { pub inside: bool, } -impl McBufWritable for BlockHit { +impl AzaleaWrite for BlockHit { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { self.block_pos.azalea_write(buf)?; self.direction.azalea_write(buf)?; @@ -52,7 +52,7 @@ impl McBufWritable for BlockHit { } } -impl McBufReadable for BlockHit { +impl AzaleaRead for BlockHit { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let block_pos = BlockPos::azalea_read(buf)?; let direction = Direction::azalea_read(buf)?; diff --git a/azalea-protocol/src/packets/login/c_login_disconnect.rs b/azalea-protocol/src/packets/login/c_login_disconnect.rs index 46617b2c..a0e50aa4 100755 --- a/azalea-protocol/src/packets/login/c_login_disconnect.rs +++ b/azalea-protocol/src/packets/login/c_login_disconnect.rs @@ -1,6 +1,6 @@ use std::io::{Cursor, Write}; -use azalea_buf::{BufReadError, McBufReadable, McBufWritable}; +use azalea_buf::{AzaleaRead, AzaleaWrite, BufReadError}; use azalea_chat::FormattedText; use azalea_protocol_macros::ClientboundLoginPacket; use serde::{Deserialize, Serialize}; @@ -10,7 +10,7 @@ pub struct ClientboundLoginDisconnect { pub reason: FormattedText, } -impl McBufReadable for ClientboundLoginDisconnect { +impl AzaleaRead for ClientboundLoginDisconnect { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let disconnect_string = String::azalea_read(buf)?; let disconnect_json: serde_json::Value = serde_json::from_str(disconnect_string.as_str())?; @@ -21,7 +21,7 @@ impl McBufReadable for ClientboundLoginDisconnect { } } -impl McBufWritable for ClientboundLoginDisconnect { +impl AzaleaWrite for ClientboundLoginDisconnect { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { let status_string = FormattedText::serialize(&self.reason, serde_json::value::Serializer) .unwrap() diff --git a/azalea-protocol/src/packets/login/s_hello.rs b/azalea-protocol/src/packets/login/s_hello.rs index 894a69ef..62015eda 100755 --- a/azalea-protocol/src/packets/login/s_hello.rs +++ b/azalea-protocol/src/packets/login/s_hello.rs @@ -12,7 +12,7 @@ pub struct ServerboundHello { mod tests { use std::io::Cursor; - use azalea_buf::{McBufReadable, McBufWritable}; + use azalea_buf::{AzaleaRead, AzaleaWrite}; use super::*; diff --git a/azalea-protocol/src/packets/mod.rs b/azalea-protocol/src/packets/mod.rs index 7c723fb8..7c280e23 100755 --- a/azalea-protocol/src/packets/mod.rs +++ b/azalea-protocol/src/packets/mod.rs @@ -7,7 +7,7 @@ pub mod status; use std::io::{Cursor, Write}; -use azalea_buf::{BufReadError, McBufVarReadable, McBufVarWritable, McBufWritable}; +use azalea_buf::{AzaleaWrite, AzaleaWriteVar, BufReadError, AzaleaReadVar}; use crate::read::ReadPacketError; @@ -81,7 +81,7 @@ impl From for ConnectionProtocol { } } -impl azalea_buf::McBufReadable for ClientIntention { +impl azalea_buf::AzaleaRead for ClientIntention { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let id = i32::azalea_read_var(buf)?; id.try_into() @@ -89,7 +89,7 @@ impl azalea_buf::McBufReadable for ClientIntention { } } -impl McBufWritable for ClientIntention { +impl AzaleaWrite for ClientIntention { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { (*self as i32).azalea_write_var(buf) } diff --git a/azalea-protocol/src/packets/status/c_status_response.rs b/azalea-protocol/src/packets/status/c_status_response.rs index c2471d3e..b30c75be 100755 --- a/azalea-protocol/src/packets/status/c_status_response.rs +++ b/azalea-protocol/src/packets/status/c_status_response.rs @@ -1,6 +1,6 @@ use std::io::{Cursor, Write}; -use azalea_buf::{BufReadError, McBufReadable, McBufWritable}; +use azalea_buf::{AzaleaRead, AzaleaWrite, BufReadError}; use azalea_chat::FormattedText; use azalea_protocol_macros::ClientboundStatusPacket; use serde::{Deserialize, Serialize}; @@ -41,7 +41,7 @@ pub struct ClientboundStatusResponse { pub enforces_secure_chat: Option, } -impl McBufReadable for ClientboundStatusResponse { +impl AzaleaRead for ClientboundStatusResponse { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let status_string = String::azalea_read(buf)?; let status_json: serde_json::Value = serde_json::from_str(status_string.as_str())?; @@ -50,7 +50,7 @@ impl McBufReadable for ClientboundStatusResponse { } } -impl McBufWritable for ClientboundStatusResponse { +impl AzaleaWrite for ClientboundStatusResponse { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { let status_string = ClientboundStatusResponse::serialize(self, Serializer) .unwrap() diff --git a/azalea-protocol/src/read.rs b/azalea-protocol/src/read.rs index 60658c3e..3e333e52 100755 --- a/azalea-protocol/src/read.rs +++ b/azalea-protocol/src/read.rs @@ -6,8 +6,8 @@ use std::{ io::{Cursor, Read}, }; +use azalea_buf::AzaleaReadVar; use azalea_buf::BufReadError; -use azalea_buf::McBufVarReadable; use azalea_crypto::Aes128CfbDec; use bytes::Buf; use bytes::BytesMut; diff --git a/azalea-protocol/src/write.rs b/azalea-protocol/src/write.rs index c6b5be47..d2f6bd5a 100755 --- a/azalea-protocol/src/write.rs +++ b/azalea-protocol/src/write.rs @@ -2,7 +2,7 @@ use std::{fmt::Debug, io::Read}; -use azalea_buf::McBufVarWritable; +use azalea_buf::AzaleaWriteVar; use azalea_crypto::Aes128CfbEnc; use flate2::{bufread::ZlibEncoder, Compression}; use thiserror::Error; diff --git a/azalea-registry/src/lib.rs b/azalea-registry/src/lib.rs index 640f3e5c..2df30cc7 100755 --- a/azalea-registry/src/lib.rs +++ b/azalea-registry/src/lib.rs @@ -11,11 +11,11 @@ pub mod tags; use std::fmt::{self, Debug}; use std::io::{Cursor, Write}; -use azalea_buf::{BufReadError, McBufReadable, McBufVarReadable, McBufVarWritable, McBufWritable}; +use azalea_buf::{AzaleaRead, AzaleaReadVar, AzaleaWrite, AzaleaWriteVar, BufReadError}; use azalea_registry_macros::registry; pub use extra::*; -pub trait Registry: McBufReadable + McBufWritable +pub trait Registry: AzaleaRead + AzaleaWrite where Self: Sized, { @@ -28,7 +28,7 @@ where #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct OptionalRegistry(Option); -impl McBufReadable for OptionalRegistry { +impl AzaleaRead for OptionalRegistry { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { Ok(OptionalRegistry(match u32::azalea_read_var(buf)? { 0 => None, @@ -39,7 +39,7 @@ impl McBufReadable for OptionalRegistry { })) } } -impl McBufWritable for OptionalRegistry { +impl AzaleaWrite for OptionalRegistry { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { match &self.0 { None => 0u32.azalea_write_var(buf), @@ -50,12 +50,12 @@ impl McBufWritable for OptionalRegistry { /// A registry that will either take an ID or a resource location. #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub enum CustomRegistry { +pub enum CustomRegistry { Direct(D), Custom(C), } -impl McBufReadable for CustomRegistry { +impl AzaleaRead for CustomRegistry { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let direct_registry = OptionalRegistry::::azalea_read(buf)?; if let Some(direct_registry) = direct_registry.0 { @@ -64,7 +64,7 @@ impl McBufReadable for CustomRegi Ok(CustomRegistry::Custom(C::azalea_read(buf)?)) } } -impl McBufWritable for CustomRegistry { +impl AzaleaWrite for CustomRegistry { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { match self { CustomRegistry::Direct(direct_registry) => { @@ -81,7 +81,7 @@ impl McBufWritable for CustomRegi } #[derive(Clone, PartialEq)] -pub enum HolderSet { +pub enum HolderSet { Direct { contents: Vec, }, @@ -91,7 +91,7 @@ pub enum HolderSet }, } -impl McBufReadable +impl AzaleaRead for HolderSet { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { @@ -111,7 +111,7 @@ impl McBufReadable } } } -impl McBufWritable +impl AzaleaWrite for HolderSet { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { @@ -130,7 +130,7 @@ impl McBufWritable Ok(()) } } -impl Debug +impl Debug for HolderSet { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/azalea-world/src/chunk_storage.rs b/azalea-world/src/chunk_storage.rs index 6d2ce24f..b4ef35e1 100755 --- a/azalea-world/src/chunk_storage.rs +++ b/azalea-world/src/chunk_storage.rs @@ -8,7 +8,7 @@ use std::{ }; use azalea_block::BlockState; -use azalea_buf::{BufReadError, McBufReadable, McBufWritable}; +use azalea_buf::{BufReadError, AzaleaRead, AzaleaWrite}; use azalea_core::position::{BlockPos, ChunkBlockPos, ChunkPos, ChunkSectionBlockPos}; use nohash_hasher::IntMap; use parking_lot::RwLock; @@ -416,7 +416,7 @@ pub fn get_block_state_from_sections( Some(section.get(chunk_section_pos)) } -impl McBufWritable for Chunk { +impl AzaleaWrite for Chunk { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { for section in &self.sections { section.azalea_write(buf)?; @@ -437,7 +437,7 @@ impl Debug for PartialChunkStorage { } } -impl McBufReadable for Section { +impl AzaleaRead for Section { fn azalea_read(buf: &mut Cursor<&[u8]>) -> Result { let block_count = u16::azalea_read(buf)?; @@ -467,7 +467,7 @@ impl McBufReadable for Section { } } -impl McBufWritable for Section { +impl AzaleaWrite for Section { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { self.block_count.azalea_write(buf)?; self.states.azalea_write(buf)?; diff --git a/azalea-world/src/palette.rs b/azalea-world/src/palette.rs index 6d9a509e..24dbe47a 100755 --- a/azalea-world/src/palette.rs +++ b/azalea-world/src/palette.rs @@ -1,6 +1,6 @@ use std::io::{Cursor, Write}; -use azalea_buf::{BufReadError, McBufReadable, McBufVarReadable, McBufVarWritable, McBufWritable}; +use azalea_buf::{AzaleaRead, AzaleaReadVar, AzaleaWrite, AzaleaWriteVar, BufReadError}; use azalea_core::math; use tracing::warn; @@ -224,7 +224,7 @@ impl PalettedContainer { } } -impl McBufWritable for PalettedContainer { +impl AzaleaWrite for PalettedContainer { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { self.bits_per_entry.azalea_write(buf)?; self.palette.azalea_write(buf)?; @@ -264,7 +264,7 @@ impl Palette { } } -impl McBufWritable for Palette { +impl AzaleaWrite for Palette { fn azalea_write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { match self { Palette::SingleValue(value) => { diff --git a/codegen/README.md b/codegen/README.md index 60b881ce..b00290aa 100755 --- a/codegen/README.md +++ b/codegen/README.md @@ -4,9 +4,9 @@ The directory name doesn't start with `azalea-` because it's not a Rust crate. ## Requirements -- Python 3.8+ -- Java 17+ -- Maven +- Python 3.8+ +- Java 17+ +- Maven ## Usage @@ -17,19 +17,20 @@ This will create a new file in the `azalea-protocol/src/packets/[state] director ## Updating to a new Minecraft version First, run `python migrate.py [new version]`. This will run a script that automatically updates as much as it can, including: -- Adding, removing, and updating packets in azalea-protocol (limited) -- Updating supported version in README.md -- Updating the `PROTOCOL_VERSION` variable in azalea-protocol -- Generating blocks in azalea-block -- Generating block shapes in azalea-physics -- Generating registries in azalea-registries -- Updating en_us.json in azalea-language -- Generating entity metadata structs and parsers in azalea-world + +- Adding, removing, and updating packets in azalea-protocol (limited) +- Updating supported version in README.md +- Updating the `PROTOCOL_VERSION` variable in azalea-protocol +- Generating blocks in azalea-block +- Generating block shapes in azalea-physics +- Generating registries in azalea-registries +- Updating en_us.json in azalea-language +- Generating entity metadata structs and parsers in azalea-world If you're lucky, that's all you're going to have to do. Look at the diff (`git diff`) and type-check the code (`cargo check`) to make sure everything is right. In the diff, specifically look for new comments that have "TODO". -If a packet is incorrect, you'll want to find it in the Minecraft source. The name of the struct should be the same or similar as the class in the vanilla source. Now, you'll have to manually write the struct for the packet. If the packet existed in the version before and it's just being updated, you can compare against that to see what was updated. Note that if a packet is particularly complicated, you may have to implement McBufReadable and McBufWritable, but most of the time the `#[derive(McBuf)]` macro will be able to generate the impls correctly. Look at other existing packets as reference if you're confused. +If a packet is incorrect, you'll want to find it in the Minecraft source. The name of the struct should be the same or similar as the class in the vanilla source. Now, you'll have to manually write the struct for the packet. If the packet existed in the version before and it's just being updated, you can compare against that to see what was updated. Note that if a packet is particularly complicated, you may have to implement AzaleaRead and AzaleaWrite, but most of the time the `#[derive(McBuf)]` macro will be able to generate the impls correctly. Look at other existing packets as reference if you're confused. Finally, test by making a bot join a world. Specifically, you'll want to test the things that were updated in the version. Setting the RUST_LOG environment variable to `debug` or `trace` may help you find the source of crashes (trace shows the first few hundred bytes for every packet received so it's typically more useful, but it may log more than you want). @@ -39,9 +40,8 @@ If it all works, make a pull request. If the version you updated to is a snapsho At the time of writing, the following data generators are used: -- [Vanilla data generator](https://wiki.vg/Data_Generators) -- [Burger](https://github.com/mat-1/Burger) -- [PixLyzer](https://gitlab.bixilon.de/bixilon/pixlyzer) +- [Vanilla data generator](https://wiki.vg/Data_Generators) +- [Burger](https://github.com/mat-1/Burger) +- [PixLyzer](https://gitlab.bixilon.de/bixilon/pixlyzer) Some things can be obtained from multiple generators. You should prefer them by the order above (the vanilla generator is the most reliable). -