aboutsummaryrefslogtreecommitdiff
path: root/azalea-block
diff options
context:
space:
mode:
Diffstat (limited to 'azalea-block')
-rw-r--r--azalea-block/Cargo.toml4
-rw-r--r--azalea-block/README.md2
-rw-r--r--azalea-block/block-macros/src/lib.rs82
-rw-r--r--azalea-block/src/lib.rs2
4 files changed, 52 insertions, 38 deletions
diff --git a/azalea-block/Cargo.toml b/azalea-block/Cargo.toml
index edeba385..71d7149f 100644
--- a/azalea-block/Cargo.toml
+++ b/azalea-block/Cargo.toml
@@ -9,3 +9,7 @@ version = "0.1.0"
[dependencies]
block-macros = {path = "./block-macros"}
+
+[features]
+default = ["trait"]
+trait = []
diff --git a/azalea-block/README.md b/azalea-block/README.md
index 39843ef4..84da3241 100644
--- a/azalea-block/README.md
+++ b/azalea-block/README.md
@@ -6,3 +6,5 @@ There's two main things here, the `BlockState` enum and the `Block` trait.
`BlockState` is a simple enum with every possible block state as variant, and `Block` is a heavier trait which lets you access information about a block more easily.
Every block is a struct that implements `Block`. You can freely convert between `BlockState` and `Block` with .into().
+
+If you don't want the `Block` trait, set default-features to false.
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()
}
diff --git a/azalea-block/src/lib.rs b/azalea-block/src/lib.rs
index 3eb86a90..9320a2a5 100644
--- a/azalea-block/src/lib.rs
+++ b/azalea-block/src/lib.rs
@@ -1,6 +1,8 @@
+#[cfg(feature = "trait")]
mod behavior;
mod blocks;
+#[cfg(feature = "trait")]
pub use behavior::BlockBehavior;
pub use blocks::*;