blob: 4f929cd3b67e426402f1433782a13daa2981c13d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
#![doc = include_str!("../README.md")]
mod behavior;
pub mod block_state;
pub mod fluid_state;
mod generated;
mod range;
use core::fmt::Debug;
use std::any::Any;
pub use behavior::BlockBehavior;
// re-exported for convenience
pub use block_state::BlockState;
pub use generated::{blocks, properties};
pub use range::BlockStates;
pub trait BlockTrait: Debug + Any {
fn behavior(&self) -> BlockBehavior;
/// Get the Minecraft ID for this block. For example `stone` or
/// `grass_block`.
fn id(&self) -> &'static str;
/// Convert the block to a block state. This is lossless, as the block
/// contains all the state data.
fn as_block_state(&self) -> BlockState;
/// Convert the block to an [`azalea_registry::Block`]. This is lossy, as
/// `azalea_registry::Block` doesn't contain any state data.
fn as_registry_block(&self) -> azalea_registry::Block;
}
impl dyn BlockTrait {
pub fn downcast_ref<T: BlockTrait>(&self) -> Option<&T> {
(self as &dyn Any).downcast_ref::<T>()
}
}
pub trait Property {
type Value;
fn try_from_block_state(state: BlockState) -> Option<Self::Value>;
}
|