aboutsummaryrefslogtreecommitdiff
path: root/azalea-buf/azalea-buf-macros/src/write.rs
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2024-11-27 19:31:40 -0600
committerGitHub <noreply@github.com>2024-11-27 19:31:40 -0600
commit08958c2278b15ebeac8a964f392ebb792e479b61 (patch)
tree4ae3664cea38d7fd1a8f1e95ed06fac04ffe519e /azalea-buf/azalea-buf-macros/src/write.rs
parent139d77d3c2b0922fba5e9d4fa2bd9819d78bd773 (diff)
downloadazalea-drasl-08958c2278b15ebeac8a964f392ebb792e479b61.tar.xz
Refactor azalea-protocol (#190)
* start updating to 1.21.4 * fix block codegen and stop using block data from burger * rename packet related modules and structs to be simpler * ItemSlot -> ItemStack for more consistency with mojmap * .get() -> .into_packet() * simplify declare_state_packets by removing packet ids * rename read_from and write_into to azalea_read and azalea_write * rename McBufReadable and McBufWritable to AzaleaRead and AzaleaWrite * McBuf -> AzBuf * remove most uses of into_variant * update codegen and use resourcelocation names for packets * implement #[limit(i)] attribute for AzBuf derive macro * fixes for 1.21.4 * fix examples * update some physics code and fix ChatType * remove unused imports in codegen * re-add some things to migrate.py and update +mc version numbers automatically * downgrade to 1.21.3 lol
Diffstat (limited to 'azalea-buf/azalea-buf-macros/src/write.rs')
-rw-r--r--azalea-buf/azalea-buf-macros/src/write.rs36
1 files changed, 18 insertions, 18 deletions
diff --git a/azalea-buf/azalea-buf-macros/src/write.rs b/azalea-buf/azalea-buf-macros/src/write.rs
index 4d31f39e..df461d59 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::var_write_into(#ident_dot_field, buf)?;
+ azalea_buf::AzaleaWriteVar::azalea_write_var(#ident_dot_field, buf)?;
}
} else {
quote! {
- azalea_buf::McBufWritable::write_into(#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,8 +45,8 @@ 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 {
- fn write_into(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> {
+ impl azalea_buf::AzaleaWrite for #ident {
+ fn azalea_write(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> {
#write_fields
Ok(())
}
@@ -55,15 +55,15 @@ pub fn create_impl_mcbufwritable(ident: &Ident, data: &Data) -> proc_macro2::Tok
}
syn::Fields::Unit => {
quote! {
- impl azalea_buf::McBufWritable for #ident {
- fn write_into(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> {
+ impl azalea_buf::AzaleaWrite for #ident {
+ fn azalea_write(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> {
Ok(())
}
}
}
}
_ => {
- panic!("#[derive(McBuf)] can only be used on structs with named fields")
+ panic!("#[derive(AzBuf)] can only be used on structs with named fields")
}
},
syn::Data::Enum(syn::DataEnum { variants, .. }) => {
@@ -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::var_write_into(&#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::var_write_into(#param_ident, buf)?;
+ azalea_buf::AzaleaWriteVar::azalea_write_var(#param_ident, buf)?;
});
} else {
writers_code.extend(quote! {
- azalea_buf::McBufWritable::write_into(#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::write_into(data, buf)?;
+ azalea_buf::AzaleaWrite::azalea_write(data, buf)?;
}
});
}
@@ -169,8 +169,8 @@ pub fn create_impl_mcbufwritable(ident: &Ident, data: &Data) -> proc_macro2::Tok
}
if is_data_enum {
quote! {
- impl azalea_buf::McBufWritable for #ident {
- fn write_into(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> {
+ 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,14 +189,14 @@ 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 {
- fn write_into(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> {
- azalea_buf::McBufVarWritable::var_write_into(&(*self as u32), buf)
+ impl azalea_buf::AzaleaWrite for #ident {
+ fn azalea_write(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> {
+ azalea_buf::AzaleaWriteVar::azalea_write_var(&(*self as u32), buf)
}
}
}
}
}
- _ => panic!("#[derive(McBuf)] can only be used on structs"),
+ _ => panic!("#[derive(AzBuf)] can only be used on structs"),
}
}