azalea/azalea-block
mat 2f51a0a123 Release 0.10.0
azalea@0.10.0
azalea-auth@0.10.0
azalea-block@0.10.0
azalea-block-macros@0.10.0
azalea-brigadier@0.10.0
azalea-buf@0.10.0
azalea-buf-macros@0.10.0
azalea-chat@0.10.0
azalea-client@0.10.0
azalea-core@0.10.0
azalea-crypto@0.10.0
azalea-entity@0.10.0
azalea-inventory@0.10.0
azalea-inventory-macros@0.10.0
azalea-language@0.10.0
azalea-physics@0.10.0
azalea-protocol@0.10.0
azalea-protocol-macros@0.10.0
azalea-registry@0.10.0
azalea-registry-macros@0.10.0
azalea-world@0.10.0

Generated by cargo-workspaces
2024-04-23 23:56:30 -05:00
..
azalea-block-macros Release 0.10.0 2024-04-23 23:56:30 -05:00
src 1.20.5 (#127) 2024-04-23 10:34:50 -05:00
.gitignore add unit structs for every bool property 2023-12-09 18:32:13 -06:00
Cargo.toml Release 0.10.0 2024-04-23 23:56:30 -05:00
README.md Add World::find_block (#80) 2023-03-07 22:09:56 -06: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::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.