From 3108372b90622a894aeb6374b33733db13e65674 Mon Sep 17 00:00:00 2001 From: SelfMadeSystem Date: Wed, 18 Oct 2023 21:51:35 -0400 Subject: [PATCH 1/3] Set the default health of entities --- crates/valence_entity/build.rs | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/crates/valence_entity/build.rs b/crates/valence_entity/build.rs index 4f916da85..bd7d19acc 100644 --- a/crates/valence_entity/build.rs +++ b/crates/valence_entity/build.rs @@ -436,9 +436,28 @@ fn build() -> anyhow::Result { pub #field_name_ident: super::#stripped_snake_entity_name_ident::#pascal_field_name_ident, }]); - bundle_init_fields.extend([quote! { - #field_name_ident: Default::default(), - }]); + if snake_field_name == "health" && entity.attributes.is_some() { + if let Some(max_health) = entity + .attributes + .as_ref() + .unwrap() + .iter() + .find(|attribute| attribute.name == "generic.max_health") + .map(|attribute| attribute.base_value as f32) + { + bundle_init_fields.extend([quote! { + living_health: super::living::Health(#max_health), + }]); + } else { + bundle_init_fields.extend([quote! { + #field_name_ident: Default::default(), + }]); + } + } else { + bundle_init_fields.extend([quote! { + #field_name_ident: Default::default(), + }]); + } } } } From 54ea6ccd8b86d84af29233db288fcbea6c75cad4 Mon Sep 17 00:00:00 2001 From: SelfMadeSystem Date: Wed, 18 Oct 2023 22:05:59 -0400 Subject: [PATCH 2/3] ? --- crates/valence_entity/build.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/valence_entity/build.rs b/crates/valence_entity/build.rs index bd7d19acc..dc22833ef 100644 --- a/crates/valence_entity/build.rs +++ b/crates/valence_entity/build.rs @@ -436,6 +436,8 @@ fn build() -> anyhow::Result { pub #field_name_ident: super::#stripped_snake_entity_name_ident::#pascal_field_name_ident, }]); + // + if snake_field_name == "health" && entity.attributes.is_some() { if let Some(max_health) = entity .attributes From 926982c5ba4507711091d27dfdcb27d4d1938577 Mon Sep 17 00:00:00 2001 From: SelfMadeSystem Date: Wed, 18 Oct 2023 22:06:05 -0400 Subject: [PATCH 3/3] ??????? --- crates/valence_entity/build.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/valence_entity/build.rs b/crates/valence_entity/build.rs index dc22833ef..bd7d19acc 100644 --- a/crates/valence_entity/build.rs +++ b/crates/valence_entity/build.rs @@ -436,8 +436,6 @@ fn build() -> anyhow::Result { pub #field_name_ident: super::#stripped_snake_entity_name_ident::#pascal_field_name_ident, }]); - // - if snake_field_name == "health" && entity.attributes.is_some() { if let Some(max_health) = entity .attributes