1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 14:26:04 +00:00
azalea/azalea-block
2025-06-17 06:49:07 -12:00
..
azalea-block-macros rename the Block trait to BlockTrait to disambiguate with azalea_registry::Block 2025-06-03 06:11:26 +07:00
src 1.21.6 (#215) 2025-06-17 06:49:07 -12:00
.gitignore add unit structs for every bool property 2023-12-09 18:32:13 -06:00
Cargo.toml use workspace deps everywhere 2025-06-16 01:20:37 +01:00
README.md rename the Block trait to BlockTrait to disambiguate with azalea_registry::Block 2025-06-03 06:11:26 +07:00

Representation of Minecraft block states.

There's three block types, used for different things. You can (mostly) convert between them with .into().

BlockState struct

[BlockState] is a struct containing the numerical protocol ID of a block state. This is how blocks are stored in the world.

# use azalea_block::BlockState;
let block_state: BlockState = azalea_block::blocks::CobblestoneWall {
    east: azalea_block::properties::WallEast::Low,
    north: azalea_block::properties::WallNorth::Low,
    south: azalea_block::properties::WallSouth::Low,
    west: azalea_block::properties::WallWest::Low,
    up: false,
    waterlogged: false,
}
.into();
# use azalea_block::BlockState;
let block_state: BlockState = azalea_registry::Block::Jukebox.into();

BlockTrait

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::{BlockTrait, BlockState};
# let block_state = BlockState::from(azalea_registry::Block::Jukebox);
let block = Box::<dyn BlockTrait>::from(block_state);
# use azalea_block::{BlockTrait, BlockState};
# let block_state: BlockState = azalea_registry::Block::Jukebox.into();
if let Some(jukebox) = Box::<dyn BlockTrait>::from(block_state).downcast_ref::<azalea_block::blocks::Jukebox>() {
    // ...
}

azalea_registry::Block enum

This one technically isn't from the azalea-block crate, but it's still very relevant. It's an enum that contains every block type as a variant without containing any state data (unlike BlockState and the Block trait). Converting this into any other block type will use the default state for that block.