13 releases (breaking)

0.10.3+mc1.21.1 Oct 23, 2024
0.10.2 Jun 14, 2024
0.10.0 Apr 24, 2024
0.9.0 Dec 5, 2023
0.4.0 Nov 19, 2022

#1 in #azalea

Download history 10/week @ 2024-08-11 4/week @ 2024-08-18 17/week @ 2024-08-25 9/week @ 2024-09-01 5/week @ 2024-09-08 20/week @ 2024-09-15 44/week @ 2024-09-22 38/week @ 2024-09-29 3/week @ 2024-10-06 12/week @ 2024-10-13 205/week @ 2024-10-20 26/week @ 2024-10-27 41/week @ 2024-11-03 11/week @ 2024-11-10 56/week @ 2024-11-17 18/week @ 2024-11-24

128 downloads per month
Used in 6 crates

MIT license

750KB
19K SLoC

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::EastWall::Low,
    north: azalea_block::properties::NorthWall::Low,
    south: azalea_block::properties::SouthWall::Low,
    west: azalea_block::properties::WestWall::Low,
    up: false,
    waterlogged: false,
}
.into();
# use azalea_block::BlockState;
let block_state: BlockState = azalea_registry::Block::Jukebox.into();

Block trait

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.

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

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.

Dependencies

~2–2.6MB
~46K SLoC