aboutsummaryrefslogtreecommitdiff
path: root/azalea-block
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2025-06-02 19:23:59 -0330
committermat <git@matdoes.dev>2025-06-03 06:11:26 +0700
commit7517a207db658c98d5b97b3b3f44df6725c025a2 (patch)
tree5daabe20be53705acd1fee93134421dc23b4d6c6 /azalea-block
parentabf995a70245028f9cc860ee231dc671f14adfcc (diff)
downloadazalea-drasl-7517a207db658c98d5b97b3b3f44df6725c025a2.tar.xz
rename the Block trait to BlockTrait to disambiguate with azalea_registry::Block
Diffstat (limited to 'azalea-block')
-rw-r--r--azalea-block/README.md14
-rw-r--r--azalea-block/azalea-block-macros/src/lib.rs6
-rw-r--r--azalea-block/src/block_state.rs12
-rw-r--r--azalea-block/src/generated.rs2
-rw-r--r--azalea-block/src/lib.rs6
-rw-r--r--azalea-block/src/range.rs1
6 files changed, 20 insertions, 21 deletions
diff --git a/azalea-block/README.md b/azalea-block/README.md
index ae3b8c5f..8eca79ee 100644
--- a/azalea-block/README.md
+++ b/azalea-block/README.md
@@ -23,20 +23,20 @@ let block_state: BlockState = azalea_block::blocks::CobblestoneWall {
let block_state: BlockState = azalea_registry::Block::Jukebox.into();
```
-## Block trait
+## BlockTrait
-The [`Block`] trait represents a type of a block. With the the [`Block`] trait, you can get some extra things like the string block ID and some information about the block's behavior. Also, the structs that implement the trait contain the block attributes as fields so it's more convenient to get them. Note that this is often used as `Box<dyn Block>`.
-If for some reason you don't want the `Block` trait, set default-features to false.
+The [`BlockTrait`] trait represents a type of a block. With [`BlockTrait`], you can get some extra things like the string block ID and some information about the block's behavior. Also, the structs that implement the trait contain the block attributes as fields so it's more convenient to get them. Note that this is often used as `Box<dyn BlockTrait>`.
+If for some reason you don't want `BlockTrait`, set `default-features = false`.
```
-# use azalea_block::{Block, BlockState};
+# use azalea_block::{BlockTrait, BlockState};
# let block_state = BlockState::from(azalea_registry::Block::Jukebox);
-let block = Box::<dyn Block>::from(block_state);
+let block = Box::<dyn BlockTrait>::from(block_state);
```
```
-# use azalea_block::{Block, BlockState};
+# use azalea_block::{BlockTrait, BlockState};
# let block_state: BlockState = azalea_registry::Block::Jukebox.into();
-if let Some(jukebox) = Box::<dyn Block>::from(block_state).downcast_ref::<azalea_block::blocks::Jukebox>() {
+if let Some(jukebox) = Box::<dyn BlockTrait>::from(block_state).downcast_ref::<azalea_block::blocks::Jukebox>() {
// ...
}
```
diff --git a/azalea-block/azalea-block-macros/src/lib.rs b/azalea-block/azalea-block-macros/src/lib.rs
index 3d09b018..4174ed41 100644
--- a/azalea-block/azalea-block-macros/src/lib.rs
+++ b/azalea-block/azalea-block-macros/src/lib.rs
@@ -660,7 +660,7 @@ pub fn make_block_states(input: TokenStream) -> TokenStream {
#block_struct_fields
}
- impl Block for #block_struct_name {
+ impl BlockTrait for #block_struct_name {
fn behavior(&self) -> BlockBehavior {
#block_behavior
}
@@ -785,7 +785,7 @@ pub fn make_block_states(input: TokenStream) -> TokenStream {
#block_structs
- impl From<BlockState> for Box<dyn Block> {
+ impl From<BlockState> for Box<dyn BlockTrait> {
fn from(block_state: BlockState) -> Self {
let b = block_state.id();
match b {
@@ -794,7 +794,7 @@ pub fn make_block_states(input: TokenStream) -> TokenStream {
}
}
}
- impl From<azalea_registry::Block> for Box<dyn Block> {
+ impl From<azalea_registry::Block> for Box<dyn BlockTrait> {
fn from(block: azalea_registry::Block) -> Self {
match block {
#from_registry_block_to_block_match
diff --git a/azalea-block/src/block_state.rs b/azalea-block/src/block_state.rs
index dfa2a9b2..a954c333 100644
--- a/azalea-block/src/block_state.rs
+++ b/azalea-block/src/block_state.rs
@@ -5,7 +5,7 @@ use std::{
use azalea_buf::{AzaleaRead, AzaleaReadVar, AzaleaWrite, AzaleaWriteVar, BufReadError};
-use crate::Block;
+use crate::BlockTrait;
/// The type that's used internally to represent a block state ID.
///
@@ -121,14 +121,14 @@ impl Debug for BlockState {
f,
"BlockState(id: {}, {:?})",
self.id,
- Box::<dyn Block>::from(*self)
+ Box::<dyn BlockTrait>::from(*self)
)
}
}
impl From<BlockState> for azalea_registry::Block {
fn from(value: BlockState) -> Self {
- Box::<dyn Block>::from(value).as_registry_block()
+ Box::<dyn BlockTrait>::from(value).as_registry_block()
}
}
@@ -149,11 +149,11 @@ mod tests {
#[test]
fn test_from_blockstate() {
- let block: Box<dyn Block> = Box::<dyn Block>::from(BlockState::AIR);
+ let block: Box<dyn BlockTrait> = Box::<dyn BlockTrait>::from(BlockState::AIR);
assert_eq!(block.id(), "air");
- let block: Box<dyn Block> =
- Box::<dyn Block>::from(BlockState::from(azalea_registry::Block::FloweringAzalea));
+ let block: Box<dyn BlockTrait> =
+ Box::<dyn BlockTrait>::from(BlockState::from(azalea_registry::Block::FloweringAzalea));
assert_eq!(block.id(), "flowering_azalea");
}
diff --git a/azalea-block/src/generated.rs b/azalea-block/src/generated.rs
index 28dfe4f9..7c26291f 100644
--- a/azalea-block/src/generated.rs
+++ b/azalea-block/src/generated.rs
@@ -2,7 +2,7 @@ use std::fmt::Debug;
use azalea_block_macros::make_block_states;
-use crate::{Block, BlockBehavior, BlockState, BlockStates, Property};
+use crate::{BlockTrait, BlockBehavior, BlockState, BlockStates, Property};
make_block_states! {
Properties => {
diff --git a/azalea-block/src/lib.rs b/azalea-block/src/lib.rs
index fdffe372..4f929cd3 100644
--- a/azalea-block/src/lib.rs
+++ b/azalea-block/src/lib.rs
@@ -15,7 +15,7 @@ pub use block_state::BlockState;
pub use generated::{blocks, properties};
pub use range::BlockStates;
-pub trait Block: Debug + Any {
+pub trait BlockTrait: Debug + Any {
fn behavior(&self) -> BlockBehavior;
/// Get the Minecraft ID for this block. For example `stone` or
/// `grass_block`.
@@ -27,8 +27,8 @@ pub trait Block: Debug + Any {
/// `azalea_registry::Block` doesn't contain any state data.
fn as_registry_block(&self) -> azalea_registry::Block;
}
-impl dyn Block {
- pub fn downcast_ref<T: Block>(&self) -> Option<&T> {
+impl dyn BlockTrait {
+ pub fn downcast_ref<T: BlockTrait>(&self) -> Option<&T> {
(self as &dyn Any).downcast_ref::<T>()
}
}
diff --git a/azalea-block/src/range.rs b/azalea-block/src/range.rs
index 183c3cc0..cbe77284 100644
--- a/azalea-block/src/range.rs
+++ b/azalea-block/src/range.rs
@@ -1,7 +1,6 @@
use std::{
collections::{HashSet, hash_set},
ops::{Add, RangeInclusive},
- sync::LazyLock,
};
use crate::{BlockState, block_state::BlockStateIntegerRepr};