aboutsummaryrefslogtreecommitdiff
path: root/azalea-block/block-macros/src
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2022-08-27 20:31:21 -0500
committerGitHub <noreply@github.com>2022-08-27 20:31:21 -0500
commitb8228a036016fa58cab4b00a2e62298df299d41f (patch)
tree37ab80c054d2c0832d0ebf61cbbefd9e368260a8 /azalea-block/block-macros/src
parent029ae0e567ccdc631a358755eba43b742811ff05 (diff)
downloadazalea-drasl-b8228a036016fa58cab4b00a2e62298df299d41f.tar.xz
Azalea registry (#20)
* make azalea-registry crate * add trait feature to az-block * registr * registry macro * impl Display for registry things * registries
Diffstat (limited to 'azalea-block/block-macros/src')
-rw-r--r--azalea-block/block-macros/src/lib.rs82
1 files changed, 44 insertions, 38 deletions
diff --git a/azalea-block/block-macros/src/lib.rs b/azalea-block/block-macros/src/lib.rs
index 907fd241..e6585600 100644
--- a/azalea-block/block-macros/src/lib.rs
+++ b/azalea-block/block-macros/src/lib.rs
@@ -426,41 +426,43 @@ pub fn make_block_states(input: TokenStream) -> TokenStream {
quote! { BlockState::#block_name_pascal_case }
};
- let block_struct = quote! {
- #[derive(Debug)]
- pub struct #block_struct_name {
- #block_struct_fields
- }
-
- impl Block for #block_struct_name {
- fn behavior(&self) -> BlockBehavior {
- #block_behavior
+ if cfg!(feature = "trait") {
+ let block_struct = quote! {
+ #[derive(Debug)]
+ pub struct #block_struct_name {
+ #block_struct_fields
}
- fn id(&self) -> &'static str {
- #block_id
+
+ impl Block for #block_struct_name {
+ fn behavior(&self) -> BlockBehavior {
+ #block_behavior
+ }
+ fn id(&self) -> &'static str {
+ #block_id
+ }
}
- }
- impl From<#block_struct_name> for BlockState {
- fn from(b: #block_struct_name) -> Self {
- #from_block_to_state_match
+ impl From<#block_struct_name> for BlockState {
+ fn from(b: #block_struct_name) -> Self {
+ #from_block_to_state_match
+ }
}
- }
- impl Default for #block_struct_name {
- fn default() -> Self {
- Self {
- #block_default_fields
+ impl Default for #block_struct_name {
+ fn default() -> Self {
+ Self {
+ #block_default_fields
+ }
}
}
- }
- };
+ };
- block_structs.extend(block_struct);
+ block_structs.extend(block_struct);
+ }
}
let last_state_id = (state_id - 1) as u32;
- quote! {
+ let mut generated = quote! {
#property_enums
#[repr(u32)]
@@ -469,18 +471,6 @@ pub fn make_block_states(input: TokenStream) -> TokenStream {
#block_state_enum_variants
}
- #block_structs
-
- impl From<BlockState> for Box<dyn Block> {
- fn from(b: BlockState) -> Self {
- let b = b as usize;
- match b {
- #from_state_to_block_match
- _ => panic!("Invalid block state: {}", b),
- }
- }
- }
-
impl BlockState {
/// Returns the highest possible state
#[inline]
@@ -488,7 +478,23 @@ pub fn make_block_states(input: TokenStream) -> TokenStream {
#last_state_id
}
}
-
+ };
+
+ if cfg!(feature = "trait") {
+ generated.extend(quote! {
+ #block_structs
+
+ impl From<BlockState> for Box<dyn Block> {
+ fn from(b: BlockState) -> Self {
+ let b = b as usize;
+ match b {
+ #from_state_to_block_match
+ _ => panic!("Invalid block state: {}", b),
+ }
+ }
+ }
+ });
}
- .into()
+
+ generated.into()
}