mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 23:44:38 +00:00
fix entitydatavalue
This commit is contained in:
parent
0fc82aa579
commit
fb158bab4b
2 changed files with 36 additions and 12 deletions
|
@ -101,9 +101,21 @@ fn create_impl_mcbufreadable(ident: &Ident, data: &Data) -> proc_macro2::TokenSt
|
|||
})
|
||||
}
|
||||
}
|
||||
syn::Fields::Unnamed(_) => quote! {
|
||||
Ok(Self::#variant_name(azalea_buf::McBufReadable::read_from(buf)?))
|
||||
},
|
||||
syn::Fields::Unnamed(fields) => {
|
||||
let mut reader_code = quote! {};
|
||||
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::var_read_from(buf)?),
|
||||
})
|
||||
} else {
|
||||
reader_code.extend(quote! {
|
||||
Self::#variant_name(azalea_buf::McBufReadable::read_from(buf)?),
|
||||
})
|
||||
}
|
||||
}
|
||||
quote! { Ok(#reader_code) }
|
||||
}
|
||||
syn::Fields::Unit => quote! {
|
||||
Ok(Self::#variant_name)
|
||||
},
|
||||
|
@ -249,12 +261,27 @@ fn create_impl_mcbufwritable(ident: &Ident, data: &Data) -> proc_macro2::TokenSt
|
|||
}
|
||||
});
|
||||
}
|
||||
syn::Fields::Unnamed(_) => {
|
||||
syn::Fields::Unnamed(fields) => {
|
||||
is_data_enum = true;
|
||||
let mut writers_code = quote! {};
|
||||
let mut params_code = quote! {};
|
||||
for (i, f) in fields.unnamed.iter().enumerate() {
|
||||
let param_ident = Ident::new(&format!("data{i}"), Span::call_site());
|
||||
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)?;
|
||||
})
|
||||
} else {
|
||||
writers_code.extend(quote! {
|
||||
azalea_buf::McBufWritable::write_into(#param_ident, buf)?;
|
||||
})
|
||||
}
|
||||
}
|
||||
match_arms.extend(quote! {
|
||||
Self::#variant_name(data) => {
|
||||
Self::#variant_name(#params_code) => {
|
||||
azalea_buf::McBufVarWritable::var_write_into(&#variant_discrim, buf)?;
|
||||
azalea_buf::McBufWritable::write_into(data, buf)?;
|
||||
#writers_code
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -46,8 +46,7 @@ impl McBufWritable for EntityMetadata {
|
|||
#[derive(Clone, Debug, McBuf)]
|
||||
pub enum EntityDataValue {
|
||||
Byte(u8),
|
||||
// varint
|
||||
Int(i32),
|
||||
Int(#[var] i32),
|
||||
Long(i64),
|
||||
Float(f32),
|
||||
String(String),
|
||||
|
@ -110,10 +109,8 @@ pub enum Pose {
|
|||
|
||||
#[derive(Debug, Clone, McBuf)]
|
||||
pub struct VillagerData {
|
||||
#[var]
|
||||
type_: u32,
|
||||
#[var]
|
||||
profession: u32,
|
||||
kind: azalea_registry::VillagerType,
|
||||
profession: azalea_registry::VillagerProfession,
|
||||
#[var]
|
||||
level: u32,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue